Knowledge Base:Home»Hardware»M-Sense M410 Modbus to Serial Adapter»M410 Modbus to Serial Adapter Firmware Notes

M410 Modbus to Serial Adapter Firmware Notes

Last Updated: July 27th, 2020
In this article

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))


    for y in range(0,2):  ## Repeat Read, first read wakes up Levelscout, seconds reads register
            register_value = modbus_obj.read_holding_registers(slave_addr, starting_address, register_quantity, signed)
            result = ustruct.unpack('>f', register_value)
        except Exception as e:
            print('Waking up Slave')

        return 0


uModbus software is licensed under Mozilla Public License.