Clients
In DeviceScript, hardware peripherals (and generally anything outside the VM) are modelled as Jacdac services.
The peripherals are servers and your client application creates clients to interact with them.
Declaring roles
Client instances, roles, should be allocated at the top level of your program. The variable name is automatically assigned as the role name.
import { Temperature } from "@devicescript/core"
const thermometer = new Temperature()
Role binding state
You can test if the service is bound to a server.
import { Temperature } from "@devicescript/core"
const thermometer = new Temperature()
setInterval(async () => {
if (await thermometer.binding().read()) {
console.log("connected!")
}
}, 1000)