Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/USB/LibUSB Test
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /USB/LibUSB Test
This example is the version from Fri, 15th Feb 2018.
Project "LibUSB Test.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer) dim v as variant = me.RowTag(row) if v isa LibUSBDeviceMBS then dim d as LibUSBDeviceMBS = v List.AddRow "BusNumber", str(d.BusNumber) List.AddRow "DeviceAddress", str(d.DeviceAddress) List.AddRow "DeviceSpeed", str(d.DeviceSpeed) dim dd as LibUSBDeviceDescriptorMBS = d.GetDeviceDescriptor if dd <> nil then List.AddFolder "Device Descriptor" List.RowTag(List.LastIndex) = dd dim NumConfigurations as integer = dd.NumConfigurations for i as integer = 0 to NumConfigurations-1 dim dc as LibUSBConfigDescriptorMBS = d.GetConfigDescriptor(i) List.AddFolder "Config Descriptor "+str(i) List.RowTag(List.LastIndex) = dc next end if end if if v isa LibUSBDeviceDescriptorMBS then dim d as LibUSBDeviceDescriptorMBS = v dim dev as LibUSBDeviceMBS = FindDevice(row) // to query device for descriptors, we need to connect. if not dev.IsOpen then if dev.Open then System.DebugLog "Open okay." else System.DebugLog "Open failed." end if end if List.AddRow "DescriptorType", str(d.DescriptorType) List.AddRow "USBReleaseNumber", hex(d.USBReleaseNumber) List.AddRow "DeviceClass", str(d.DeviceClass) List.AddRow "DeviceSubClass", str(d.DeviceSubClass) List.AddRow "DeviceProtocol", str(d.DeviceProtocol) List.AddRow "MaxPacketSize0", str(d.MaxPacketSize0) List.AddRow "VendorID", str(d.VendorID) List.AddRow "ProductID", str(d.ProductID) List.AddRow "DeviceReleaseNumber", str(d.DeviceReleaseNumber) List.AddRow "IndexManufacturer", str(d.IndexManufacturer) if dev.IsOpen then dim s as string = dev.GetStringDescriptor(d.IndexManufacturer, 0) if s <> "" then List.AddRow "Manufacturer", s else s = dev.GetStringDescriptorAscii(d.IndexManufacturer) List.AddRow "Manufacturer ASCII", s end if end if List.AddRow "IndexProduct", str(d.IndexProduct) if dev.IsOpen then dim s as string = dev.GetStringDescriptor(d.IndexProduct, 0) if s <> "" then List.AddRow "Product", s else s = dev.GetStringDescriptorAscii(d.IndexProduct) List.AddRow "Product ASCII", s end if end if List.AddRow "IndexSerialNumber", str(d.IndexSerialNumber) if dev.IsOpen then dim s as string = dev.GetStringDescriptor(d.IndexSerialNumber, 0) if s <> "" then List.AddRow "SerialNumber", s else s = dev.GetStringDescriptorAscii(d.IndexSerialNumber) List.AddRow "SerialNumber ASCII", s end if end if List.AddRow "NumConfigurations", str(d.NumConfigurations) end if if v isa LibUSBConfigDescriptorMBS then dim d as LibUSBConfigDescriptorMBS = v dim NumInterfaces as integer = d.NumInterfaces List.AddRow "DescriptorType", str(d.DescriptorType) List.AddRow "TotalLength", str(d.TotalLength) List.AddRow "NumInterfaces", str(NumInterfaces) List.AddRow "ConfigurationValue", str(d.ConfigurationValue) List.AddRow "Configuration", str(d.Configuration) List.AddRow "Attributes", str(d.AttributesBitmap) List.AddRow "MaxPower", str(d.MaxPower) for i as integer = 0 to NumInterfaces-1 dim dc as LibUSBInterfaceMBS = d.GetInterface(i) List.AddFolder "Interface "+str(i) List.RowTag(List.LastIndex) = dc next end if if v isa LibUSBInterfaceMBS then dim d as LibUSBInterfaceMBS = v dim Count as integer = d.Count List.AddRow "Count", str(Count) for i as integer = 0 to Count-1 dim dc as LibUSBInterfaceDescriptorMBS = d.InterfaceDescriptor(i) List.AddFolder "Interface Descriptor "+str(i) List.RowTag(List.LastIndex) = dc next end if if v isa LibUSBInterfaceDescriptorMBS then dim d as LibUSBInterfaceDescriptorMBS = v dim NumEndpoints as integer = d.NumEndpoints List.AddRow "DescriptorType", str(d.DescriptorType) List.AddRow "InterfaceNumber", str(d.InterfaceNumber) List.AddRow "AlternateSetting", str(d.AlternateSetting) List.AddRow "NumEndpoints", str(NumEndpoints) List.AddRow "InterfaceClass", str(d.InterfaceClass) List.AddRow "InterfaceSubClass", str(d.InterfaceSubClass) List.AddRow "InterfaceProtocol", str(d.InterfaceProtocol) List.AddRow "IndexInterface", str(d.IndexInterface) for i as integer = 0 to NumEndpoints-1 dim dc as LibUSBEndpointDescriptorMBS = d.EndpointDescriptor(i) List.AddFolder "Endpoint Descriptor "+str(i) List.RowTag(List.LastIndex) = dc next end if if v isa LibUSBEndpointDescriptorMBS then dim d as LibUSBEndpointDescriptorMBS = v List.AddRow "DescriptorType", str(d.DescriptorType) List.AddRow "EndpointAddress", str(d.EndpointAddress) List.AddRow "AttributesBitmap", str(d.AttributesBitmap) List.AddRow "MaxPacketSize", str(d.MaxPacketSize) List.AddRow "Interval", str(d.Interval) List.AddRow "Refresh", str(d.Refresh) List.AddRow "SynchAddress", str(d.SynchAddress) List.AddRow "TransferType", str(d.TransferType) List.AddRow "EndpointDirection", str(d.EndpointDirection) end if End EventHandler
End Control
EventHandler Sub Open() #if TargetWindows then #if Target64Bit then call LibUSBDeviceMBS.LoadLibrary("libusb0.dll") #else call LibUSBDeviceMBS.LoadLibrary("libusb0_x86.dll") #endif #endif List.AddRow "LibraryLoaded", yes(LibUSBDeviceMBS.LibraryLoaded) List.AddRow "LibraryLoadErrorMessage", LibUSBDeviceMBS.LibraryLoadErrorMessage List.AddRow "" if LibUSBDeviceMBS.LibraryLoaded then try dim v as LibUSBVersionMBS = LibUSBDeviceMBS.LibVersion List.AddRow "LibVersion.Major", str(v.Major) List.AddRow "LibVersion.Minor", str(v.Minor) List.AddRow "LibVersion.Micro", str(v.Micro) List.AddRow "LibVersion.Nano", str(v.Nano) List.AddRow "LibVersion.RC", str(v.RC) List.AddRow "LibVersion.Describe", str(v.Describe) List.AddRow "" catch f as FunctionNotFoundException end try dim r as integer = LibUSBDeviceMBS.Initialize if r = 0 then dim Devices() as LibUSBDeviceMBS = LibUSBDeviceMBS.Devices for each device as LibUSBDeviceMBS in devices List.AddFolder "Device "+str(device.BusNumber)+":"+str(device.DeviceAddress) List.RowTag(List.LastIndex) = device next end if end if End EventHandler
Function FindDevice(row as integer) As LibUSBDeviceMBS for i as integer = row downto 0 dim v as Variant = List.RowTag(i) if v isa LibUSBDeviceMBS then return v end if next End Function
Shared Function Yes(b as Boolean) As string if b then Return "Yes" else return "No" end if End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections

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

MBS Xojo Chart Plugins