A Non Blocking Modbus Master Library

This library is available via the Arduino library manager as NonBlockingModbusMaster

A detailed tutorial is at Non Blocking Modbus Master Library works with any Stream object

Why this library?
Version 2 of the Solar Hot Water Battery, uses two modbus devices to measure the 3 phase power and hot water kWhrs. It takes six (6) modbus commands to collect the complete system state. These six commands take between a half to three quarters of a second (0.5s to 0.75s) to complete, assuming there are not timeouts. This library allows those six commands to be executed as a single block while still letting the loop() continue run at high speed to handle push button inputs and Serial commands. If one of the block's commands times out, this library also allows that command to be retried before continuing with the other commands.

The NonBlockingModbusMaster library has the following features:-

– With suitably sized serial TX and RX buffers, it is completely non-blocking.
– No callback methods are necessary for single command non-blocking use.
– Uses RTU modbus and works with any Arduino Stream object
– Supports multiple device IDs.
– Has a simple command chaining facility to group commands together in a single executable non-blocking block.
– Has a retry() method for use when the command times out (or other some other error occurs)
– Has oneTimeDelay() method to insert an extra pre-command delay. e.g. when switching between device ID's
– Supports optional results processing functions that are called when the command completes.
– Runs on UNO with software serial while maintaining responsive Serial and other loop() processing.

The tutorial uses an UNO and Paul Stoffregen's AltSoftSerial library. For an ESP32 example using Serial1, see the Solar Hot Water Battery Ver 2 project (under construction). To access Modbus devices with this library an RS232 to RS485 converter is necessary.

This library is a modification of the Doc Walker's ModbusMaster library.
Disclaimer: The readHoldingRegisters method is the only modbus command that has been extensively tested, due to lack if other modbus hardware. All other commands are expected to work as their code has been inherited from the original ModbusMaster library. Code corrections and/or test results welcome.

Is it available on Github?

Searching the Arduino Library Manager for "non blocking modbus" will bring up this library for installation.
The More Info link will take you to the Github page

A zip file of the library is also available under
Parts List -- Software
on
https://www.forward.com.au/pfod/ArduinoProgramming/NonBlockingModbusMaster/index.html

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.