Viam SDK
    Preparing search index...

    Class BoardClient

    A gRPC-web client for the Board component.

    Implements

    Index

    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' } }));
    • Return the current value of the interrupt which is based on the type of interrupt.

      Parameters

      • digitalInterruptName: string

        The name of the digital interrupt.

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

      Returns Promise<number>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the number of times this DigitalInterrupt has been interrupted with a tick.
      const count = await board.getDigitalInterruptValue('my_example_digital_interrupt');

      For more information, see Board API.

    • Get the high/low state of the given pin.

      Parameters

      • pin: string

        The pin number.

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

      Returns Promise<boolean>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get if it is true or false that the state of the pin is high.
      const high = await board.getGPIO('15');

      For more information, see Board API.

    • Get the duty cycle of the given pin of a board.

      Parameters

      • pin: string

        The pin number.

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

      Returns Promise<number>

      The duty cycle, which is a value from 0 to 1.

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the duty cycle of this pin.
      const dutyCycle = await board.getPWM('15');

      For more information, see Board API.

    • Get the PWM frequency of the given pin of a board.

      Parameters

      • pin: string

        The pin.

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

      Returns Promise<number>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the PWM frequency of this pin.
      const freq = await board.getPWMFrequency('15');

      For more information, see Board API.

    • Get the status of the resource.

      Parameters

      • callOptions: CallOptions = ...

      Returns Promise<JsonValue>

    • Read the current value of an analog reader of a board.

      Parameters

      • analogReader: string

        The name of the analog reader.

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

      Returns Promise<ReadAnalogReaderResponse>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the value of the analog signal "my_example_analog_reader" has most
      // recently measured.
      const reading = await board.readAnalogReader('my_example_analog_reader');

      For more information, see Board API.

    • Set the high/low state of the given pin of a board.

      Parameters

      • pin: string

        The pin number.

      • high: boolean

        When true, set the given pin to high. When false, set the given pin to low.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the pin to high.
      await board.setGPIO('15', true);

      For more information, see Board API.

    • Set power mode of the board.

      Parameters

      • powerMode: boardApi.PowerMode

        The requested power mode.

      • Optionalduration: Duration

        The requested duration to stay in power mode.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the power mode of the board to OFFLINE_DEEP.
      const duration = new VIAM.Duration({ seconds: 10n });
      await board.setPowerMode(VIAM.PowerMode.OFFLINE_DEEP, duration);

      For more information, see Board API.

    • Set the duty cycle of the given pin of a board.

      Parameters

      • pin: string

        The pin.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the duty cycle to 0.6, meaning that this pin will be in the high state for
      // 60% of the duration of the PWM interval period.
      await board.setPWM('15', 0.6);

      For more information, see Board API.

    • Set the PWM frequency of the given pin of a board.

      Parameters

      • pin: string

        The pin.

      • frequencyHz: number

        The PWM frequency, in hertz. 0 will use the board's default PWM frequency.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the PWM frequency of this pin to 1600 Hz.
      await board.setPWMFrequency('15', 1600);

      For more information, see Board API.

    • Stream digital interrupt ticks on the board.

      Parameters

      • interrupts: string[]

        Names of the interrupts to stream.

      • queue: Tick[]

        Array to put the ticks in.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Stream ticks from pins 8 and 11.
      const ticks = await board.streamTicks(['8', '11']);

      for await (const tick of ticks) {
      console.log(
      `Pin ${tick.pinName} changed to ${tick.high ? 'high' : 'low'} at ${tick.time}`,
      );
      }

      For more information, see Board API.

    • Write an analog value to a pin on the board.

      Parameters

      • pin: string

        The pin name.

      • value: number

        An integer value to write.

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

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Write the value 42 to "my_example_analog_writer".
      await board.writeAnalog('my_example_analog_writer', 42);

      For more information, see Board API.