dcs_cn0435_utilities (version 0.1)
index
c:\users\msuciu\documents\github\dcs\for wiki\read or write registers\dcs_cn0435_utilities.py

Base MODBUS functions.
 
This module provide base functionalities to easy interact with:
CN0414 - Analog input and HART for PLC/DCS systems
CN0418 - Analog output and HART for PLC/DCS systems
CN0416 - RS485 transceiver.

 
Modules
       
dcs_cn0414_utilities
dcs_cn0418_utilities
minimalmodbus
serial
sys

 
Functions
       
detect_system_configuration(global_data: Dict[str, Any]) -> Tuple[List[int], List[int]]
Detect boards connected.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    Tuple of two lists
generate_channel_register_address(channel_type: str, address: List[int]) -> int
Generate channel register address.
 
Args:
    channel_type:
        - If "V" voltage channel is selected
        - If "I" current channel is selected
    address: List of MODBUS address, CS and channel number
 
Returns:
    Register address
generate_register_address(address: List[int]) -> int
Generate register address from a list.
 
Args:
    address: list used to generate the the registers address
 
Returns:
    Return the registers address
print_table(register_address: int, register_count: int, labels: List[str], registers: List[int]) -> None
Print data in a table.
 
Print registers addresses, description and
    current value in a colored table format.
 
Args:
    register_address: First register number
    register_count: Number of registers
    labels: Registers description
    registers: Registers values
 
Returns:
    None
read_analog_input_regs_from_sys_config(global_data: Dict[str, Any]) -> None
Read analog input registers from detected system configuration.
 
Determine the number and type (analog input/output) of the boards detected
in the curent system configuration and read all analog input registers.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    None
read_common_analog_input_regs(global_data: Dict[str, Any], register_address: int = 0, registers_number: int = 5, debug: bool = False) -> List[int]
Read common analog input registers.
 
Read common analog input registers with function code 4.
 
Args:
    global_data: Dictionary with global variables
    register_address: MODBUS register start address (default value = 0)
    registers_number: Number of MODBUS register read (default value = 5)
    debug: If True will print registers description and value
        in a colored table (default value = False)
 
Returns:
    Return a list of registers values
read_common_output_holding_regs(global_data: Dict[str, Any], register_address: int = 254, registers_number: int = 2, debug: bool = False) -> List[int]
Read common output holding registers.
 
Read common output holding registers with function code 3.
 
Args:
    global_data: Dictionary with global variables
    register_address: MODBUS register start address (default value = 254)
    registers_number: Number of MODBUS register read (default value = 2)
    debug: If True will print registers description and value
        in a colored table (default value = False)
 
Returns:
    Return a list of registers values
read_output_holding_regs_from_sys_config(global_data: Dict[str, Any]) -> None
Read output holding registers from detected system configuration.
 
Determine the number and type (analog input/output) of the boards detected
in the curent system configuration and read all output holding registers.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    None
request_cs_data(global_data: Dict[str, Any]) -> int
Request CS address.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    CS address
request_info() -> Tuple[str, int, float, float, List[int], List[str]]
Request input data.
 
List all serial devices detected in use and wait for the user to choose
which port/serial device want to use.
 
Args:
    None
 
Returns:
    Return requested port name, modbus address,modbus timeout, delay
    between commands and devices address(es) for current MODBUS address
request_reconfig_data(global_data: Dict[str, Any]) -> Tuple[int, int]
Request device CS address and register value.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    Return requested device address and register value
scan_system_config(port_name: str, delay: float) -> Tuple[List[int], List[List[int]], List[List[str]]]
Detect system configuration for each possible MODBUS node.
 
Create an instrument object for each MODBUS node and read 5 analog
input registers with function code 4 starting from address 0.
Print registers description and value in a colored table.
Convert first 4 registers value in binary format and check if the least
significant bit is 0 or 1. If 0 is found, an analog input board have been
detected, else, if 1 is found, an analog output board have been detected.
 
Args:
    port_name: COMPORT name
 
Returns:
    None
select_and_write_register(global_data: Dict[str, Any]) -> None
Write any output holding register.
 
Args:
    global_data: Dictionary with global variables
 
Returns:
    None
serial_devices() -> Tuple[List[str], List[str]]
List serial port names and description.
 
Search for all serial devices detected in use and return
their description and port name as a list with an index.
 
Args:
    None
 
Returns:
    Return a tuple of two lists, serial device(s) description(s)
    and serial device(s) port(s).
serial_ports() -> List[str]
List serial port names.
 
Args:
    None
 
Returns:
    List of detected serial ports.
sleep(...)
sleep(seconds)
 
Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
switch_modbus_address(selected_port: str, timeout: float) -> Tuple[int, List[int], List[str]]
Switch between MODBUS address.
 
Args:
    selected_port: Port name
    timeout: MODBUS timeout
 
Returns:
    Return a tuple of two lists, MODBUS address(es)
    and detected device(s) address(es).
write_output_holding_reg(global_data: Dict[str, Any], address: List[int], registers_values: int) -> None
Write output holding register.
 
Write a single output holding register with function code 6.
 
Args:
    instrument: Instrument object created by minimalmodbus
    delay: Delay between MODBUS commands
    address: MODBUS register address
    registers_values: New MODBUS register value to be write
 
Returns:
    None

 
Data
        Any = typing.Any
Dict = typing.Dict
Fore = <colorama.ansi.AnsiFore object>
List = typing.List
Tuple = typing.Tuple
__status__ = 'Development'

 
Author
        Mihai Ionut Suciu