cheap_modbus_rtu
Lightweight control of cheap Modbus RTU components using Python
Public Member Functions | Public Attributes | List of all members
cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC Class Reference

Base class for cheap Modbus IO modules. More...

Public Member Functions

def __init__ (self, int slave_id, str serial_device_name, int baudrate, **kwargs)
 
int get_slave_id (self)
 Sends a broadcast query to all devices on the bus. More...
 
def set_slave_id (self, int slave_id_new)
 Set the slave ID. More...
 
def set_baudrate (self, int baudrate=9600)
 Set RS485 serial baud rate. More...
 
def do_factory_reset (self)
 Restore factory default settings. More...
 

Public Attributes

 master
 
 slave_id
 

Detailed Description

Base class for cheap Modbus IO modules.

Configuration constants like register values are device-specific and implemented in the derived classes.

Member Function Documentation

◆ do_factory_reset()

def cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.do_factory_reset (   self)

Restore factory default settings.

   You must cycle the power supply after this command.

   Expect a CRC mismatch error when invoking this function,
   I don't know if this is always the case.

Reimplemented in cheap_modbus_rtu.cheap_modbus_io.RelayModule.

◆ get_slave_id()

int cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.get_slave_id (   self)

Sends a broadcast query to all devices on the bus.

   This only works when only one device is attached to the bus
Returns
The first found slave ID.

◆ set_baudrate()

def cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.set_baudrate (   self,
int   baudrate = 9600 
)

Set RS485 serial baud rate.

   Most devices require cycling the power supply after running this command
   before the new baud rate applies.
Warning
While usually undocumented, it is possible that the device writes directly to FLASH, thus frequent writes could damage the chip!
Parameters
baudrateCan be 1200, 2400, 4800, 9600 (default) or 19200

Reimplemented in cheap_modbus_rtu.cheap_modbus_io.RelayModule.

◆ set_slave_id()

def cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.set_slave_id (   self,
int  slave_id_new 
)

Set the slave ID.

Warning
While usually undocumented, it is possible that the device writes directly to FLASH, thus frequent writes could damage the chip!
Parameters
slave_id_newNew Modbus slave ID

Reimplemented in cheap_modbus_rtu.cheap_modbus_io.RelayModule.


The documentation for this class was generated from the following file: