c_serial - Serial port base network coordinator

class pycstbox.hal.c_serial.SerialCoordinatorServiceObject(c_id)

Abstract class implementing the base tasks for a coordinator based on a serial port interface with the network.

It has to be overridden to provide the dispatch_received_data() method which is responsible for handling the incoming data, depending on the protocol in use for the relevant equipments.

Parameters:c_id (str) – coordinator id
serial_port

The serial port object used by the coordinator.

start()

Starts the service object.

This will initialize the serial port, open it and start the data receive thread.

stop()

Stops the service object.

This will stop the receive thread and close the serial port.

send_command(command, callback=None)

Sends a command for a device attached to the coordinator, handling appropriate locking for guarantying the atomicity of the operation (command sending, callback invocation).

Parameters:
  • command (str) – the command to be sent (device dependant)
  • callback (callable) – an optional callable invoked is the command is send without error
data_received(data)

Callback used by the receiver thread to notify us that a data packet is here to be processed.

Parameters:data – the received data
dispatch_received_data(data)

Dispatch the received data to the relevant devices, so that they return us the corresponding events to be emitted (if any).

This method must be implemented by concrete coordinators, in order to handle the device identification based on the protocol in use and transmit them the received data.

Parameters:data – the data to be processed
Returns:a list of events to be emitted (can be empty)
class pycstbox.hal.c_serial.SerialPortConfiguration(port, baudrate=4800, bytesize=8, parity='N', stopbits=1)

Convenience data holder for serial port configuration data, providing commonly used default settings.

update(src)

Updates attribute values based on information defined as attributes of another object (most often, an extract of the device network configuraton data structure). :param src: the configuration data source object