MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / testUART

Function testUART

examples/io/ble/client/uart/main.js:31–71  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

29scan();
30
31function testUART(address) {
32 new GATTClient({
33 address,
34 onError(error) {
35 trace(`onError: ${ error }\n`);
36 scan();
37 },
38 onReadable(count) {
39 while (count--) {
40 const value = this.read();
41 if (!value || (value.handle !== this.input.handle))
42 continue;
43 const bytes = new Uint8Array(value);
44 trace(`UART: ${bytes.toHex()}\n`);
45 }
46 },
47 onReady() {
48 trace(`onReady: maximumWrite ${ this.maximumWrite }\n`);
49 this.getPrimaryServices([ "6e400001-b5a3-f393-e0a9-e50e24dcca9e"], (error, services) => {
50 this.getCharacteristics(services[0], ["6e400002-b5a3-f393-e0a9-e50e24dcca9e", "6e400003-b5a3-f393-e0a9-e50e24dcca9e"], (error, characteristics) => {
51 characteristics.forEach(characteristic => {
52 trace(`characteristic: ${ characteristic.uuid } ${ characteristic.handle }\n`);
53 if (characteristic.properties & GATTClient.properties.read)
54 this.input = characteristic;
55 if (characteristic.properties & GATTClient.properties.write)
56 this.output = characteristic;
57 });
58 this.subscribe(this.input, error => {
59 trace(`notification: ${ this.input.uuid } ${ error ? "error " + error : "enabled"}\n`);
60 });
61 this.write(this.output, Uint8Array.of(0, 1, 2, 3), error => {
62 trace(`write 1: ${ error ?? "no error" }\n`);
63 });
64 this.write(this.output, ArrayBuffer.fromString("Hello, BLE."), error => {
65 trace(`write 2: ${ error ?? "no error" }\n`);
66 });
67 });
68 });
69 },
70 });
71}

Callers 1

onReadableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected