Controller

isort:skip_file

class lvmecp.controller.controller.Module(plcname, config, name, mode, channels, description, *args, **kwargs)[source]

Bases: object

Defines modules connected with an PLC.

Parameters
  • plcname (str) – A plc name connected with the module.

  • config ([]) – The configuration defined on the .yaml file under /etc/lvmecp.yml

  • name (str) – Module name

  • mode (str) – Modbus memory type coil/register

  • channels (int) – Number of elements in the module

  • description (str) – An explanation of the module

config_get(key, default=None)[source]

Read the configuration and extract the data as a structure that we want. Notice: DOESNT work for keys with dots !!!

Parameters

key

The tree structure as a string to extract the data. For example, if the configuration structure is

ports;
1;

desc; “Hg-Ar spectral callibration lamp”

You can input the key as “ports.1.desc” to take the information “Hg-Ar spectral callibration lamp”

get_address()[source]

return a dictionary about modbus address of each element in module.

get_element()[source]

return a list of elements in module.

get_unit()[source]

return a dictionary about units of each element in module.

class lvmecp.controller.controller.PlcController(name, config, log)[source]

Bases: object

Talks to an Plc controller over TCP/IP.

Parameters
  • name (str) – A name identifying this controller.

  • config ([]) – The configuration defined on the .yaml file under /etc/lvmecp.yml

  • log (SDSSLogger) – The logger for logging

config_get(key, default=None)[source]

Read the configuration and extract the data as a structure that we want. Notice: DOESNT work for keys with dots !!!

Parameters

key

The tree structure as a string to extract the data. For example, if the configuration structure is

ports;
1;

desc; “Hg-Ar spectral callibration lamp”

You can input the key as “ports.1.desc” to take the information “Hg-Ar spectral callibration lamp”

async get_status(mode, addr)[source]

get the status of the device

Parameters
  • mode (str) – coil or holding_registers

  • addr (int) – modbus address

async static parse(value)[source]

Parse the input data for ON/OFF.

async read(mode, addr)[source]

read the data from devices

Parameters
  • mode (str) – coil or holding_registers

  • addr (int) – modbus address

async send_command(module, element, command)[source]

send command to PLC

Parameters
  • module (str) – The devices controlled by lvmecp which are “interlocks”, “light”, “shutter” and “emergengy”.

  • element (str) – The elements contained by the module

  • command (str) – on/off/status/trigger

async start(*argv)[source]

open the ModbusTCP connection with PLC

async stop()[source]

close the ModbusTCP connection with PLC

async write(mode, addr, data)[source]

write the data to devices

Parameters
  • mode (str) – coil or holding_registers

  • addr (int) – modbus address

  • data – ON 0xFF00 OFF 0x0000