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.N4AIA04 Class Reference

Control N4AIA04 4-channel 0..5V / 0..10V / 0..20mA analog input modules (ADC) via RS-485 Modbus RTU. More...

Public Member Functions

def __init__ (self, int slave_id=1, str serial_device_name=None, int baudrate=9600, **kwargs)
 
float get_voltage (self, int input_no)
 Read and return the value of the specified analog input voltage. More...
 
float get_current (self, int input_no)
 Read and return the value of the specified analog input current. More...
 
float get_cal_factor (self, int input_no)
 Get currently set hardware calibration / correction factor for input. More...
 
def set_cal_factor (self, int input_no, float cal_factor=1.000)
 Set analog calibration / correction factor for specified input. More...
 
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
 

Static Public Attributes

int INPUT_REG_OFFSET = 40000
 
int INPUT_CAL_REG_OFFSET = 40007
 
int SLAVE_ID_REGISTER = 40015
 
int BAUDRATE_REGISTER = 40016
 
int FACTORY_RESET_REGISTER = 40016
 
int FACTORY_RESET_VALUE = 5
 
int BROADCAST_SLAVE_ID = 0xFF
 
dictionary BAUDRATE_KEYS = {1200: 0, 2400: 1, 4800: 2, 9600: 3, 19200: 4}
 

Detailed Description

Control N4AIA04 4-channel 0..5V / 0..10V / 0..20mA analog input modules (ADC) via RS-485 Modbus RTU.

The N4AIA04 seem to come with a pre-set slave ID of 1.

Brand name is "eletechsup", available at https://www.eletechsup.com

Member Function Documentation

◆ do_factory_reset()

def cheap_modbus_rtu.cheap_modbus_io.ModbusModuleABC.do_factory_reset (   self)
inherited

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

float cheap_modbus_rtu.cheap_modbus_io.N4AIA04.get_cal_factor (   self,
int  input_no 
)

Get currently set hardware calibration / correction factor for input.

   A factor of 1.000 means no correction.
Parameters
input_noInput number, valid range is 1...4
Returns
Hardware calibration factor for input

◆ get_current()

float cheap_modbus_rtu.cheap_modbus_io.N4AIA04.get_current (   self,
int  input_no 
)

Read and return the value of the specified analog input current.

   Input numbers are 3 and 4 and these are both 0..20 mA inputs.
Parameters
input_noInput number, can be 3 or 4.
Returns
Analog input current read-out value in mA

◆ 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.

◆ get_voltage()

float cheap_modbus_rtu.cheap_modbus_io.N4AIA04.get_voltage (   self,
int  input_no 
)

Read and return the value of the specified analog input voltage.

   Input no. 1 is 0..5 V,
   Input no. 2 is 0..10 V
Parameters
input_noInput number, can be 1 or 2.
Returns
Analog input voltage read-out value in volts

◆ set_baudrate()

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

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

def cheap_modbus_rtu.cheap_modbus_io.N4AIA04.set_cal_factor (   self,
int  input_no,
float   cal_factor = 1.000 
)

Set analog calibration / correction factor for specified input.

   A factor of 1.000 means no correction.

   This does not factor in any previously set value.
   The currently set value can be queried using get_cal_factor().
Warning
While undocumented, it is possible that the device writes directly to FLASH, thus frequent writes could damage the chip!
Parameters
input_noInput number, valid range is 1...4
cal_factorCalibration value. Valid range is 0.0 ... 65.535

◆ set_slave_id()

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

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: