VisualBasic Developer's API usage examples

The following shows sample application framework using SP_InitAllDevices()
for sample application framework using SP_InitAllDevices_Thread() go here
 





Samples shown for Win98/WinME only
For Win2k/WinXP change only
LL_USB.DLL   to   LL_USB2k.DLL
in all prototypes and calls shown below


Variable type syntaxing
go HERE for description of each







Function call prototypes from module file
(only those used in following example shown)

Declare Function SP_InitAllDevices Lib "LL_USB.DLL" _
          (ByRef pausDevList As Integer, ByRef pbNumDevices_SP As Byte, ByRef padblRate As Double, ByVal fShowDevList As Byte) As Byte

Declare Function SP_GetOneConversion Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByRef puiConvRawCount as Long, ByVal bCurChan As Byte, ByRef pbLastDigin as Byte) As Byte

Declare Function DLL_StartScan_DIO Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByRef pScanObject As SCAN_OBJECT, ByVal bReserved As Byte) As Byte

Declare Function DLL_ReadScanData_DIO Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByRef pauiDataBuff as Long, ByVal usNumPointsToRead As Integer, _
          ByRef pScanObject As SCAN_OBJECT) As Byte

Declare Function SP_EndScan Lib "LL_USB.DLL" (ByVal usDevID) As Byte

Declare Function SP_SendChan Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByVal bCurChan as Byte, ByRef pbLastDigin As Byte) As Byte

Declare Function SP_SendDigOut Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByVal bDigOut as Byte, ByRef pbLastDigin As Byte) As Byte

Declare Function SP_SendDAC Lib "LL_USB.DLL" _
          (ByVal usDevID As Integer, ByVal dblVoltage as Double, ByVal bDAC As Byte, ByVal bReserved as Byte) As Byte

Declare Function SP_SendRate Lib "LL_USB.DLL" (ByVal dblVoltage as Double, ByVal usDevID As Integer) As Byte








Variables prototypes from module file

Initialization related
Public Const MAX_DEV_CNT = 32

Public pausDevList() As Integer
Public padblRate(MAX_DEV_CNT) As Double
Public pbNumDevices As Byte
Public fShowDevList As Byte
Public bCurChan As Byte
Public pbLastDigin As Byte
Public bCurListIndex As Byte



Get one conversion
Public puiConvRawCount() As Long



Scan related
Type SCAN_OBJECT      'NOTE:  Most commonly used members are underlined
SO_bScanType As Byte app writes (needed by DLL to start scan)
SO_dblDevRate As Double app writes (needed by DLL to start scan)
SO_iTotalPointsReadByDrvr As Long DLL writes (can be read by app)
SO_iPointsInBuffer As Long DLL writes (app reads this to get num points available to be read)
SO_iStatus As Long DLL writes (important scanning status information needed by app)
SO_iSizeVoltageArray As Long No longer used (but must be present as placeholder)
SO_iCurHead As Long DLL writes (can be read by app)
SO_iCurTail As Long DLL writes (can be read by app)
SO_bDigitalInput As Byte DLL writes (can be read by app)
SO_bChecksum As Byte DLL writes (can be read by app)
SO_DeviceDisconnect As Byte No longer used (but must be present as placeholder)
SO_iScanStartTime As Long No longer used (app may use for convenience)
SO_iScanEndTime As Long No longer used (app may use for convenience)
SO_bScanArg As Byte app writes (needed by DLL to start scan)
End Type
Public pScanObjectArray() As SCAN_OBJECT
'NOTE:  The following are possible bit settings for SO_Status shown above
Public Const SCAN_RUNNING = &H1 not currently used
Public Const SCAN_DATA_REQUEST_SUCCEEDED = &H2 not currently used
Public Const SCAN_ENDING = &H4 not currently used
Public Const SCAN_HALTED = &H8 if set, the device is no longer scanning
Public Const SCAN_CHECKSUM_ERROR = &H10 if set there has been a checksum error
Public Const SCAN_VOLTAGE_BUFFER_WRAP = &H20 indicates a wrap in the DLL's data buffer
Public Const SCAN_MICRO_CODE_BUFF_WRAP = &H40 indicates a wrap in the device's data buffer
Public Const SCAN_DEVICE_IO_ERROR = &H80 indicates I/O error
Public Const SCAN_DEVICE_DISCONNECTED = &H100 The device has been disconnected
Public Const SCAN_DEVICE_NOT_FOUND = &H200 not currently used
Public pauiDataBuff() As Long
Public usNumPointsToRead() As Integer
Public faDevScanning(MAX_DEV_CNT) As Byte
Public faDevStopScanRequest(MAX_DEV_CNT) As Byte









Function call examples

Preinitialization
Public Sub DoPreInitialization()
' Initialize global variables that will be used later on

Dim bArrayIndex as Byte
For bArrayIndex = MAX_DEV_CNT - 1
pausDevList(bArrayIndex) = 0
padblRate(bArrayIndex) = 0
faDevScanning(bArrayIndex) = 0
faDevStopScanRequest(bArrayIndex) = 0
pbNumDevices = 0
fShowDevList = 0
bCurChan = 0
pbLastDigin = 0
bCurListIndex = 0
Next bArrayIndex

End Sub



Initialize all devices
Public Sub Initialize()

