Xojo Conferences

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/Phidget/Phidget01616
This example is the version from Sun, 17th Mar 2012.
Project "Phidget01616.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() ' call loadPhidgetFrameworkMBS, LoadPhidgetWindowsDLLMBS or LoadPhidgetLinuxLibraryMBS #if TargetMacOS //Mac Dim f as FolderItem f = FrameworksFolderMBS(-32765).Child("Phidget21.framework") if LoadPhidgetFrameworkMBS(f) Then MsgBox("Framework loaded") Else MsgBox("Failed to load Mac Framework") End if #endif //For Linix, see LoadPhidgetLinuxLibraryMBS //I have not tested this application on Linux #if TargetWin32 'Windows: (Your file path to the DLLmay be different.) if LoadPhidgetWindowsDLLMBS("C:\Program Files\Phidgets\phidget21.dll") Then MsgBox("Framework loaded") Else MsgBox("Failed to load Windows Framework") End if #endif p = new MyPhidgetInterfaceKitMBS End EventHandler
Note "ReadMe"
This application was developed on WindowsXp SP2, RealBasic 2007 R4, with a Phidgets Interface Kit 0-16-16. It requires the following MBS plugins: MBS REALbasic USB Plugin MBS Main Plugin (for Macintosh) for the invocation of FrameworksFolderMBS The Windows version is hardcoded for the Phidgets library: C:\Program Files\Phidgets\phidget21.dll. I wrote it to detect if fewer than 16 inputs or outputs are available and to hide the excess input & output controls and indicators. However, I do not have a lesser input/output device like an 8-8-8 or an 0-0-4 to test with. I also have no analog Phidgets, so this program tests only Digital Inputs and Outputs. All display items show the 1-based input/output number, not the 0-based index. This program only handles a single Phidget at a time. Tested on: Windows XP SP2, Core 2 Duo, USB2 Mac OS X 10.4.x, PPC, USB 1.1(?) Not Tested on: Linux jackD codeman@cox.net
Property p As MyPhidgetInterfaceKitMBS
End Class
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control StaticText8 Inherits Label
ControlInstance StaticText8 Inherits Label
End Control
Control StaticText9 Inherits Label
ControlInstance StaticText9 Inherits Label
End Control
Control StaticText10 Inherits Label
ControlInstance StaticText10 Inherits Label
End Control
Control StaticText11 Inherits Label
ControlInstance StaticText11 Inherits Label
End Control
Control StaticText12 Inherits Label
ControlInstance StaticText12 Inherits Label
End Control
Control StaticText13 Inherits Label
ControlInstance StaticText13 Inherits Label
End Control
Control StaticText14 Inherits Label
ControlInstance StaticText14 Inherits Label
End Control
Control StaticText15 Inherits Label
ControlInstance StaticText15 Inherits Label
End Control
Control StaticText16 Inherits Label
ControlInstance StaticText16 Inherits Label
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1(0) Inherits CheckBox
ControlInstance CheckBox1(1) Inherits CheckBox
ControlInstance CheckBox1(2) Inherits CheckBox
ControlInstance CheckBox1(3) Inherits CheckBox
ControlInstance CheckBox1(4) Inherits CheckBox
ControlInstance CheckBox1(5) Inherits CheckBox
ControlInstance CheckBox1(6) Inherits CheckBox
ControlInstance CheckBox1(7) Inherits CheckBox
ControlInstance CheckBox1(8) Inherits CheckBox
ControlInstance CheckBox1(9) Inherits CheckBox
ControlInstance CheckBox1(10) Inherits CheckBox
ControlInstance CheckBox1(11) Inherits CheckBox
ControlInstance CheckBox1(12) Inherits CheckBox
ControlInstance CheckBox1(13) Inherits CheckBox
ControlInstance CheckBox1(14) Inherits CheckBox
ControlInstance CheckBox1(15) Inherits CheckBox
End Control
Control CheckBox17 Inherits CheckBox
ControlInstance CheckBox17(0) Inherits CheckBox
ControlInstance CheckBox17(1) Inherits CheckBox
ControlInstance CheckBox17(2) Inherits CheckBox
ControlInstance CheckBox17(3) Inherits CheckBox
ControlInstance CheckBox17(4) Inherits CheckBox
ControlInstance CheckBox17(5) Inherits CheckBox
ControlInstance CheckBox17(6) Inherits CheckBox
ControlInstance CheckBox17(7) Inherits CheckBox
ControlInstance CheckBox17(8) Inherits CheckBox
ControlInstance CheckBox17(9) Inherits CheckBox
ControlInstance CheckBox17(10) Inherits CheckBox
ControlInstance CheckBox17(11) Inherits CheckBox
ControlInstance CheckBox17(12) Inherits CheckBox
ControlInstance CheckBox17(13) Inherits CheckBox
ControlInstance CheckBox17(14) Inherits CheckBox
ControlInstance CheckBox17(15) Inherits CheckBox
EventHandler Sub Action(index as Integer) //Process the outputs if Window1.CheckBox17(index).value then app.p.setOutputState(index,true) else app.p.setOutputState(index,false) end if End EventHandler
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
EventHandler Sub Close() app.p.Close End EventHandler
EventHandler Sub Open() // Open Phidget // -1 for first device app.p.Open -1 End EventHandler
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 MyPhidgetInterfaceKitMBS Inherits PhidgetInterfaceKitMBS
EventHandler Sub Attach() Window1.Listbox1.AddRow "Attached" Dim numInputs as integer = app.p.getInputCount Dim numOutputs as integer = app.p.getOutputCount // DEBUG: To simulate Phidget interface kit 0-0-4 or 8-8-8 uncomment the appropriate lines below 'numInputs = 8 'or 4 'numOutputs = 8 'or 0 Window1.StaticText7.Text =app.p.GetDeviceName Window1.StaticText8.Text =app.p.GetDeviceLabel Window1.StaticText9.Text =app.p.GetDeviceType Window1.StaticText10.Text =str(app.p.GetDeviceStatus) Window1.StaticText11.Text =str(app.p.GetDeviceVersion) Window1.StaticText12.Text =str(app.p.GetSerialNumber) Window1.StaticText14.Text =str(numInputs) Window1.StaticText16.Text =str(numOutputs) //Show or hide checkboxes as needed dim i as integer for i =0 to 15 Window1.Checkbox1(i).Visible = (i < numInputs) Window1.Checkbox17(i).Visible = (i < numOutputs) next End EventHandler
EventHandler Sub Detach() Window1.Listbox1.AddRow "Detached" //need to be sure all DI and DO boxes are reset and invisible on dettach... dim i as integer for i = 0 to 15 Window1.Checkbox1(i).Value = False Window1.Checkbox1(i).Visible = False Window1.Checkbox17(i).Value = False Window1.Checkbox17(i).Visible = False next i End EventHandler
EventHandler Sub Error(errorCode as integer, errorDescription as string) Window1.Listbox1.AddRow "Error " + str(errorCode)+": "+errorDescription End EventHandler
EventHandler Sub InputChanged(index as integer, value as integer) //Set Input Checkboxes as needed Window1.CheckBox1(index).value = (value = 1) Window1.CheckBox1(index).Bold = (value = 1) //Log any changes in digital inputs //NOTE: Entry displays the 1-based input number, not the 0-based index number Window1.ListBox1.Addrow "Input changed at DI#: "+str(index+1)+" New value: " +str(value) End EventHandler
EventHandler Sub OutputChanged(index as integer, value as integer) //Log any changes in digital outputs //NOTE: Entry displays the 1-based output number, not the 0-based index number Window1.ListBox1.Addrow "Output changed at DO#: "+str(index+1)+" New value: " +str(value) End EventHandler
End Class
End Project

Feedback, Comments & Corrections

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

MBS FileMaker blog