I would want to get values of the analogic inputs from K8055 to Excel.
Now, I can only get the logic ones using this macro :
Private Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim Connected As Boolean
Sub StartTimer()
TimerSeconds = 1 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub
Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Dim Byt As Long
Dim Bit As Long
On Error Resume Next
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Byt = ReadAllDigital
ActiveSheet.Cells(3, 1).Value = Byt
For i = 0 To 4
If (Byt And 2 ^ i) Then Bit = 1 Else Bit = 0
ActiveSheet.Cells(4, 5 - i).Value = Bit
Next i
'
End Sub
Sub Start_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = ActiveSheet.Cells(1, 3).Value
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
ActiveSheet.Cells(1, 1) = "Card " + Str(h) + " connected"
Case -1
ActiveSheet.Cells(1, 1) = "Card " + Str(CardAddress) + " not found"
End Select
StartTimer
End Sub
Sub Stop_Click()
EndTimer
ActiveSheet.Cells(1, 1) = "Stopped"
End Sub
Thank you helping me !
I am an awful beginner in VBA !
There in the examples folder is a ready to run Excel VBA demo.
It reads both the analog and digital inputs
The demo also send incrementing value to the digital outputs.
Here is the whole VBA code:
[code]Option Explicit
Private Declare Function Version Lib “k8055d.dll” () As Long
Private Declare Function SearchDevices Lib “k8055d.dll” () As Long
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib “k8055d.dll” (Data1 As Long, Data2 As Long)
Private Declare Sub OutputAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub OutputAllAnalog Lib “k8055d.dll” (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllAnalog Lib “k8055d.dll” ()
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()
Private Declare Sub SetAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Declare Function ReadCounter Lib “k8055d.dll” (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib “k8055d.dll” (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib “k8055d.dll” (ByVal CounterNr As Long, ByVal DebounceTime As Long)
Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim CardAddress As Long
Dim n As Long
Sub Button1_Click()
Dim h As Long
n = 0
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 0 Connected”
TimerSeconds = 0.1 ’ the timer interval is now .1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 4) = “Card 0 Not Found”
End If
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim Data1 As Long
Dim Data2 As Long
Dim i As Long
ReadAllAnalog Data1, Data2
ActiveSheet.Cells(2, 2) = Data1
ActiveSheet.Cells(3, 2) = Data2
WriteAllDigital n
ActiveSheet.Cells(5, 2) = n
n = n + 1
i = ReadAllDigital
ActiveSheet.Cells(7, 2) = i
End Sub
Sub Button3_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 4) = “Card 0 Closed”
End Sub[/code]