You find this example project in your Plugins Download as a Xojo project file within the examples folder: /USB/USBtest
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
// This is for the Custom Computer Services Inc.
// PIC24 development board. http://www.ccsinfo.com/product_info.php?products_id=usb-pic24-kit
// At present this is for Mac only, will need to add target testing and Windows code
App.mycount = 0
if not InitInstance then
quit
end if
End EventHandler
Protected Function FindDevice() As MyHID
dim h as MyHID
dim p as string
h=new MyHID
if h.FindFirstDevice then
// compare here Product name, ProductID and VendorID
p=h.Product
if left(p,3)="CCS" then
Return h
end if
while h.FindNextDevice
p=h.Product
if left(p,3)="CCS" then
Window1.statusField.BackColor = &C00FF00
Window1.statusField.Text = "CCS demo Connected"
Return h
end if
wend
end if
End Function
Function InitInstance() As boolean
if OpenUSBDevice = False Then
Return False
Else
Return True
end if
End Function
Function OpenUSBDevice() As boolean
h=FindDevice
if h=nil then
MsgBox "No CCS device found."
quit
Return false
end if
h.Connect
if h.Lasterror<>0 then
MsgBox "Failed to connect to CCS Device."
quit
Return false
end if
h.InstallCallback
Return true
End Function
Note "Description"
Property h As myHID
Property myCount As Integer
End Class
Class Window1 Inherits Window
Control statusField Inherits TextField
ControlInstance statusField Inherits TextField
End Control
Control RxDataField Inherits TextArea
ControlInstance RxDataField Inherits TextArea
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
Window1.RxDataField.Text = Window1.RxDataField.Text + chr(13)
App.h.Send chr(86)
End EventHandler
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyHID Inherits MacHIDMBS
EventHandler Sub ReceivedData(data as string, size as integer)
Window1.RxDataField.Text = Window1.RxDataField.Text + data
App.mycount = App.mycount + 1
End EventHandler
Sub Send(data As string)
dim m as New MemoryBlock(16)
m.StringValue(0, 1) = data
me.SendMessageMemory m, 0, 16
if me.Lasterror = -536854447 Then
MsgBox "The USB Receiver failed with a timeout to send an answer"
Quit
end if
End Sub
End Class