Interface Switch

Represents a physical switch with multiple positions.

interface Switch {
    getNumberOfPositions: (extra?: Struct) => Promise<[number, string[]]>;
    getPosition: (extra?: Struct) => Promise<number>;
    name: string;
    setPosition: (position: number, extra?: Struct) => Promise<void>;
    doCommand(command: Struct): Promise<JsonValue>;
}

Hierarchy (View Summary)

Implemented by

Properties

getNumberOfPositions: (extra?: Struct) => Promise<[number, string[]]>

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.

getPosition: (extra?: Struct) => Promise<number>

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.

name: string

The name of the resource.

setPosition: (position: number, extra?: Struct) => Promise<void>

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.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct

      The command to execute.

    Returns Promise<JsonValue>

    import { Struct } from '@viamrobotics/sdk';

    const result = await resource.doCommand(
    Struct.fromJson({
    myCommand: { key: 'value' },
    })
    );