Skip to content
Cloud-Automation edited this page Oct 3, 2014 · 5 revisions

Modbus Loop API

Setup a Modbus Loop

loop = new ModbusLoop(client);
  • client A ModbusClient Instance.

top

Register Function Calls

Read Holding Registers (FC 03)

loop.readHoldingRegisters(start, count)
  • start Start Address for the Holding Registers to be read.
  • count Number of Registers to be read.
  • Returns the loop object.

top

Read Input Registers (FC 04)

loop.readInputRegisters(start, count)
  • start Start Address for the Input Registers to be read.
  • count Number of Registers to be read.
  • Returns the loop object.

top

Start the loop

loop.start()

top

Stop the loop

loop.stop()

top

Events

loop.on('update', function (inputRegisters, holdingRegisters) { ... });

When every request for the input and holding registers has finished the update event will be fired. You can get your desired data from the inputRegisters and holdingRegisters Parameter.

loop.on('error', function (err) { ... });

Normally fired when there is an unexpected error on the Modbus Client. The loop will be stopped.

top

Optimization

The Modbus Loop will automatically optimize your requests. So when you register

loop.readInputRegisters(0, 10)

and

loop.readInputRegisters(10, 10)

the request that is actually been send through the client is

client.readInputRegisters(0, 20)

top