Skip to content

Commit b7893f1

Browse files
committed
docs: add full client example to readme
1 parent baf87ee commit b7893f1

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

packages/binding-modbus/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@ W3C WoT Binding Template for Modbus can be found [here](https://w3c.github.io/wo
88

99
Current Maintainer(s): [@relu91](https://github.com/relu91) [@fillobotto](https://github.com/fillobotto)
1010

11+
## Client Example
12+
13+
You can use a code like the following to use the binding. This specific code is interacting with one of the Eclipse Thingweb Test Things at <https://github.com/eclipse-thingweb/test-things/tree/main/things/elevator>.
14+
15+
```js
16+
// Protocols and Servient
17+
Servient = require("@node-wot/core").Servient;
18+
ModbusClientFactory = require("@node-wot/binding-modbus").ModbusClientFactory;
19+
20+
// create Servient and add Modbus binding
21+
let servient = new Servient();
22+
servient.addClientFactory(new ModbusClientFactory());
23+
24+
async function main() {
25+
let td = {} // see https://github.com/eclipse-thingweb/test-things/blob/main/things/elevator/modbus/js/modbus-elevator.td.json
26+
27+
const WoT = await servient.start();
28+
const thing = await WoT.consume(td);
29+
30+
const readData1 = await thing.readProperty("lightSwitch"); // coil
31+
const readData2 = await thing.readProperty("floorNumber"); // register
32+
33+
const readValue1 = await readData1.value();
34+
console.log(readValue1);
35+
36+
const readValue2 = await readData2.value();
37+
console.log(readValue2);
38+
}
39+
40+
main();
41+
```
42+
1143
## Binding Information
1244

1345
### Protocol specifier

0 commit comments

Comments
 (0)