Platforms to show: All Mac Windows Linux Cross-Platform

Required plugins for this example: MBS USB Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /USB/HID Mac/USB HID IO Warrior Mac OS X LEDs
This example is the version from Sun, 17th Mar 2012.
Project "USB HID IO Warrior Mac OS X LEDs.xojo_binary_project"
Class Window1 Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() 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 EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Open() if not TargetMachO then MsgBox "Please use only with MachO targets on Mac OS X!" quit end if OpenUSBDevice End EventHandler
Protected Function FindDevice() As MyHID dim h as MyHID dim p as string h=new MyHID if h.FindFirstDevice then if h.ProductID=&h1500 and h.VendorID=&h7C0 then Return h end if while h.FindNextDevice if h.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 h.Connect if h.Lasterror<>0 then MsgBox "Failed to connect to "+h.Product+" Device." h=nil quit Return end if h.InstallCallback listbox1.AddRow "OpenUSBDevice done" timer1.mode=2 End Sub
Sub send(n as integer) dim m as MemoryBlock 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 h.ProductID case IOWKIT_PRODUCT_ID_IOW40 m=NewMemoryBlock(IOWKIT40_IO_REPORT_SIZE-1) m.Byte(4-1)=n case IOWKIT_PRODUCT_ID_IOW24 m=NewMemoryBlock(IOWKIT24_IO_REPORT_SIZE-1) m.Byte(1-1)=n case IOWKIT_PRODUCT_ID_IOW56 m=NewMemoryBlock(IOWKIT56_IO_REPORT_SIZE-1) m.Byte(7-1)=n else // unknown product? Return end Select m.Byte(0)=IOW_PIPE_IO_PINS h.SendMessageMemory(m,0,m.size) Exception End Sub
Property Protected counter As integer
Property Protected h As myhid
Property Protected last As integer
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
Property quitting As boolean
End Class
Class MyHID Inherits MacHIDMBS
EventHandler Sub ReceivedData(data as string, size as integer) // we received something window1.listbox1.AddRow "Received: "+EncodingToHexMBS(data) End EventHandler
Sub Constructor() TimeOut=2222 End Sub
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS USB Plugin.

The biggest plugin in space...

MBS Xojo Plugins

Start Chat