sxip_drivers.py

Sxip class

class sxip.Sxip(modbus_link: Modbus = None, modbus_addr: int = 1)

Bases: object

Allows to instantiate a SxIP device, then provides methods to access it.

Parameters:
  • modbus_link – modbus_link objet instantiated from the modbus module or None (default)

  • modbus_addr – device’s Modbus slave address (0 to 247). 0 is broadcast.

property modbus_addr

Get or set the Modbus address of the device. int: device’s Modbus slave address (0 to 247). 0 is broadcast.

read_registers(reg_addr: int, nb_reg: int = 1, **kwargs) list

Read a register from the SxIP device.

Parameters:
  • reg_addr – Starting address (0x0000 to 0xFFFF).

  • nb_reg – Quantity of registers to read (1 to 125).

  • kwargs – Arbitrary keyword arguments.

Returns list(int):

Registers’ content.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

write_register(reg_addr: int, value: int, **kwargs) None

Write a register to the SxIP device.

Parameters:
  • reg_addr – Starting address (0x0000 to 0xFFFF).

  • value – Value to write (0x0000 to 0xFFFF).

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

write_registers(reg_addr: int, values: list, **kwargs) None

Write multiple registers to the SxIP device.

Parameters:
  • reg_addr – Starting address (0x0000 to 0xFFFF).

  • values – List of words (0x0000 to 0xFFFF) to write (max 123 words).

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

write_coil(coil_addr: int, state: str, **kwargs) None

Write a coil to the SxIP device.

Parameters:
  • reg_addr – Coil’s address (0x0000 to 0xFFFF).

  • state – state to write (‘ON’ or ‘OFF’).

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

reset() None

Reset the SxIP device (software reset).

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_init_done() None

Set the init done flag of the SxIP device.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

clear_init_done() None

Clear the init done flag of the SxIP device.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

clear() None

Clear error flags of the SxIP device.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

flash() None

Trigger a flash from the SxIP device.

Software trigger is for test purpose. Trigger delay is long and inconstant.

save_settings() None

Save actual settings in the SxIP device memory.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

clear_lamp_count() None

Clear the SxIP device lamp count (At lamp replacement).

get_state() dict

Read device’s state.

Returns {str:

bool}: A dictinonay of flags’ names and states state values could be 0 or 1:

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_config_inputs() int

Read device’s configuration inputs’ value (1..16).

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_io_state(output: str = 'binary') dict

Read device’s inputs and outputs’ state.

Parameters:

output – ‘binary’ or ‘dict’

Returns flag byte:

if output is selected to ‘binary’:

bit

6

5

4

3

2

1

0

IO

ISO_OUT

TTL_IO

DRY_INPUT

IN4

IN3

IN2

IN1

DRY_INPUT and ISO_OUTPUT are 1 when closed

Returns dict:

if output is selected to ‘dict’: A dictionnay with couples of IOnames and states

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_serial() int

Read device’s serial number.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_date() tuple

Read device’s manufacturing date.

Returns list(int):

year, week

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_hwrev() str

Read device’s hardware revision.

Returns str:

Major.minor (A.00)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_modbus_address() int

Read device’s modbus address

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_energy_level() int

Read device’s current energy level

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_ftime() int

Read device’s current flash time (µs)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_input_voltage() int

Return device’s input voltage (V)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_temperature() int

Read device’s temperature (°C)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_last_flash_energy() int

Read device’s last flash energy (J)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_flash_error_count() int

Read device’s error count

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_flash_healt() int

Read device’s health value

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_minmax_temp() tuple

Read device’s minimum and maximum recorded temperatures

Returns:

int: minimum temperature (°C) int: maximum_temperature (°C)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_start_count()

Read device’s start count

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_time_count()

Read device’s time counter since last power-up

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_total_time_count()

Read slave device’s total power-up time count

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_flash_count()

Read device’s flash counter since last power-up

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_total_flash_count()

Read device’s total flash counter

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

get_lamp_count()

Read device’s lamp counter

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_voltage(voltage: int) None

Set the regulation voltage (V)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_ftime(ftime: int) None

Set the flash time (µs)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_mode(mode: str = 'ftime') None

Set the device operating mode.

Parameters:

mode

ftime = Fixed ftime.

