ant-plus-next / GarminStick3
Class representing a Garmin Stick 3 USB driver, which extends the base USBDriver class.
NodeUSBDriver
new GarminStick3(
debugOptions
?):GarminStick3
Creates an instance of GarminStick3.
DebugOptions
= {}
Optional debug options for USB operations.
const garminStick = new GarminStick3({ usbDebugLevel: 1 });
garminStick.open(); // Opens the connection to the Garmin Stick 3 device.
NodeUSBDriver.constructor
_canScan:
boolean
=false
Indicates if the device can scan for channels. Represents whether the USB device has scanning capabilities.
NodeUSBDriver._canScan
core/driver/nodeUSBDriver.ts:113
maxChannels:
number
=0
The maximum number of channels available for communication. Defines the total number of channels the device can handle.
NodeUSBDriver.maxChannels
core/driver/nodeUSBDriver.ts:105
throwLibUSBException:
boolean
=false
Defines whether to throw LibUSB exceptions when errors occur during USB communication.
Default value is set to false
.
NodeUSBDriver.throwLibUSBException
core/driver/nodeUSBDriver.ts:121
usedChannels:
number
=0
The number of channels currently used. Tracks how many channels are actively being used.
NodeUSBDriver.usedChannels
core/driver/nodeUSBDriver.ts:88
attach(
sensor
,forScan
):Promise
<boolean
>
Attaches a sensor to the driver and assigns it a channel.
The sensor to attach.
boolean
Whether the sensor is being attached for scanning.
Promise
<boolean
>
Resolves with true if the sensor was successfully attached, otherwise false.
const sensor = new BaseSensor();
driver.attach(sensor, true).then((attached) => {
if (attached) console.log("Sensor attached");
});
NodeUSBDriver.attach
core/driver/nodeUSBDriver.ts:394
canAttach():
Promise
<boolean
>
Checks if a new sensor can be attached to the driver. It verifies whether the current number of used channels is less than the maximum available channels.
Promise
<boolean
>
Resolves with true if a new sensor can be attached, otherwise false.
const canAttach = await this.stick.canAttach();
if (canAttach) {
console.log("A new sensor can be attached.");
} else {
console.log("Cannot attach sensor: Maximum number of channels reached.");
}
NodeUSBDriver.canAttach
core/driver/nodeUSBDriver.ts:160
canScan():
Promise
<boolean
>
Checks if the device can scan for channels.
Promise
<boolean
>
Resolves with true if the device can scan, otherwise false.
NodeUSBDriver.canScan
core/driver/nodeUSBDriver.ts:169
close():
Promise
<void
>
Closes the connection to the USB device and releases the interface.
Promise
<void
>
Resolves when the device is closed.
const driver = new NodeUSBDriver(1234, 5678);
driver.open().then(() => {
driver.close().then(() => console.log("Device closed"));
});
NodeUSBDriver.close
core/driver/nodeUSBDriver.ts:282
detach(
sensor
):Promise
<boolean
>
Detaches a sensor from the driver.
The sensor to detach.
Promise
<boolean
>
Resolves with true if the sensor was successfully detached, otherwise false.
const sensor = new BaseSensor();
driver.detach(sensor).then((detached) => {
if (detached) console.log("Sensor detached");
});
NodeUSBDriver.detach
core/driver/nodeUSBDriver.ts:424
isPresent():
Promise
<boolean
>
Checks if a USB device is present.
Promise
<boolean
>
Resolves with true if a device is present, otherwise false.
NodeUSBDriver.isPresent
core/driver/nodeUSBDriver.ts:441
isScanning():
Promise
<boolean
>
Checks if the driver is currently scanning.
Promise
<boolean
>
Resolves with true if the driver is scanning, otherwise false.
NodeUSBDriver.isScanning
core/driver/nodeUSBDriver.ts:450
open():
Promise
<boolean
>
Opens a connection to the USB device and sets up endpoints for communication.
Promise
<boolean
>
Resolves with true if the device is successfully opened, otherwise false.
const driver = new NodeUSBDriver(1234, 5678);
driver.open().then((result) => {
if (result) {
console.log("Device successfully opened");
} else {
console.error("Failed to open device");
}
});
NodeUSBDriver.open
core/driver/nodeUSBDriver.ts:187
read(
data
):Promise
<void
>
Reads data from the USB device and processes it.
Uint8Array
<ArrayBufferLike
>
The data received from the USB device.
Promise
<void
>
Resolves when the data has been processed.
const data = new Uint8Array([0x01, 0x02, 0x03]);
driver.read(data).then(() => console.log("Data processed"));
NodeUSBDriver.read
core/driver/nodeUSBDriver.ts:327
reset():
Promise
<void
>
Resets the device and its channels, and sends a reset message to the system.
Promise
<void
>
Resolves when the reset is completed.
driver.reset().then(() => console.log("Device reset"));
NodeUSBDriver.reset
core/driver/nodeUSBDriver.ts:375
write(
data
):Promise
<void
>
Writes data to the USB device.
Uint8Array
<ArrayBufferLike
>
The data to be sent to the USB device.
Promise
<void
>
Resolves when the data has been written.
const data = new Uint8Array([0x01, 0x02, 0x03]);
driver.write(data).then(() => console.log("Data sent"));
NodeUSBDriver.write