The M410 Modbus to Serial adapter is based on the uModbus python implementation of the Modbus protocol as described in the MODBUS Application Protocol Specification V1.1b3 along with the MAX485 processor and IC as described in the RS-485/RS-422 Circuit Implementation guide at Analog Devices.
uModbus and the M410 Modbus to Serial adapter implement a Modbus client (RTU) and a Modbus server (RTU). The same firmware can be used to implement TCP variations of both client and server.
The following functions have been implemented for Modbus RTU
- 01: Read Coils
- 02: Read Discrete Inputs
- 03: Read Holding Registers
- 04: Read Input Registers
- 05: Write Single Coil
- 06: Write Single Register
- 15: Write Multiple Coils
- 16: Write Multiple Registers
Includes support for signed and unsigned register values.
A full working copy of channel firmware and libraries for use in all AlphaX devices can be found at M innovations GitHub.
A copy of original libraries and examples are available from AdvancedClimateSystems GitHub. Full documentation provided here.
Doing a Simple Modbus request (For reading Seametrics LevelSCOUT):
from uModBus.serial import Serial # from uModBus.tcp import TCP ## Not required import machine, utime, ustruct def getData(P1,P2): uart_id = 0x01 modbus_obj = Serial(uart_id, pins=(P1,P2)) slave_addr=2 starting_address=62594 register_quantity=1 signed=True result='' for y in range(0,2): ## Repeat Read, first read wakes up Levelscout, seconds reads register try: register_value = modbus_obj.read_holding_registers(slave_addr, starting_address, register_quantity, signed) #print(register_value) #print(bytes(register_value[1])) result = ustruct.unpack('>f', register_value) #print(result[0]) #print(result[1]-14.7) except Exception as e: print('Waking up Slave') utime.sleep_ms(1000) try: return(result[0]) except: return 0 print(getData('P10','P9'))
uModbus software is licensed under Mozilla Public License.