burst = Ftime is according to the ftime table. Allows successive flashes without recharge.

energy_reg = Ftime is according to the energy level table. Flash energy is regulated.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_fan(mode: str = 'temp_regulated', level: int = 100) None

Set the fan’s operating parameters.

Parameters:
  • mode

    fixed level = Fan speed is fixed to the level.

    temp_regulated = Fan speed is regulated according to both power and temperature with minium speed = level.

    power_regulated = Fan speed is regulated according to power with is the minium speed = level.

  • level – [0..100] %

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_health_param(missed_flash_weight: int, health_treshold: int) None

Set flash health supervision parameters.

Parameters:
  • missed_flash_weight – When a flash is missed, health value is increased by this value When a flash is succeded, health value is decreased by 1

  • health_threshold – Health value that triggers an error.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_reset_on_failure(delay: int) None

Set the reset on failure delay

Parameters:

delay – Delay from failure detection to reset. If 0, SxIP will not reset (remains locked in failure)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_modbus_addr(address: int) None

Set the modbus address.

Parameters:

address – Modbus address [0..247]

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_energy_levels(prim_energy_level: int, alt_energy_level: int = 0) None

Set the energy levels

Parameters:
  • prim_energy_level – Energy level [0..16]

  • alt_energy_level – Energy level [0..16]

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_trigger_delay(delay: int)

Set delay from trigger input edge to flash triggering.

Parameters:

delay – delay from trigger input edge to flash triggering (µs)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_sync_shift(slave: int, time_shift: int) None

Set synchronisation signal relatively to the flash triggering.

Parameters:
  • time_shift – time shift (µs)

  • alt_energy_level – Energy level [0..16]

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_sync_pulse_time(duration: int) None

Set synchronisation pulse duration

Parameters:

duration – synchronisation pulse width (µs)

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_io5(polarity: str = 'high', buffer: str = 'schmitt', mode: str = 'not_used') None

Configure IO5 (Dry input) functionnality.

Parameters:
  • polarity

    low = active low, trigger on falling edges.

    high = active high, trigger on rising edges.

  • buffer

    schmitt = optimized for 12V levels (Levels are 2.0V & 8.0V).

    TTL = 5V compatible (levels are 1.6V & 4.0V).

  • mode

    not_used = Has no effect.

    flash_trigger = Trigger the flash.

    alt_energy_selector = Turns to alternate energy level.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_io6(polarity: str = 'high', buffer: str = 'schmitt', mode: str = 'not_used') None

Configure IO6 (TTL IO) functionnality.

Parameters:
  • polarity

    low = active low, trigger on falling edges.

    high = active high, trigger on rising edges.

  • buffer

    schmitt = Levels are 1.0V and 4.0V).

    TTL = 3.3V compatible (levels are 0.8V and 2.0V).

  • mode

    not_used = Has no effect.

    flash_trigger = Trigger the flash.

    alt_energy_selector = Turns to alternate energy level.

    low = Force output to low state.

    high = Force output to high state.

    sync_output = Output the synchronisation signal.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

set_io7(polarity: str = 'high', mode: str = 'not_used') None

Configure IO7 (Isolated output) functionnality.

Parameters:
  • polarity

    low = active low.

    high = active high.

  • mode

    not_used = Has no effect.

    open = Force output to open state.

    closed = Force output to closed state.

    sync_output = Output the synchronisation signal.

Raises:
  • ValueError – Arguments are out of range.

  • ModbusError – Modbus protocol error or the device answers with an exception.

  • serial.SerialException – Serial port is missing, busy, or can not be configured.

Exceptions

Exceptions inherited from phox-modbus

class modbus.ModbusError

Exception raised in case of Modbus communication error.

class modbus.SlaveExceptionError

Exceptions that the Modbus device reports.

class modbus.IllegalRequestError

The slave has received an illegal request.

Can be “Illegal function”, “Illegal address” or “Illegal data value”

class modbus.MasterReportedError

Exceptions that are detected by the master.

class modbus.NoResponseError

No response from the slave.

class modbus.InvalidResponseError

The response does not fulfill the Modbus standad.

Exceptions inherited from pyserial

class serial.SerialException

Base class for serial port related exceptions.

class serial.PortNotOpenError

Port is not open

class serial.SerialTimeoutException

Write timeouts give an exception