Platforms to show: All Mac Windows Linux Cross-Platform

/USB/HID/USB HID IO Warrior Windows LEDs
Feedback.

Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /USB/HID/USB HID IO Warrior Windows LEDs
This example is the version from Thu, 3rd Feb 2010.
Notes: Last modified: Thu, 3rd Feb 2010
Class Window1
Inherits Window
// Controls
ControlInstance
Sub Action() Handles Event
dim n as integer
dim v as integer

if CheckBox1.Value then
if counter>=16 then
counter=0
end if

if counter>=8 then

n=255-pow(2,15-counter)

else

n=255-pow(2,counter)

end if

send n

counter=counter+1

else
send counter

counter=counter+1
if counter=256 then
counter=0
end if
end if

End Sub
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance

// Properties
Protected Dim counter As integer
Protected Dim last As integer
Protected Dim h As WinHIDMBS
Protected Dim ProductID As integer

// Event implementations
Sub Open()
if not TargetWin32 then
MsgBox "Please use only with Windows!"
quit
end if

OpenUSBDevice

End Sub

// Methods
Protected Function FindDevice() As WinHIDMBS
dim h as WinHIDMBS
dim p as string

h=new WinHIDMBS

if h.FindFirstDevice then
ProductID=h.ProductID
if ProductID=&h1500 and h.VendorID=&h7C0 then
Return h
end if

while h.FindNextDevice
ProductID=h.ProductID
if ProductID=&h1500 and h.VendorID=&h7C0 then
Return h
end if

wend

end if


End Function
Sub OpenUSBDevice()
dim i as integer

listbox1.AddRow "OpenUSBDevice"

h=FindDevice

if h=nil then
MsgBox "No IOWarrior 40 device found."
quit
Return
end if

listbox1.AddRow h.Product

if not h.Connect then
MsgBox "Failed to connect to "+h.Product+" Device."+EndOfLine+EndOfLine+"Error: "+str(h.Lasterror)
h=nil
quit
Return
end if

listbox1.AddRow "OpenUSBDevice done"

timer1.mode=2

End Sub
Sub send(n as integer)
dim m as MemoryBlock
dim e as integer

const IOW_PIPE_IO_PINS=0

const IOWKIT40_IO_REPORT_SIZE=5
const IOWKIT24_IO_REPORT_SIZE=3
const IOWKIT56_IO_REPORT_SIZE=8

const IOWKIT_PRODUCT_ID_IOW40=&h1500
const IOWKIT_PRODUCT_ID_IOW24=&h1501
const IOWKIT_PRODUCT_ID_IOW56=&h1503

Select case ProductID
case IOWKIT_PRODUCT_ID_IOW40
m=NewMemoryBlock(IOWKIT40_IO_REPORT_SIZE)
m.Byte(4)=n

case IOWKIT_PRODUCT_ID_IOW24
m=NewMemoryBlock(IOWKIT24_IO_REPORT_SIZE)
m.Byte(1)=n

case IOWKIT_PRODUCT_ID_IOW56
m=NewMemoryBlock(IOWKIT56_IO_REPORT_SIZE)
m.Byte(7)=n

else
// unknown product?
Return
end Select

m.Byte(0)=IOW_PIPE_IO_PINS

e=h.SendMessageMemory(m,0,m.size)

System.DebugLog "SendMessageMemory: "+str(e)+" "+str(h.Lasterror)

Exception

End Sub
End Class

Class App
Inherits Application
// Properties
Dim quitting As boolean
End Class


See also:




Links
MBS REALbasic Plugins - Pfarrgemeinde Ministranten Nickenich