Get the total number of positions available on the switch, along with their labels. Labels should either be null, undefined, empty, or the same length has the number of positions.
const mySwitch = new VIAM.SwitchClient(machine, 'my_switch');
// Get the number of available positions
const numPositions = await mySwitch.getNumberOfPositions();
console.log('Number of positions:', numPositions);
For more information, see Switch API.
Get the current position of the switch.
const mySwitch = new VIAM.SwitchClient(machine, 'my_switch');
// Update the switch to position 1
await mySwitch.setPosition(1);
// Get the current set position
const pos1 = await mySwitch.getPosition();
// Update the switch to position 0
await mySwitch.setPosition(0);
// Get the current set position
const pos2 = await mySwitch.getPosition();
For more information, see Switch API.
ReadonlynameThe name of the resource.
Set the switch to a specific position.
const mySwitch = new VIAM.SwitchClient(machine, 'my_switch');
// Update the switch from its current position to position 1
await mySwitch.setPosition(1);
// Update the switch from its current position to position 0
await mySwitch.setPosition(0);
For more information, see Switch API.
Represents a physical switch with multiple positions.