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

Control N4DAC02 2-channel 0..5V / 0..10V analog output modules (DAC) 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)
 
def set_voltage (self, int output_no, float voltage)
 Set setpoint for the analog output voltage. More...
 
float get_cal_factor (self, int output_no)
 Get currently set hardware calibration / correction factor for output. More...
 
def set_cal_factor (self, int output_no, float cal_factor=1.000)
 Set analog calibration / correction factor for specified output. 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 OUTPUT_REG_OFFSET = 40000
 
int OUTPUT_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 N4DAC02 2-channel 0..5V / 0..10V analog output modules (DAC) via RS-485 Modbus RTU.

The N4DAC02 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.N4DAC02.get_cal_factor (   self,
int  output_no 
)

Get currently set hardware calibration / correction factor for output.

   A factor of 1.000 means no correction.
Parameters
output_noOutput number, can be 1 or 2.
Returns
Hardware calibration factor for output

◆ 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.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.N4DAC02.set_cal_factor (   self,
int  output_no,
float   cal_factor = 1.000 
)

Set analog calibration / correction factor for specified output.

   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
output_noOutput number, can be 1 or 2.
cal_factorCalibration value. Valid range is 0.0 ... 32.767

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

◆ set_voltage()

def cheap_modbus_rtu.cheap_modbus_io.N4DAC02.set_voltage (   self,
int  output_no,
float  voltage 
)

Set setpoint for the analog output voltage.

   Output no. 1 is 0..5 V,
   Output no. 2 is 0..10 V
Parameters
output_noOutput number, can be 1 or 2.
voltageSetpoint for output voltage in volts.

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