Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/USB/Phidget/PhidgetMotorControl Test with Events
Function:
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/PhidgetMotorControl Test with Events
This example is the version from Sun, 17th Mar 2012.
Project "PhidgetMotorControl Test with Events.rbp"
FileTypes
Filetype text
End FileTypes
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 StaticText17 Inherits Label
ControlInstance StaticText17 Inherits Label
End Control
Control StaticText18 Inherits Label
ControlInstance StaticText18 Inherits Label
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() StaticText11.text=p.GetDeviceLabel StaticText10.text=p.GetDeviceName StaticText13.text=hex(p.GetDeviceStatus) StaticText12.text=p.GetDeviceType StaticText14.text=hex(p.GetDeviceVersion) StaticText15.text=hex(p.GetSerialNumber) StaticText16.text=str(p.getMotorCount) StaticText17.text=str(p.getAcceleration(0)) StaticText18.text=str(p.getVelocity(0)) StaticText20.text=str(p.getCurrent(0)) End EventHandler
End Control
Control StaticText19 Inherits Label
ControlInstance StaticText19 Inherits Label
End Control
Control StaticText20 Inherits Label
ControlInstance StaticText20 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // Set the acceleration to 100 for this example and intialize the velocity to 0.00 (stopped) p.setAcceleration 0, 100 p.setVelocity 0, 0 dim i as integer // Slowly speed the motor to full speed going one direction for i=0 to 100 DelayMBS(0.1) p.setVelocity 0,i next // Slowly speed down and start accelerating in the other direction for i=-100 to 100 DelayMBS(0.1) p.setVelocity 0,i next // Stop the motor p.setVelocity 0,0 End EventHandler
End Control
EventHandler Sub Close() p.Close End EventHandler
EventHandler Sub Open() ' call loadPhidgetFrameworkMBS, LoadPhidgetWindowsDLLMBS or LoadPhidgetLinuxLibraryMBS p=new MyPhidgetMotorControlMBS // -1 for first device p.Open -1 End EventHandler
Property Protected p As PhidgetMotorControlMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() dim f as FolderItem f=FrameworksFolderMBS(-32765).Child("Phidget21.framework") if LoadPhidgetFrameworkMBS(f) then MsgBox "Framework loaded" else MsgBox "Failed to load framework" end if // use LoadPhidgetWindowsDLLMBS on Windows // use LoadPhidgetLinuxLibraryMBS on Linux End EventHandler
End Class
Class MyPhidgetMotorControlMBS Inherits PhidgetMotorControlMBS
EventHandler Sub Attach() window1.ListBox1.AddRow "Attached" End EventHandler
EventHandler Sub CurrentChanged(index as integer, value as double) window1.ListBox1.AddRow "CurrentChanged index: "+str(index)+" value: "+str(value) End EventHandler
EventHandler Sub Detach() window1.ListBox1.AddRow "Detached" 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) window1.ListBox1.AddRow "InputChanged index: "+str(index)+" value: "+str(value) End EventHandler
EventHandler Sub VelocityChanged(index as integer, value as double) window1.ListBox1.AddRow "VelocityChanged index: "+str(index)+" 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.




Links
MBS Xojo Plugins