Class SwitchClient

A gRPC-web client for the Switch component.

Implements

Constructors

Properties

callOptions: CallOptions = ...
name: string

The name of the resource.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct | Record<string, JsonValue>

      The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.

    • callOptions: CallOptions = ...

    Returns Promise<JsonValue>

    // Plain object (recommended)
    const result = await resource.doCommand({
    myCommand: { key: 'value' },
    });

    // Struct (still supported)
    import { Struct } from '@viamrobotics/sdk';

    const result = await resource.doCommand(
    Struct.fromJson({ myCommand: { key: 'value' } })
    );
  • 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.

    Parameters

    • extra: {} = {}
    • callOptions: CallOptions = ...

    Returns Promise<[number, string[]]>

    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.

    Parameters

    • extra: {} = {}
    • callOptions: CallOptions = ...

    Returns Promise<number>

    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.

  • Set the switch to a specific position.

    Parameters

    • position: number
    • extra: {} = {}
    • callOptions: CallOptions = ...

    Returns Promise<void>

    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.