...
Additionally, users will need to add a dependency for the Serial Java library used by the SDK. This can be done by…
...
by modifying the settings.gradle file with the following highlighted
...
lines:
...
…and adding a reference to the git repo for the serial library to the relevant module.
...
Device Manager
Instantiation
The act of connecting and disconnecting to a device, as well as maintaining a record of connected devices, is handled by the device manager. Before any work can be done on reading, writing, and subscribing to services, users must first create and work with the device manager.
BLE
Code Block | ||
---|---|---|
| ||
import com.fn.victorcommunications.VictorBleDeviceManager; public class MainActivity extends Activity { VictorBleDeviceManager deviceManager; @Override public void onCreate(Bundle savedInstanceState) { deviceManager = new VictorBleDeviceManager(this); } } |
USB
Code Block | ||
---|---|---|
| ||
import com.fn.victorcommunications.VictorUsbDeviceManager;
public class MainActivity extends Activity
{
VictorUsbDeviceManager deviceManager;
@Override
public void onCreate(Bundle savedInstanceState)
{
deviceManager = new VictorUsbDeviceManager(this);
}
} |
Scanning for Devices
Once a VictorBleDeviceManager DeviceManager has been instantiated, a scan must be performed to identify any active VictoR devices accepting connections over bluetoothBLE or USB (dependent on the device manager instantiated). By default, scanning for devices is set to take 10 seconds, with a query for any devices with the term “victor” in its name, with case sensitivity not taken into account. Once the scan has completed, a Set of VictorDeviceInfo objects is returned, which each contain the name and address of a VictoR device. The following illustrates the work flow for a BLE device manager, but the same workflow exists for the USB device manager in all cases save for when specifying scan parameters, explained in the next section.
Code Block | ||
---|---|---|
| ||
import com.fn.victorcore.VictorDeviceInfo; import com.fn.victorcommunications.VictorBleDeviceManager; public class MainActivity extends Activity { VictorBleDeviceManager deviceManager; @Override public void onCreate(Bundle savedInstanceState) { deviceManager = new VictorBleDeviceManager(this); } public void Scan() { CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(); } } |
...
Users have a means to also specify VictorDeviceScanParameters when scanning for VictoR devices. Options include specifying the scan time, the string query for victor device names, and whether the case of the device name is important. It is important to note that the VictorDeviceScanParameters are not used when scanning for USB devices, as this uses an entirely different set of filters to find any connected devices over USB.
Code Block | ||
---|---|---|
| ||
import com.fn.victorcore.VictorDeviceInfo; import com.fn.victorcore.VictorDeviceScanParameters; import com.fn.victorcommunications.VictorBleDeviceManager; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { deviceManager = new VictorBleDeviceManager(this); } public void Scan() { deviceManager = new VictorBleDeviceManager(this); VictorDeviceScanParameters scanParameters = new VictorDeviceScanParameters(); scanParameters.setScanTime(3000L); CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(scanParameters); } } |
...
Once a powered on VictoR device has been found by scanning for devices with the VictorBleDeviceManagerDeviceManager, the resulting VictorDeviceInfo can be used to connect to the device along with the VictorBleDeviceManager DeviceManager that found the device.
Code Block | ||
---|---|---|
| ||
CompletableFuture<Boolean> futureConnected = deviceManager.connect(deviceInfo.getAddress()); |
...
Code Block | ||
---|---|---|
| ||
private final DeviceInformationService.DeviceInformationCallback deviceInformationCallback = new DeviceInformationService.DeviceInformationCallback() { public void onCurrentBatteryLevelChanged(VictorDeviceInfo deviceInfo, short currentBatteryLevel) { debugTextView.post(() -> debugTextView.append("Current Battery Level: " + currentBatteryLevel + "\n")); } }; deviceInfoService.subscribeToCurrentBatteryLevel(deviceInfo.getAddress(), deviceInformationCallback); |
NOTE: When subscribing to an attribute, please reference the supported ICD document specified above to ensure that subscribing to the attribute itself supported.