-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
25 lines (21 loc) · 1.07 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { SiPortReader, SiReadout, listSiPorts, SiPortId, SiPortDetectedMode } from './opensportident';
listSiPorts((err, ports) => {
if (err) {
console.error(err);
}
else {
if (!ports.length) {
console.error('No SPORTident device found');
}
ports.forEach((portId: SiPortId) => {
console.log(`Opening ${portId.comName} => ${portId.serialNumber}...`);
const siPort = new SiPortReader(portId.comName, {mute: false, debug: false});
siPort.on('open', (mode: SiPortDetectedMode) => console.log(`Connected to ${portId.comName} ${JSON.stringify(mode)})`));
siPort.on('close', () => console.log(`Closed ${portId.comName} => ${portId.serialNumber}`));
siPort.on('error', err => console.error(`Error on ${portId.comName}: ${err}`));
siPort.on('warning', warn => console.error(`Warning on ${portId.comName}: ${warn}`));
siPort.on('readout', (readout: SiReadout) => console.log(readout.toDebugString()));
siPort.open();
});
}
});