mx2
index
/Users/vpaeder/Projects/pymx2/mx2/__init__.py

A driver to communicate with an Omron MX2 inverter through Modbus.
 
Classes:
    MX2
 
Functions:
    crc16
 
Submodules:
    enums
    exceptions

 
Package Contents
       
enums
exceptions
types

 
Classes
       
builtins.object
MX2

 
class MX2(builtins.object)
    MX2(port: str = '', baud_rate: int = 9600, parity: str = 'N') -> None
 
A driver to control an Omron MX2 inverter
using RS-485 (Modbus).
 
Protected attributes:
    _latency_time(int): additional delay, in ms, between request and response (default: 30).
    _wait_time(int): total delay, in ms, between request and response (_latency_time + 3.5 characters).
    _last_req_time(float): time when last request was issued.
    _dev_id(int): device ID (default: 1).
    _ser(serial.rs485.RS485): Modbus driver instance.
 
  Methods defined here:
__init__(self, port: str = '', baud_rate: int = 9600, parity: str = 'N') -> None
Constructor.
 
Parameters:
    port(str): logical path of RS-485 device (default: "").
    baud_rate(int): serial baud rate (default: 9600).
    parity(str): serial parity (default: serial.PARITY_NONE).
close(self) -> None
Close serial connection with MX2 inverter.
 
Raises:
    SerialException: if connection is not open.
    SerialException: if connection couldn't be closed.
get_baud_rate(self) -> int
Get serial baud rate.
 
Returns:
    int: baud rate.
get_device_id(self) -> int
Get device ID.
 
Returns:
    int: device ID.
get_latency_time(self) -> int
Get latency time, in ms.
 
Returns:
    int: latency time.
get_parity(self) -> str
Get serial parity.
 
Returns:
    str: serial parity.
get_port(self) -> str
Get path of RS-485 device port.
 
Returns:
    str: port path.
get_stop_bits(self) -> int
Get number of stop bits.
 
Returns:
    int: number of stop bits.
loopback_test(self) -> None
Perform a loopback test.
 
Raises:
    BadRequestException: if device ID is a broadcast address.
    BadResponseLengthException: if response length isn't 8.
    BadResponseException: if response data differs from request.
open(self) -> None
Open serial connection with MX2 inverter.
 
Raises:
    SerialException: if connection is already open.
    SerialException: if connection couldn't be opened.
read_and_write_registers(self, read_start_address: mx2.enums.Register, write_start_address: mx2.enums.Register, read_count: int, write_values: 'list[int]') -> bytes
Read from and write to one or more registers at once.
 
Parameters:
    read_start_address(Register): address of 1st register to read.
    write_start_address(Register): address of 1st register to set.
    read_count(int): number of registers to query, from 1 to 16.
    values(list[int]): register values to write.
 
Returns:
    list[int]: the values of requested registers as a list of integers.
 
Raises:
    BadRequestException: if device ID is a broadcast address.
    BadParameterException: if read start address is outside bounds.
    BadParameterException: if write start address is outside bounds.
    BadParameterException: if read_count is outside bounds.
    BadParameterException: if len(values) is zero or more than 16.
    BadParameterException: if any of the values is less than 0 or more than 65535.
    BadResponseLengthException: if response length doesn't match read_count.
read_coil_status(self, start_address: mx2.enums.Coil, coil_count: int) -> 'list[CoilValue]'
Read the status of one or more coils.
 
Parameters:
    start_address(Coil): address of 1st coil to read.
    coil_count(int): number of coils to query, between 1 and 31.
 
Returns:
    list[CoilValue]: the coil states as coil value objects.
 
Raises:
    BadRequestException: if device ID is a broadcast address.
    BadParameterException: if start address is outside bounds.
    BadParameterException: if coil_count is outside bounds.
    BadResponseLengthException: if response length is inconsistent with coil_count.
read_fault_monitor(self, index: int, value: mx2.enums.FaultMonitorData) -> int
Query fault monitor.
 
Parameters:
    index(int): fault monitor index (from 1 to 6).
    value(FaultMonitorData): index of fault monitor data to read (from 0 to 9, see enum).
 
Returns:
    int: fault monitor value.
 
Raises:
    BadParameterException: if fault monitor index if outside bounds.
    BadParameterException: if fault monitor data index is outside bounds.
