VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "cLabJack" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False 'The Resource Manager knows about the resources on your PC Private Declare Function GetDriverVersion Lib "C:\Windows\SysWOW64\LabJackUD.dll" () As Double Private Declare Function OpenLabJack Lib "C:\Windows\SysWOW64\LabJackUD.dll" (ByVal DeviceType As Long, _ ByVal ConnectionType As Long, _ ByRef pAddress As Byte, _ ByVal FirstFound As Long, _ ByRef pHandle As Long) As Long Private Declare Function eGet Lib "C:\Windows\SysWOW64\LabJackUD.dll" (ByVal pHandle As Long, _ ByVal IOType As Long, _ ByVal Channel As Long, _ ByRef pValue As Double, _ ByVal x1 As Long) As Long Private Declare Function ePut Lib "C:\Windows\SysWOW64\LabJackUD.dll" (ByVal pHandle As Long, _ ByVal IOType As Long, _ ByVal Channel As Long, _ ByVal pValue As Double, _ ByVal x1 As Long) As Long Private Declare Sub Close  Lib "C:\Windows\SysWOW64\LabJackUD.dll" Alias "Close" () ' "Close " has a space ALT-255 at the end Private Declare Function ErrorToString Lib "C:\Windows\SysWOW64\LabJackUD.dll" (ByVal ErrorCode As Long, _ ByVal buffer As LongPtr) ' not working and too lazy to write code to convert to BSTR ' Device types Private Const LJ_dtUE9 As Integer = 9 Private Const LJ_dtU3 As Integer = 3 Private Const LJ_dtU6 As Integer = 6 Private Const LJ_ioGET_AIN As Integer = 10 Private Const LJ_ioPUT_DAC As Integer = 20 ' Connection types Private Const LJ_ctUSB As Integer = 1 ' UE9 + U3 + U6 Private Const LJ_ctETHERNET As Integer = 2 ' UE9 only Private Const LJ_ctETHERNET_MB As Integer = 3 ' Modbus over Ethernet. UE9 only. Private Const LJ_ctETHERNET_DATA_ONLY As Integer = 4 ' Opens data port but not stream port. UE9 only. Private Const LJ_ioGET_DIGITAL_BIT As Long = 30 ' UE9 + U3 + U6 Private Const LJ_ioGET_DIGITAL_PORT As Long = 35 ' UE9 + U3 + U6 Private Const LJ_ioPUT_DIGITAL_BIT As Long = 40 ' UE9 + U3 + U6 ' Config iotypes: Private Const LJ_ioPUT_CONFIG As Long = 1000 ' UE9 + U3 + U6 Private Const LJ_ioGET_CONFIG As Long = 1001 ' UE9 + U3 + U6 Private Const LJ_ioPIN_CONFIGURATION_RESET As Long = 2017 ' UE9 + U3 + U6 '***** Private members Private lngHandle As Long Private pAIN(0 To 3) As Variant Private pTimer(0 To 1) As Object ' object to contain another object Private pFIO(4 To 7) As Object ' flex IO, can be AIN, DI, or DO, plus value out/in '***** other members Private pUD_Version As Double Const TypeAIN As Byte = 0 Const TypeDI As Byte = 1 Const TypeDO As Byte = 2 Public Sub InitiateProperties(inHandle As Long) pUD_Version = GetDriverVersion ' Read the UD version. If Not inHandle Then lngErrorcode = OpenLabJack(LJ_dtU3, LJ_ctUSB, "1", 1, lngHandle) ' Open the first found LabJack U3. ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "OpenLabJack") Then lngHandle = 0 Exit Sub End If Else lngErrorcode = inHandle End If lngErrorcode = ePut(lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0) ' RESET pins. ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "ePut") Then Exit Sub For i = 0 To 1 Set pTimer(i) = Nothing ' future use Next i End Sub '''''''''''''''''''''' ' UD Version (software driver) '''''''''''''''''''''' Public Property Get UD_Version() As String UD_Version = Format(pUD_Version, "0.00") End Property '''''''''''''''''''''' ' handle, should be unchanged from subsequent DLL calls '''''''''''''''''''''' Public Property Get Handle() As LongPtr Handle = lngHandle End Property '''''''''''''''''''''' ' Analog inputs '''''''''''''''''''''' Public Property Get AIN(inHandle As Long) As Variant Dim i As Integer If inHandle = 0 Then For i = 0 To 3 pAIN(i) = 0# Next i Call MsgBox("U3 not initialized", vbCritical, "LJ Initialization Error") Exit Sub End If lngHandle = inHandle For i = 0 To 3 lngErrorcode = eGet(lngHandle, LJ_ioGET_AIN, i, pAIN(i), 0) ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "eGet") Then Exit Function Next i AIN = pAIN End Property '''''''''''''''''''''' ' Analog output '''''''''''''''''''''' Public Property Let DAC(inHandle As Long, inDAC() As Variant) Dim i As Integer: Dim D(0 To 1) As Double If inHandle = 0 Then Call MsgBox("U3 not initialized", vbCritical, "LJ Initialization Error") Exit Property End If lngHandle = inHandle If UBound(inDAC) - LBound(inDAC) < 2 Then Call MsgBox("DAC data incorrect", vbCritical, "LJ Initialization Error") Exit Property End If For i = 0 To 1 D(i) = inDAC(LBound(inDAC) + i) lngErrorcode = ePut(lngHandle, LJ_ioPUT_DAC, i, D(i), 0) ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "ePut") Then Exit Property Next i End Property '''''''''''''''''''''' ' FIO programming '''''''''''''''''''''' Public Property Let FIO(inHandle As Long, inFIO() As Object) Dim i As Integer: If inHandle = 0 Then Call MsgBox("U3 not initialized", vbCritical, "LJ Initialization Error") Exit Property End If lngHandle = inHandle For i = LBound(pFIO) To UBound(pFIO) Set pFIO(i) = inFIO(i) If pFIO(i).TypeIO = TypeDO Then lngErrorcode = ePut(lngHandle, LJ_ioPUT_DIGITAL_BIT, i, pFIO(i).Value, 0) ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "ePut") Then Exit Property Else ' lngErrorcode = ePut(lngHandle, LJ_ioPUT_CONFIG, dgh, i, 0) ' ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "LJ_ioPUT_CONFIG") Then Exit Property lngErrorcode = eGet(lngHandle, LJ_ioGET_DIGITAL_PORT, i, pFIO(i).Value, 0) ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "LJ_ioGET_DIGITAL_BIT") Then Exit Property End If Next i End Property '''''''''''''''''''''' ' FIO read '''''''''''''''''''''' 'Public Property Get FIO(inHandle As Long) As Object ' Dim i As Integer: ' Dim T(LBound(pFIO) To UBound(pFIO)) As Object ' ' If inHandle = 0 Then ' Call MsgBox("U3 not initialized", vbCritical, "LJ Initialization Error") ' Exit Property ' End If ' lngHandle = inHandle ' ' For i = LBound(pFIO) To UBound(pFIO) ' Set T(i) = pFIO(i) ' Next i ' FIO = T 'End Property '''''''''''''''''''''' ' temperature '''''''''''''''''''''' Public Property Get Temperature(inHandle As Long) As String Dim i As Integer: Dim T As Double If inHandle = 0 Then Call MsgBox("U3 not initialized", vbCritical, "LJ Initialization Error") Exit Property End If lngHandle = inHandle lngErrorcode = eGet(lngHandle, LJ_ioGET_AIN, 30, T, 0) ErrNo = lngErrorcode: If ErrorLJ(ErrNo, "eGet") Then Exit Property Temperature = Format(T - 273.15, "#.0 °C") & "" End Property Public Sub CloseUD() Call Close  End Sub Private Function ErrorLJ(ByVal ErrNo As Long, CallStr As String) As Integer ErrorLJ = ErrNo If ErrNo Then Call MsgBox("LabJack Error, ErrNo = " & ErrNo & vbCrLf & "on: " & CallStr, vbCritical, "LJ Initialization Error") End Function