...
Connect
Open a UsbDeviceConnection on the UsbSerialDriver’s UsbDevice using UsbManager.openDevice
Get the correct UsbSerialPort from the UsbSerialDriver using UsbSerialDriver.getPorts
Most devices only have one port
Preliminary prototyping has shown that the VictoR device exposes two ports
The correct port appears to be the 2nd port (port 1, not port 0)
Open the port, providing the open UsbDeviceConnection using UsbSerialPort.open
Disconnect
As with connect, get the correct UsbSerialPort from the UsbSerialDriver using UsbSerialDriver.getPorts
Close the port using UsbSerialPort.close
This also closes the open UsbDeviceConnection
Read
Send a read request using UsbSerialPort.write
Read the response using UsbSerialPort.read
Write
Send a write request using UsbSerialPort.write
Verify the write was successful by reading the response using UsbSerialPort.read
Subscribe to Connection State Changes
Add the provided user callback to the set of connection state change callbacks
When the device connects or disconnects, invoke each callback in the set with the corresponding connection state
To detect connection state changes, a thread will be needed to continuously poll the serial port status
If the device is disconnected, an attempt to reconnect should be made.
Unsubscribe from Connection State Changes
Remove the provided user callback from the set of connection state change callbacks
Subscribe to Attribute Changes
Send a subscribe request using UsbSerialPort.write
Verify the subscribe was successful by reading the response using UsbSerialPort.read
This is not possible as it appears the VictoR firmware doesn’t currently support this.
Success will instead indicate that the request was successfully communicated to the device, not necessarily that the device acknowledged it.
Unsubscribe from Attribute Changes
Send an unsubscribe request using UsbSerialPort.write
Verify the unsubscribe was successful by reading the response using UsbSerialPort.read
This is not possible as it appears the VictoR firmware doesn’t currently support this.
Success will instead indicate that the request was successfully communicated to the device, not necessarily that the device acknowledged it.
VictorUsbDeviceManager
Scan for Devices
Using the Android SDK:
Get the UsbManager from the application Context using Context.getSystemService
Using the USB Serial for Android library:
Create a ProbeTable with the Vendor ID and Product ID of the VictoR device
Create a custom UsbSerialProber using this custom ProbeTable
Use this custom UsbSerialProber to find all UsbSerialDrivers using UsbSerialProber.findAllDrivers
findAllDrivers is not a timed, asynchronous operation
UsbSerialProber has no concept of a scan time
This class will ignore the scan time field of the VictorDeviceScanParameters provided to it
API documentation for this class will make note of this fact
Track all UsbSerialDrivers discovered in a map keyed on the device name (address) using UsbDevice.getDeviceName()
Use the Android Intent system to request permission to communicate with the UsbDevice within each UsbSerialDriver as outlined here
Get all Devices
Maintain a map of all UsbSerialDrivers that have been scanned, connected, or disconnected at any point
Key the map using UsbDevice.getDeviceName()
Get Scanned Devices
Maintain a map of all UsbSerialDrivers that have been discovered during the last scan
Key the map using UsbDevice.getDeviceName()
Clear the map each time a scan is performed
Get Connected Devices
Maintain a map of all UsbSerialDrivers that are currently connected
Key the map using UsbDevice.getDeviceName()
Add devices as they are connected
Remove devices when they disconnect
Connect
Find the specified device from the map of connected devices
If it can be found, then call Device.Connect
Disconnect
Find the specified device from the map of connected devices
If the device is found, then call Device.Disconnect
Read
Find the specified device from the map of connected devices
If the device is found, then call Device.Read
Write
Find the specified device from the map of connected devices
If the device is found, then call Device.Write
Subscribe to Connection State Changes
Find the specified device from the map of connected devices
If the device is found, then call Device.SubscribeConnectionStateChange
Unsubscribe from Connection State Changes
Find the specified device from the map of connected devices
If the device is found, then call Device.UnsubscribeConnectionStateChange
Subscribe to Attribute Changes
Find the specified device from the map of connected devices
If the device is found, then call Device.SubscribeAttributeChange
Unsubscribe from Attribute Changes
Find the specified device from the map of connected devices
If the device is found, then call Device.UnsubscribeAttributeChange
...