read_registers(self, start_address: mx2.enums.Register, register_count: int) -> 'list[RegisterValue]'
Read the content of one or more registers.
 
Parameters:
    start_address(Register): address of 1st register to read.
    register_count(int): number of registers to query, from 1 to 16.
 
Returns:
    list[RegisterValue]: register values as a list of RegisterValue objects.
 
Raises:
    BadRequestException: if device ID is a broadcast address.
    BadParameterException: if start address is outside bounds.
    BadParameterException: if register count is outside bounds.
    BadResponseLengthException: if response length doesn't match register count.
set_baud_rate(self, baud_rate: int) -> None
Set serial baud rate. Can take the following values:
   2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200.
Must match setting C071 of MX2 inverter.
 
Parameters:
    baud_rate(int): serial baud rate.
 
Raises:
    SerialException: if connection is already open.
    BadParameterException: if baud rate is invalid.
set_device_id(self, dev_id: int) -> None
Set device ID. This can be between 1 and 247 for
single device or between 250 and 254 for broadcast and
must match setting C072 of MX2 inverter.
set_latency_time(self, latency_time: int) -> None
Set latency time, betweeen 0 and 1000 ms.
Must be at least as much as setting C078 of MX2 inverter.
In case device returns no data, try increasing this.
set_parity(self, parity: str) -> None
Set serial parity. Can be serial.PARITY_NONE,
serial.PARITY_EVEN, serial.PARITY_ODD.
Must match setting C074 of MX2 inverter.
 
Parameters:
    parity(str): serial parity.
 
Raises:
    SerialException: if connection is already open.
    BadParameterException: if parity is not amongst allowed values.
set_port(self, port: str) -> None
Set path of RS-485 device port.
 
Parameters:
    port(str): logical path of RS-485 device.
 
Raises:
    SerialException: if connection is already open.
    BadParameterException: if port path is None.
set_stop_bits(self, stop_bits: int) -> None
Set number of stop bits (either 1 or 2).
Must match setting C075 of MX2 inverter.
 
Parameters:
    stop_bits(int): number of stop bits.
 
Raises:
    SerialException: if connection is already open.
    BadParameterException: if stop bit value is not 1 or 2.
write_in_coil(self, address: mx2.enums.Coil, state: bool) -> None
Set the state of a coil.
 
Parameters:
    address(Coil): coil address.
    state(bool): state to set.
 
Raises:
    BadParameterException: if address is outside bounds.
    BadResponseLengthException: if response length isn't 8.
    BadResponseException: if response data differs from request.
write_in_multiple_coils(self, start_address: mx2.enums.Coil, values: 'list[bool]') -> None
Set the state of multiple coils at once.
 
Parameters:
    start_address(Coil): address of 1st coil to set.
    values(list[bool]): coil values.
 
Raises:
    BadParameterException: if start address is outside bounds.
    BadParameterException: if len(values) is zero or more than 31.
    BadResponseLengthException: if response length isn't 8.
    BadResponseException: if response data differs from request.
write_in_multiple_registers(self, start_address: mx2.enums.Register, values: 'list[int]') -> None
Set the values of multiple registers at once.
 
Parameters:
    start_address(Register): address of 1st register to set.
    values(list[int]): register values.
 
Raises:
    BadParameterException: if start address is outside bounds.
    BadParameterException: if len(values) is zero or more than 16.
    BadParameterException: if any of the values is less than 0 or more than 65535.
    BadResponseLengthException: if response length isn't 8.
    BadResponseException: if response data differs from request.
write_in_register(self, address: mx2.enums.Register, value: int) -> None
Set the value of a register.
 
Parameters:
    address(Register): register address.
    value(int): value to set, from 0 to 65535.
 
Raises:
    BadParameterException: if address is outside bounds.
    BadParameterException: if value is outside bounds.
    BadResponseLengthException: if response length isn't 8.
    BadResponseException: if response data differs from request.

Readonly properties defined here:
is_open

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
baud_rate
Get serial baud rate.
 
Returns:
    int: baud rate.
device_id
Get device ID.
 
Returns:
    int: device ID.
latency_time
Get latency time, in ms.
 
Returns:
    int: latency time.
parity
Get serial parity.
 
Returns:
    str: serial parity.
port
Get path of RS-485 device port.
 
Returns:
    str: port path.
stop_bits
Get number of stop bits.
 
Returns:
    int: number of stop bits.

 
Data
        __all__ = ['MX2']