Problem using VM140 and VM167 card together

Hello Velleman

the info material(for the VM167 package) states that it is possible to use both VM140 and VM167 together on same computer. i’m currently working with the Excel visual basic examples.

and when i look at the commands that are possible to call the vm167.dll file with then i see that the most vm167 commands match the vm140/k8061 commands.

how to distinguish the vm167 commands from the vm140/k8061 commands inside the visual basic code? i’m trying to make an handcontroller unit built on the vm167 usb interface card and then having the vm140 card act as in/out interface for some relays and sensors for some hobby-automation projects.

thanks.

[quote]how to distinguish the vm167 commands from the vm140/k8061 commands inside the visual basic code?[/quote]You can use alias names for the DLL functions who have same names.

Here is an example.
There are three buttons on the workbook.
The first button opens the VM167 card and sets its digital output #1 on.
The second button opens VM140 card and sets its digital output #1 on.
The third button clears all digital outputs and closes the cards.
For more info pleas see also this thread: viewtopic.php?f=12&t=5098

[code]Option Explicit
Private Declare Function VM167OpenDevices Lib “vm167.dll” Alias “OpenDevices” () As Long
Private Declare Sub VM167CloseDevices Lib “vm167.dll” Alias “CloseDevices” ()
Private Declare Sub VM167InOutMode Lib “vm167.dll” Alias “InOutMode” (ByVal CardAddress As Long, ByVal HighNibble As Long, ByVal LowNibble As Long)
Private Declare Function VM167ReadAnalogChannel Lib “vm167.dll” Alias “ReadAnalogChannel” (ByVal CardAddress As Long, ByVal Channel As Long) As Long
Private Declare Sub VM167ReadAllAnalog Lib “vm167.dll” Alias “ReadAllAnalog” (ByVal CardAddress As Long, ByRef Buffer As Long)
Private Declare Sub VM167OutputAllDigital Lib “vm167.dll” Alias “OutputAllDigital” (ByVal CardAddress As Long, ByVal Data As Long)
Private Declare Sub VM167ClearDigitalChannel Lib “vm167.dll” Alias “ClearDigitalChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM167ClearAllDigital Lib “vm167.dll” Alias “ClearAllDigital” (ByVal CardAddress As Long)
Private Declare Sub VM167SetDigitalChannel Lib “vm167.dll” Alias “SetDigitalChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM167SetAllDigital Lib “vm167.dll” Alias “SetAllDigital” (ByVal CardAddress As Integer)
Private Declare Function VM167ReadDigitalChannel Lib “vm167.dll” Alias “” (ByVal CardAddress As Long, ByVal Channel As Long) As Boolean
Private Declare Function VM167ReadAllDigital Lib “vm167.dll” Alias “ReadAllDigital” (ByVal CardAddress As Long) As Long
Private Declare Function VM167ReadCounter Lib “vm167.dll” Alias “ReadCounter” (ByVal CardAddress As Long) As Long
Private Declare Sub VM167ResetCounter Lib “vm167.dll” Alias “ResetCounter” (ByVal CardAddress As Long)
Private Declare Sub VM167SetPWM Lib “vm167.dll” Alias “SetPWM” (ByVal CardAddress As Long, ByVal Channel As Long, ByVal Data As Long, ByVal Freq As Long)
Private Declare Sub VM167OutputAllPWM Lib “vm167.dll” Alias “OutputAllPWM” (ByVal CardAddress As Long, ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Function VM167VersionDLL Lib “vm167.dll” Alias “VersionDLL” () As Long
Private Declare Function VM167VersionFirmware Lib “vm167.dll” Alias “VersionFirmware” (ByVal CardAddress As Long) As Long
Private Declare Function VM167Connected Lib “vm167.dll” Alias “Connected” () As Long
Private Declare Sub VM167ReadBackPWMOut Lib “vm167.dll” Alias “ReadBackPWMOut” (ByVal CardAddress As Long, ByRef Buffer As Long)
Private Declare Function VM167ReadBackInOutMode Lib “vm167.dll” Alias “ReadBackInOutMode” (ByVal CardAddress As Long) As Long

Private Declare Function VM140OpenDevice Lib “k8061.dll” Alias “OpenDevice” () As Long
Private Declare Sub VM140CloseDevices Lib “k8061.dll” Alias “CloseDevices” ()
Private Declare Sub VM140CloseDevice Lib “k8061.dll” Alias “CloseDevice” (ByVal CardAddress As Long)
Private Declare Function VM140ReadAnalogChannel Lib “k8061.dll” Alias “ReadAnalogChannel” (ByVal CardAddress As Long, ByVal Channel As Long) As Long
Private Declare Function VM140PowerGood Lib “k8061.dll” Alias “PowerGood” (ByVal CardAddress As Long) As Boolean
Private Declare Function VM140Connected Lib “k8061.dll” Alias “Connected” (ByVal CardAddress As Long) As Boolean
Private Declare Sub VM140ReadVersion Lib “k8061.dll” Alias “ReadVersion” (ByVal CardAddress As Long, Buffer As Long)
Private Declare Sub VM140ReadAllAnalog Lib “k8061.dll” Alias “ReadAllAnalog” (ByVal CardAddress As Long, Buffer As Long)
Private Declare Sub VM140OutputAnalogChannel Lib “k8061.dll” Alias “OutputAnalogChannel” (ByVal CardAddress As Long, ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub VM140OutputAllAnalog Lib “k8061.dll” Alias “OutputAllAnalog” (ByVal CardAddress As Long, Buffer As Long)
Private Declare Sub VM140ClearAnalogChannel Lib “k8061.dll” Alias “ClearAnalogChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM140SetAllAnalog Lib “k8061.dll” Alias “SetAllAnalog” (ByVal CardAddress As Long)
Private Declare Sub VM140ClearAllAnalog Lib “k8061.dll” Alias “ClearAllAnalog” (ByVal CardAddress As Long)
Private Declare Sub VM140SetAnalogChannel Lib “k8061.dll” Alias “SetAnalogChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM140OutputAllDigital Lib “k8061.dll” Alias “OutputAllDigital” (ByVal CardAddress As Long, ByVal Data As Long)
Private Declare Sub VM140ClearDigitalChannel Lib “k8061.dll” Alias “ClearDigitalChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM140ClearAllDigital Lib “k8061.dll” Alias “ClearAllDigital” (ByVal CardAddress As Long)
Private Declare Sub VM140SetDigitalChannel Lib “k8061.dll” Alias “SetDigitalChannel” (ByVal CardAddress As Long, ByVal Channel As Long)
Private Declare Sub VM140SetAllDigital Lib “k8061.dll” Alias “SetAllDigital” (ByVal CardAddress As Long)
Private Declare Function VM140ReadDigitalChannel Lib “k8061.dll” Alias “ReadDigitalChannel” (ByVal CardAddress As Long, ByVal Channel As Long) As Boolean
Private Declare Function VM140ReadAllDigital Lib “k8061.dll” Alias “ReadAllDigital” (ByVal CardAddress As Long) As Long
Private Declare Sub VM140OutputPWM Lib “k8061.dll” Alias “OutputPWM” (ByVal CardAddress As Long, ByVal Data As Long)
Private Declare Function VM140ReadBackDigitalOut Lib “k8061.dll” Alias “ReadBackAnalogOut” (ByVal CardAddress As Long) As Long
Private Declare Sub VM140ReadBackAnalogOut Lib “k8061.dll” Alias “” (ByVal CardAddress As Long, Buffer As Long)
Private Declare Function VM140ReadBackPWMOut Lib “k8061.dll” Alias “ReadBackPWMOut” (ByVal CardAddress As Long) As Long

Dim CardAddress_VM167 As Long
Dim CardAddress_VM140 As Long
Dim Cards As Long

Sub Button1_Click()

Cards = VM167OpenDevices()
Select Case Cards
Case 0
ActiveSheet.Cells(1, 8) = “Card open error.”
Case 1
ActiveSheet.Cells(1, 8) = “Card 0 connected.”
CardAddress_VM167 = 0
Case 2
ActiveSheet.Cells(1, 8) = “Card 1 connected.”
CardAddress_VM167 = 1
Case 3
ActiveSheet.Cells(1, 8) = “Cards 0 and 1 connected.”
CardAddress_VM167 = 0
Case -1
ActiveSheet.Cells(1, 8) = “Card not found.”
End Select
If Cards > 0 Then
VM167InOutMode CardAddress_VM167, 0, 0 ’ all outputs
VM167SetDigitalChannel CardAddress_VM167, 1
End If
End Sub

Sub Button2_Click()
CardAddress_VM140 = VM140OpenDevice
If CardAddress_VM140 >= 0 Then
ActiveSheet.Cells(1, 4) = “Card connected”
VM140SetDigitalChannel CardAddress_VM140, 1
Else
ActiveSheet.Cells(1, 4) = “Card not found”
End If
End Sub

Sub Button3_Click()
VM167ClearAllDigital CardAddress_VM167
VM140ClearAllDigital CardAddress_VM140
VM167CloseDevices
ActiveSheet.Cells(1, 8) = “Card closed”
VM140CloseDevices
ActiveSheet.Cells(1, 4) = “Card closed”
End Sub[/code]