pausDevList(0) = 199:   pausDevList(1) = 276:
padblRate(0) = 200   padblRate(1) = 600
fShowDevList = 0

fRetVal = SP_InitAllDevices(pausDevList(0), pbNumDevices, padblRate, fShowDevList)
NOTE:
    This function does not return until it's attempted to initialize all of the devices listed in pausDevList. Each device could take up to 3 seconds. If you are using 3 or more devices, it's recommended that you use SP_InitAllDevices_Thread(), discussed elsewhere within this documentation.
    Place only those devices that you wish to initialize, in the pausDevList array, any devices already initialized will remain undisturbed.

'handle any errors here
End Sub



GetOneConversion
Public Sub SP_GetOneConversion()

bCurListIndex = 0
Dim dblCurVoltage as Double
Dim iCurRawCount as Long

fRetVal = SP_GetOneConversion(pausDevList(bCurListIndex), puiConvRawCount, bCurChan, pbLastDigin)

'handle any errors here

iCurRawCount = puiConvRawCount(0)
dblCurVoltage = (iCurRawCount - 8388608) * 0.00000059604645     ' display +-5 volt range
VoltageDisplayBox = Format$(dblCurVoltage, "#####.000000")

End Sub



Scanning
Public Sub DoScan()
NOTE: The following is just a simple overview of the scanning procedure.
Please see sample source code downloadable from web site for better example.

bCurListIndex = 0
Dim bCurScanDevIndex as Byte: bCurScanDevIndex = 0
Dim fAnyDevScanning as Byte: fAnyDevScanning = 0

Dim dblCurVoltage as Double
Dim iCurRawCount as Long
ReDim pScanObjectArray pbNumDevices
For bArrayIndex = 0 To pbNumDevices - 1
pScanObjectArray(bArrayIndex).SO_iStatus = 0
pScanObjectArray(bArrayIndex).SO_iCurHead = 0
pScanObjectArray(bArrayIndex).SO_iCurTail = 0
pScanObjectArray(bArrayIndex).SO_iPointsInBuffer = 0
pScanObjectArray(bArrayIndex).SO_iTotalPointsReadByDrvr = 0

fRetVal = DLL_StartScan_DIO(pausDevList(bArrayIndex), pScanObjectArray(bArrayIndex), 0)
If fRetVal Then
faDevScanning(bArrayIndex) = 1
fAnyDevScanning = 1
End If
Next bArrayIndex

'if no devices started scanning exit this function
If fAnyDevScanning = 0 then goto EXIT_SCAN:

ReDim pauiDataBuff 10
usNumPointsToRead = 10

While fAnyDevScanning = 1
For bArrayIndex = 0 To pbNumDevices - 1
DoEvents
fRetVal = 0
If faDevScanning(bArrayIndex) = l Then
fRetVal = DLL_ReadScanData_DIO(pausDevList(bArrayIndex), pauiDataBuff(0), usNumPointsToRead, pScanObjectArray(bArrayIndex)

If fRetVal Then
iCurRawCount = puiConvRawCount(0)
dblCurVoltage = (iCurRawCount - 8388608) * 0.00000059604645
VoltageDisplayBox = Format$(dblCurVoltage, "#####.000000")
Else
'check for errors
End If
End If

If faDevStopScanRequest(bArrayIndex) Then
fRetVal = SP_EndScan(pausDevList(bArrayIndex))
faDevScanning(bArrayIndex) = 0

fAnyDevScanning = 0
Dim bTempIndex as Byte
For bTempIndex = 0 To pbNumDevices - 1
If faDevScanning(bTempIndex) = 1 then fAnyDevScanning = 1
Next bTempIndex
End If
Next bArrayIndex
Wend
EXIT_SCAN:
End Sub



Channel Change
Public Sub SendChan()

Dim bChanToSendLocal as Byte
bChanToSendLocal = 7
bCurListIndex = 0

fRetVal = SP_SendChan(pausDevList(bCurListIndex), bCurChan, pbLastDigin)

'handle any errors here
'update controls to reflect new channel and digital input value


End Sub



Send digital output
Public Sub SendDigOut()

Dim bDigOut as Byte
bDigOut = 128
bCurListIndex = 0

fRetVal = SP_SendDigOut(pausDevList(bCurListIndex), bDigOut, pbLastDigin)

'handle any errors here
'update controls to reflect new digital output/input values


End Sub



Send analog output
Public Sub SendAnalogOut()
'supported by 302 only

Dim bDAC as Byte
Dim dblVoltage as Double
bDAC = 1
bCurListIndex = 0
dblVoltage = 2.5

fRetVal = SP_SendDAC(pausDevList(bCurListIndex), dlbVoltage, bDAC, bReserved)

'handle any errors here
'update controls to reflect new DAC settings


End Sub



Change rate
Public Sub SendRate()

Dim dblRate as Double
bCurListIndex = 0
dblRate = 600#

fRetVal = SP_SendRate(dlbRate, pausDevList(bCurListIndex))

'handle any errors here
'update controls to reflect new rate settings


End Sub


back to main page Table of Contents     (use browser "back" button to go back to other locations)




lawsnlab@lawsonlabs.com
last reviewed/modified: 9-29-03 (Tim Van Dusen)