PythonForTheLab.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 PythonForTheLab.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': '\n', 'read_timeout': 1, 'write_termination': '\n', 'write_timeout': 1}
finalize()[source]

Closes the resource

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

idn()[source]

Get the serial number from the device.

Returns:str – The serial number of the device
initialize()[source]

Opens the serial port with the DEFAULTS.

query(message)[source]

Wrapper around writing and reading to make the flow easier.

Parameters:message (str) – The message to send to the device
Returns:str – Whatever the message outputs
set_analog_output(channel, output_value)[source]

Sets the analog output of a channel

Parameters:
  • channel (int) – The channel
  • output_value (int) – The output value in the range 0-4095