When a library will be available for K8090 to be programmed in visual basic?
Hi,
After you install the software you can find the DLL in the following location.
c:\windows\system32\K8090D.dll
I hope this helps.
I know. Thank you. But there is only examples for VBasic 8 express not for Vbasic 6.
Compilers for Visual Basic 6 can no longer be bought or downloaded legally so it’s kind of hard to make any examples. I’ll see what we can do to come up with an example, but i’m also afraid that very few people still have that old VB6.0 compiler lying around…
Thank you. I’m waiting for the VB6 example, as we can found in anothers Velleman KITs.
Have you already any VB6 example to manage K8090D.DLL?
Thank you for your cooperation.
Option Explicit
Private acm As String
Private cmd As String
Private msk As Integer
Private pr1 As Integer
Private pr2 As Integer
Private prt As Integer
Private CO(8) As Boolean
Private RO(8) As Boolean
Private RI(8) As Boolean
Private Sub Form_Load()
On Error Resume Next
Timer1.Enabled = False
DoEvents
Dim pok As Boolean
Dim env As Boolean
Dim cnt As Integer
msc.Settings = “19200,n,8,1”
prt = 0
pok = False
Do Until pok
If msc.PortOpen Then
If env Then
If msc.InBufferCount > 0 Then
acm = msc.Input
If InStr(acm, Chr(&H4) & Chr(&H71)) > 0 Then
pok = True
Me.Caption = “K8090 - COM” & prt
Else
env = False
cnt = 0
prt = prt + 1
If prt > 20 Then End
msc.CommPort = prt
msc.PortOpen = True
End If
Else
cnt = cnt + 1
If cnt > 10000 Then msc.PortOpen = False
End If
Else
msc.Output = chks(Chr(&H71) & Chr(&H0) & Chr(&H0) & Chr(&H0))
env = True
End If
Else
env = False
cnt = 0
prt = prt + 1
If prt > 20 Then End
msc.CommPort = prt
msc.PortOpen = True
End If
Loop
acm = “”
Timer1.Enabled = True
DoEvents
msc.Output = chks(Chr(&H18) & Chr(&H0) & Chr(&H0) & Chr(&H0))
End Sub
Private Sub Form_Unload(Cancel As Integer)
msc.PortOpen = False
End Sub
Private Sub chkO_Click(Index As Integer)
If chkO(Index).Value = vbChecked Then
Select Case Index
Case 0
msc.Output = chks(Chr(&H11) & Chr(1) & Chr(&H0) & Chr(&H0))
Case 1
msc.Output = chks(Chr(&H11) & Chr(2) & Chr(&H0) & Chr(&H0))
Case 2
msc.Output = chks(Chr(&H11) & Chr(4) & Chr(&H0) & Chr(&H0))
Case 3
msc.Output = chks(Chr(&H11) & Chr(8) & Chr(&H0) & Chr(&H0))
Case 4
msc.Output = chks(Chr(&H11) & Chr(16) & Chr(&H0) & Chr(&H0))
Case 5
msc.Output = chks(Chr(&H11) & Chr(32) & Chr(&H0) & Chr(&H0))
Case 6
msc.Output = chks(Chr(&H11) & Chr(64) & Chr(&H0) & Chr(&H0))
Case 7
msc.Output = chks(Chr(&H11) & Chr(128) & Chr(&H0) & Chr(&H0))
End Select
Else
Select Case Index
Case 0
msc.Output = chks(Chr(&H12) & Chr(1) & Chr(&H0) & Chr(&H0))
Case 1
msc.Output = chks(Chr(&H12) & Chr(2) & Chr(&H0) & Chr(&H0))
Case 2
msc.Output = chks(Chr(&H12) & Chr(4) & Chr(&H0) & Chr(&H0))
Case 3
msc.Output = chks(Chr(&H12) & Chr(8) & Chr(&H0) & Chr(&H0))
Case 4
msc.Output = chks(Chr(&H12) & Chr(16) & Chr(&H0) & Chr(&H0))
Case 5
msc.Output = chks(Chr(&H12) & Chr(32) & Chr(&H0) & Chr(&H0))
Case 6
msc.Output = chks(Chr(&H12) & Chr(64) & Chr(&H0) & Chr(&H0))
Case 7
msc.Output = chks(Chr(&H12) & Chr(128) & Chr(&H0) & Chr(&H0))
End Select
End If
End Sub
Private Sub Timer1_Timer()
Dim x, pi As Integer
If msc.InBufferCount > 0 Then
acm = acm & msc.Input
pi = InStr(acm, Chr(&H4))
If pi > 0 Then
If Len(acm) - pi > 5 Then
cmd = Mid(acm, pi + 1, 1)
msk = Asc(Mid(acm, pi + 2, 1))
pr1 = Asc(Mid(acm, pi + 3, 1))
pr2 = Asc(Mid(acm, pi + 4, 1))
lbl(0).Caption = cmd
lbl(1).Caption = msk
lbl(2).Caption = pr1
lbl(3).Caption = pr2
acm = “”
Select Case cmd
Case Chr(&H50)
If msk >= 128 Then RI(7) = True: msk = msk Mod 128 Else RI(7) = False
If msk >= 64 Then RI(6) = True: msk = msk Mod 64 Else RI(6) = False
If msk >= 32 Then RI(5) = True: msk = msk Mod 32 Else RI(5) = False
If msk >= 16 Then RI(4) = True: msk = msk Mod 16 Else RI(4) = False
If msk >= 8 Then RI(3) = True: msk = msk Mod 8 Else RI(3) = False
If msk >= 4 Then RI(2) = True: msk = msk Mod 4 Else RI(2) = False
If msk >= 2 Then RI(1) = True: msk = msk Mod 2 Else RI(1) = False
If msk >= 1 Then RI(0) = True: msk = msk Mod 1 Else RI(0) = False
For x = 0 To 7
If RI(x) Then shpI(x).BackColor = vbGreen Else shpI(x).BackColor = vbButtonFace
Next x
Case Chr(&H51)
If pr1 >= 128 Then RO(7) = True: pr1 = pr1 Mod 128 Else RO(7) = False
If pr1 >= 64 Then RO(6) = True: pr1 = pr1 Mod 64 Else RO(6) = False
If pr1 >= 32 Then RO(5) = True: pr1 = pr1 Mod 32 Else RO(5) = False
If pr1 >= 16 Then RO(4) = True: pr1 = pr1 Mod 16 Else RO(4) = False
If pr1 >= 8 Then RO(3) = True: pr1 = pr1 Mod 8 Else RO(3) = False
If pr1 >= 4 Then RO(2) = True: pr1 = pr1 Mod 4 Else RO(2) = False
If pr1 >= 2 Then RO(1) = True: pr1 = pr1 Mod 2 Else RO(1) = False
If pr1 >= 1 Then RO(0) = True: pr1 = pr1 Mod 1 Else RO(0) = False
For x = 0 To 7
If RO(x) Then chkO(x).BackColor = vbGreen Else chkO(x).BackColor = vbButtonFace
If RO(x) Then chkO(x).Value = vbChecked Else chkO(x).Value = vbUnchecked
Next x
End Select
End If
End If
If Len(acm) > 35 Then acm = “”
End If
End Sub
Private Function chks(s As String) As String
Dim v, x As Integer
s = Chr(&H4) & s
v = 0
For x = 1 To Len(s)
v = v + Asc(Mid(s, x, 1))
Next x
v = (-v + 0) And 255
chks = s & Chr(v) & Chr(&HF)
End Function
Option Explicit
Public glPrevWndProc As Long
Public hDevice1 As Long
Public hWnd1 As Long
Private Const WM_USER = &H400
Public Const USR_MESSAGE1 = WM_USER + 1
Public Const CMD_SWITCH_RELAY_ON As Byte = &H11
Public Const CMD_SWITCH_RELAY_OFF As Byte = &H12
Public Const CMD_TOGGLE_RELAY As Byte = &H14
Public Const CMD_QUERY_RELAY_STATUS As Byte = &H18
Public Const CMD_SET_MANUAL_OPERATION_MODE As Byte = &H21
Public Const CMD_QUERY_MANUAL_OPERATION_MODE As Byte = &H22
Public Const CMD_START_RELAY_TIMER As Byte = &H41
Public Const CMD_SET_RELAY_TIMER_DELAY As Byte = &H42
Public Const CMD_QUERY_TIMER_DELAY As Byte = &H44
Public Const CMD_BUTTON_STATUS As Byte = &H50
Public Const CMD_RELAY_STATUS As Byte = &H51
Public Const CMD_RESET_FACTORY_DEFAULTS As Byte = &H66
Public Const CMD_GET_JUMPER_STATUS As Byte = &H70
Public Const CMD_FIRMWARE_VERSION As Byte = &H71
Declare Function OpenDevice Lib “K8090D.DLL” (ByVal port As String) As Long
Declare Sub CloseDevice Lib “K8090D.DLL” (ByVal hDevice As Long)
Declare Function SendCommand Lib “K8090D.DLL” (ByVal hDevice As Long, ByVal cmd As Byte, ByVal Mask As Byte, ByVal hparam As Byte, ByVal lParam As Byte) As Boolean
Declare Sub RegisterListener Lib “K8090D.DLL” (ByVal hDevice As Long, ByVal hwnd As Long)
Declare Sub UnregisterListener Lib “K8090D.DLL” (ByVal hDevice As Long)
Declare Function CallWindowProc Lib “user32” Alias “CallWindowProcA” (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function DefWindowProc Lib “user32” Alias “DefWindowProcA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function WndProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim cmd As Byte
Select Case uMsg
Case USR_MESSAGE1
cmd = wParam
Select Case cmd
Case CMD_SWITCH_RELAY_ON
Debug.Print “CMD_SWITCH_RELAY_ON”
Exit Function
Case CMD_SWITCH_RELAY_OFF
Debug.Print “CMD_SWITCH_RELAY_OFF”
Exit Function
Case CMD_TOGGLE_RELAY
Debug.Print “CMD_TOGGLE_RELAY”
Exit Function
Case CMD_QUERY_RELAY_STATUS
Debug.Print “CMD_QUERY_RELAY_STATUS”
Exit Function
Case CMD_SET_MANUAL_OPERATION_MODE
Debug.Print “CMD_SET_MANUAL_OPERATION_MODE”
Exit Function
Case CMD_START_RELAY_TIMER
Debug.Print “CMD_START_RELAY_TIMER”
Exit Function
Case CMD_QUERY_TIMER_DELAY
Debug.Print “CMD_QUERY_TIMER_DELAY”
Exit Function
Case CMD_QUERY_TIMER_DELAY
Debug.Print “CMD_QUERY_TIMER_DELAY”
Exit Function
Case CMD_BUTTON_STATUS
Debug.Print “CMD_BUTTON_STATUS”
Exit Function
Case CMD_RELAY_STATUS
Debug.Print “CMD_RELAY_STATUS”
Exit Function
Case CMD_RESET_FACTORY_DEFAULTS
Debug.Print “CMD_RESET_FACTORY_DEFAULTS”
Exit Function
Case CMD_GET_JUMPER_STATUS
Debug.Print “CMD_GET_JUMPER_STATUS”
Exit Function
Case CMD_FIRMWARE_VERSION
Debug.Print “CMD_FIRMWARE_VERSION”
Exit Function
Case Else
WndProc = DefWindowProc(hw, uMsg, wParam, lParam)
End Select
Case Else
WndProc = DefWindowProc(hw, uMsg, wParam, lParam)
End Select
End Function
Public Function fSubClass() As Long
fSubClass = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Function
Public Sub pUnSubClass()
Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, glPrevWndProc)
End Sub
Option Explicit
Private Sub Form_Load()
hDevice1 = OpenDevice(“COM10”)
Me.Caption = hDevice1
End Sub
Private Sub chkO_Click(Index As Integer)
Me.Caption = “”
If chkO(Index).Value = vbChecked Then
Select Case Index
Case 0
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 1, 0, 0)
Case 1
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 2, 0, 0)
Case 2
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 4, 0, 0)
Case 3
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 8, 0, 0)
Case 4
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 16, 0, 0)
Case 5
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 32, 0, 0)
Case 6
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 64, 0, 0)
Case 7
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_ON, 128, 0, 0)
End Select
Else
Select Case Index
Case 0
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 1, 0, 0)
Case 1
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 2, 0, 0)
Case 2
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 4, 0, 0)
Case 3
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 8, 0, 0)
Case 4
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 16, 0, 0)
Case 5
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 32, 0, 0)
Case 6
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 64, 0, 0)
Case 7
Me.Caption = SendCommand(hDevice1, CMD_SWITCH_RELAY_OFF, 128, 0, 0)
End Select
End If
End Sub
Private Sub cmdSub_Click()
glPrevWndProc = Me.hwnd
Call RegisterListener(hDevice1, USR_MESSAGE1)
cmdSub.Caption = WndProc(glPrevWndProc, 0, 0, 0)
End Sub
Private Sub cmdUnSub_Click()
Call UnregisterListener(hDevice1)
End Sub
Private Sub cmdQuit_Click()
On Error Resume Next
Call UnregisterListener(hDevice1)
Call CloseDevice(hDevice1)
Unload Me
End Sub