Private Const NUM_OF_VARS = 2
Private Const WIDGET_INPUTDATA_NAME = "widget_inputdata"
Private Const WIDGET_INPUTDATA_USG_PG = 65280
Private Const WIDGET_INPUTDATA_USG = 1
Private Const WIDGET_INPUTDATA_RPT_TYPE = 0
' Input (0 = Input, 1 = Output, 2 = Feature)
Private Const WIDGET_INPUTDATA_IDENTITY = 1
' Config or Identity this var belongs to
Private Const WIDGET_OUTPUTDATA_NAME = "widget_outputdata"
Private Const WIDGET_OUTPUTDATA_USG_PG = 65280
Private Const WIDGET_OUTPUTDATA_USG = 2
Private Const WIDGET_OUTPUTDATA_RPT_TYPE = 1
' Input (0 = Input, 1 = Output, 2 = Feature)
Private Const WIDGET_OUTPUTDATA_IDENTITY = 1
' Config or Identity this var belongs to
*******************************************************************Private Sub ReadRptsBtn_Click()
Dim AStr As String
Dim DevNum As Long
Dim i As Long
ClearBtn_Click
For DevNum = 1 To cc_widget.Count
AddToResults ("")
AStr = "Device #" + Str$(DevNum) + ":"
AddToResults (AStr)
If cc_widget.Item(DevNum).ReadAllReports Then
AStr = " widget_inputdata " + Str$(cc_widget(DevNum).widget_inputdata.UnScaledValue)
AddToResults (AStr)
Else
Beep
AStr = "+ + + Unable to read from device" + Str$(DevNum) + "! + + +"
AddToResults (AStr)
End If
Next DevNum
End Sub
*******************************************************************
Private Sub SendRptsBtn_Click()
Dim AStr As String
Dim DevNum As Long
Dim i As Long
Dim MaxVal As Long
'
For DevNum = 1 To cc_widget.Count
AddToResults ("")
cc_widget(DevNum).widget_outputdata.UnScaledValue = 85
' Activate next 2 lines to send random values
'MaxVal = 127
'cc_widget(DevNum).widget_outputdata.UnScaledValue =
Int((MaxVal+1) * Rnd(1))
AStr = " Wrote to device: widget_outputdata = 0x" +
Hex$(cc_widget(DevNum).widget_outputdata.UnScaledValue)
AddToResults (AStr)
If cc_widget(DevNum).WriteAllReports Then
' Success
AddToResults (" Successfully wrote to device")
Else
' Failure
Beep
AStr = "+ + + Unable to send to device" +
Str$(DevNum) + "! + + +"
AddToResults (AStr)
End If
Next DevNum
End Sub
Listing 2—The variable cc_widget
data is used by the Visual Basic 6 side of the USB link along with the USB peripheral
widget_inputdata and widget_outputdata data variables. Visual Basic 6 works with
events, while the USB peripheral code is actually a round-robin multitasking environment.