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

Control affordable Modbus relay PCBs via RS-485 Modbus RTU. More...

Public Member Functions

def __init__ (self, int slave_id=255, str serial_device_name=None, int baudrate=9600, **kwargs)
 
def set_output (self, int output_no, bool active=True)
 Set specified output. More...
 
def clear_output (self, int output_no)
 Disable specified output. More...
 
bool get_input (self, int input_no)
 Return the state of the specified digital input. More...
 
tuple[bool,...] get_inputs (self)
 Returns the state of the digital inputs. 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)
 Factory reset not implemented for the relay modules.
 
int get_slave_id (self)
 Sends a broadcast query to all devices on the bus. More...
 

Public Attributes

 slave_id
 
 master
 

Static Public Attributes

int DI_REGISTER = 10001
 
int SLAVE_ID_REGISTER = 40001
 
int BAUDRATE_REGISTER = 41002
 
int BROADCAST_SLAVE_ID = 0
 
dictionary BAUDRATE_KEYS = {1200: 0, 2400: 1, 4800: 2, 9600: 3, 19200: 4}
 

Detailed Description

Control affordable Modbus relay PCBs via RS-485 Modbus RTU.

These come in one, two, four, eight or more channel variants and feature different numbers of additional digital IO pins.

While the relay outputs are insulated for mains voltage application, the digital IO pins are only featuring functional or low-voltage isolation, some variants do not have isolated inputs at all.

The detailed implementation varies slightly between variants, the difference (for the time being) is the number of input state values contained in the tuple returned from the "get_inputs()" method.

All other methods are identical.

==> Please see documentation of the derived classes for details:

Brand name is "bestep" among others.

Member Function Documentation

◆ clear_output()

def cheap_modbus_rtu.cheap_modbus_io.RelayModule.clear_output (   self,
int  output_no 
)

Disable specified output.

Parameters
output_noOutput number, starts counting at 1

◆ get_input()

bool cheap_modbus_rtu.cheap_modbus_io.RelayModule.get_input (   self,
int  input_no 
)

Return the state of the specified digital input.

Parameters
input_noInput number, starts counting at 1
Returns
True if input signal is active, False if inactive

◆ get_inputs()

tuple[bool, ...] cheap_modbus_rtu.cheap_modbus_io.RelayModule.get_inputs (   self)

Returns the state of the digital inputs.

Returns
Tuple of boolean flags, one for each input

◆ get_slave_id()

int cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.get_slave_id (   self)
inherited

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.RelayModule.set_baudrate (   self,
int   baudrate = 9600 
)

Set RS485 serial baud rate.

Warning
While undocumented, it is possible that the device writes directly to FLASH, thus frequent writes could damage the chip!
Parameters
FIXME1200 and 2400 are undocumented. Really possible?
baudrateCan be 1200, 2400, 4800, 9600 (default) or 19200

Reimplemented from cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.

◆ set_output()

def cheap_modbus_rtu.cheap_modbus_io.RelayModule.set_output (   self,
int  output_no,
bool   active = True 
)

Set specified output.

Parameters
output_noOutput number, starts counting at 1
activeEnable output if active == True (default) Disable output if active == False

◆ set_slave_id()

def cheap_modbus_rtu.cheap_modbus_io.RelayModule.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 from cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.


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