Controller
One of the building blocks of the MVC design pattern. Controller hosts all the packages related to communication with devices. Each element should reflect exactly what a device is capable of doing and not the imposed logic from the experimentor. Loops, etc. should be placed within the Models.
Module contents
PFTL DAQ controller
Python For The Lab revolves around controlling a simple DAQ device built on top of an Arduino. The DAQ device is capable of generating up to two analog outputs in the range 0-3.3V and to acquire several analog inputs.
Because of the pedagogy of the course Python for the Lab, it was assumed that the device can generate value by value and not a sequence. This forces the developer to think on how to implement a solution purely on Python.
- class PFTL.controller.pftl_daq.Device(port)[source]
controller for the serial devices that ships with Python for the Lab.
- Parameters:
port (str) – The port where the device is connected. Something like COM3 on Windows, or /dev/ttyACM0 on Linux
- rsc
The serial communication with the device
- Type:
serial
- port
The port where the device is connected, such as COM3 or /dev/ttyACM0
- Type:
str
- DEFAULTS = {'baudrate': 9600, 'encoding': 'ascii', 'read_termination': '\r\n', 'read_timeout': 1, 'write_termination': '\n', 'write_timeout': 1}
- get_analog_input(channel)[source]
Get the Analog input in a channel
- Parameters:
channel (int) – The channel
output_value (int) – The output value in the range 0-4095
- Returns:
int – The value
- get_analog_output(channel)[source]
Retrieves the current value set to the analog channel
- Parameters:
channel (int) – The channel from which to retrieve the value
- Returns:
int – The setpoint in the given channel
- idn()[source]
Get the serial number from the device.
- Returns:
str – The serial number of the device