pamoja for TypeScript - v0.2.0
    Preparing search index...

    A Modbus RTU client on a serial line: the gateway, the master in the specification's words, that sends each request and waits for its reply.

    Each transaction follows the Modbus over Serial Line specification. The client leaves the line silent for 3.5 characters, or 1.75 ms above 19200 baud; drops anything stale waiting in the port; writes the request; and reads the reply to the length the request implies, against the response timeout. The reply's CRC, unit, and function are checked before a value is read out of it, and any failure rejects with a ModbusClientError. A write to BROADCAST reaches every device and draws no reply, so the client waits out the turnaround delay instead. Each call runs on a worker thread.

    const port = SerialPort.open('/dev/ttyUSB0', { baud: 19200, parity: Parity.Even })
    const client = new ModbusClient(port)
    const [volts, amps] = await client.readHoldingRegisters(17, 107, 2)
    Index
    • get responseTimeoutMs(): number

      How long the client waits for a whole reply, in milliseconds.

      Returns number

    • set responseTimeoutMs(ms: number): void

      Parameters

      • ms: number

      Returns void

    • get turnaroundMs(): number

      How long the client leaves the line quiet after a broadcast, in milliseconds.

      Returns number

    • set turnaroundMs(ms: number): void

      Parameters

      • ms: number

      Returns void

    • Reads coils, function 0x01.

      Parameters

      • unit: number

        The device, 1 to 247.

      • start: number

        The first coil's address.

      • quantity: number

        How many, 1 to 2000.

      Returns Promise<boolean[]>

      The coils' states, in address order.

      ModbusClientError When the transaction fails.

    • Reads discrete inputs, function 0x02.

      Parameters

      • unit: number

        The device, 1 to 247.

      • start: number

        The first input's address.

      • quantity: number

        How many, 1 to 2000.

      Returns Promise<boolean[]>

      The inputs' states, in address order.

      ModbusClientError When the transaction fails.

    • Reads holding registers, function 0x03.

      Parameters

      • unit: number

        The device, 1 to 247.

      • start: number

        The first register's address.

      • quantity: number

        How many, 1 to 125.

      Returns Promise<number[]>

      The registers' values, in address order.

      ModbusClientError When the transaction fails.

    • Reads input registers, function 0x04.

      Parameters

      • unit: number

        The device, 1 to 247.

      • start: number

        The first register's address.

      • quantity: number

        How many, 1 to 125.

      Returns Promise<number[]>

      The registers' values, in address order.

      ModbusClientError When the transaction fails.

    • Writes a run of coils, function 0x0F.

      Parameters

      • unit: number

        The device, 1 to 247, or BROADCAST for every device.

      • start: number

        The first coil's address.

      • values: readonly boolean[]

        The states to write, 1 to 1968 of them, in address order.

      Returns Promise<void>

      ModbusClientError When the transaction fails.

    • Writes a run of holding registers, function 0x10.

      Parameters

      • unit: number

        The device, 1 to 247, or BROADCAST for every device.

      • start: number

        The first register's address.

      • values: readonly number[]

        The values to write, 1 to 123 of them, in address order.

      Returns Promise<void>

      ModbusClientError When the transaction fails.

    • Writes one coil, function 0x05.

      Parameters

      • unit: number

        The device, 1 to 247, or BROADCAST for every device.

      • address: number

        The coil's address.

      • on: boolean

        The state to write.

      Returns Promise<void>

      ModbusClientError When the transaction fails.

    • Writes one holding register, function 0x06.

      Parameters

      • unit: number

        The device, 1 to 247, or BROADCAST for every device.

      • address: number

        The register's address.

      • value: number

        The value to write.

      Returns Promise<void>

      ModbusClientError When the transaction fails.

    • The silence that separates two frames: 3.5 characters at the line's speed and format, and a fixed 1750 microseconds above 19200 baud.

      Parameters

      Returns number

      The silence, in nanoseconds, rounded up.