pyopticon.majumdar_lab_widgets package
Submodules
pyopticon.majumdar_lab_widgets.aalborg_dpc_widget module
- class pyopticon.majumdar_lab_widgets.aalborg_dpc_widget.AalborgDPCWidget(parent_dashboard, name, nickname, default_serial_port, default_gas='Ar', **kwargs)
Bases:
GenericWidgetWidget for an Aalborg DPC mass flow controller (MFC). This widget controls a single MFC via a serial port.
By default, the gas selection dropdown includes a few gases that the author happened to use. Aalborg has many, many gas options in its user manual. You can configure the gas options in the constructor.
In practice, the MFC’s sometimes bug out when serial commands are sent directly back-to-back, so we use a short delay between queries/commands that are sent.
One can add a manual calibration curve, though these devices tend to be pretty accurate. This is done by tabulating the commanded flow (i.e., the value sent to the MFC) and the actual flow (according to an external flow meter) at various flow conditions, then feeding the resulting tuples of flows to the constructor for this class.
- Parameters:
parent_dashboard (richardview.dashboard.RichardViewDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’
default_gas (str, optional) – The default gas that’s selected in the dropdown, defaults to ‘Ar’ for Argon
gas_options (list, optional) – The list of gas names (strings) that can be selected. Defaults to argon, hydrogen, and methane.
gas_numbers (list, optional) – The list of gas numbers (integers) corresponding to gas_options according to the Aalborg DPC handbook. Defaults to indices for Ar, H2, and CH4.
calibration (tuple, optional) – a tuple containing two tuples of ints or floats with the results of calibrating the MFC. The first should contain a range of flow commands sent to the MFC. The second should contain the result flows according to an external flow meter. (0,0) should be included, as should a value above the highest flow you expect to use. For example, ( (0,10,20,30), (0,11.5,20.7,33.4) ).
- on_failed_serial_open()
If serial failed to open, set the readouts to ‘no reading’.
- on_handshake()
Conduct a handshake and populate the default values.
- on_update()
Send four queries to the serial device asking for the gas selection, mode, setpoint, and actual flow rate. Mode refers to open, closed, or setpoint. Read and process the responses.
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
- on_confirm()
When ‘confirm’ is pressed, send the appropriate commands to the MFC. Prints warnings to console if the entered parameters are invalid.
pyopticon.majumdar_lab_widgets.iot_relay_widget module
- class pyopticon.majumdar_lab_widgets.iot_relay_widget.IotRelayWidget(parent_dashboard, name, nickname, default_serial_port)
Bases:
GenericWidgetWidget for using an Arduino to control a Digital Loggers Internet of Things (IoT) Relay, like this: https://www.digital-loggers.com/iot2.html . This can be used for on/off control of pretty much any AC-powered device like a light, fan, or pump.
The arduino is expected to control the IoT relay with a digital output pin and to read serial commands using its built-in USB connection. An arduino nano works well; these typically use mini-B USB connections. The arduino ground and digital output pin get connected to the green connector on the side of the IoT relay. Commands to the arduino are broken up by carriage return and newline characters. The arduino should turn on the IoT relay when the command ‘1’ is received and turn it off when the command ‘0’ is received. Additionally, when the command ‘Q’ for query is received, it should reply with its status (‘1’ or ‘0’) followed by a newline or carriage return character.
A suitable arduino sketch (program) to control the IoT relay can quickly be written by analogy to this Arduino forum post: https://forum.arduino.cc/t/serial-commands-to-activate-a-digital-output/49036/3 A working .ino sketch is also available in the majumdar_lab_widgets source code file on this project’s Github.
- Parameters:
parent_dashboard (richardview.dashboard.RichardViewDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’
- on_failed_serial_open()
If serial failed, set readout to ‘No Reading’
- on_handshake()
Handshake with the Arduino.
- on_update()
Query the device and update the display based on the reply.
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
- on_confirm()
When ‘confirm’ is pressed, send the appropriate commands to the arduino.
pyopticon.majumdar_lab_widgets.mks_mfc_widget module
- class pyopticon.majumdar_lab_widgets.mks_mfc_widget.MksMFCWidget(parent_dashboard, name, nickname, channel, **kwargs)
Bases:
GenericWidgetWidget to control MKS ‘mass flo controllers’ (MFCs), which are themselves controlled by an MKS ‘vacuum controller’.
A control box like an MKS ‘946 Vacuum System Controller’ converts digital signals or manual inputs into the actual voltage and/or current signals that control MKS mass flo controllers. One 946 control box can control up to 6 mass flo controllers at once, with some trickery required (described below) to let multiple widgets share a single serial connection.
Each control box has a 3-digit ID number, e.g. 001, which can be configured on the box. Each MFC on the box has a channel, which is one of {A1, A2, B1, B2, C1, C2}. These are fixed when you initialize a widget and can’t be changed from the GUI.
Each mass flo controller on the same vacuum controller gets its own widget, even though they all share the same control box and hence the same serial connection. The first MFC widget is initialized normally, and then for every subsequent widget representing an MFC on the same control box, the constructor is called with the first widget passed as the keyword argument ‘widget_to_share_serial_with’. The later widgets then know to share the serial connection with the first widget, rather than trying to initialize a new one, which would fail because that serial port is already in use by the first widget.
One can also set a ‘scale factor,’ which adjusts for different gas types (e.g. air is usually a conversion factor of 1.0). Refer to the MKS MFC documentation for what scale factor to use for a particular gas. One can optionally lock the scale factor for a certain widget.
Finally, one can add a manual calibration curve independent of the scale factor. This is done by tabulating the commanded flow (i.e., the value sent to the MFC) and the actual flow (according to an external flow meter) at various flow conditions, then feeding the resulting tuples of flows to the constructor for this class.
- Parameters:
parent_dashboard (richardview.dashboard.RichardViewDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
channel (str) – A string representing which channel on the control box the MFC is connected to. One of (A1,A2,B1,B2,C1,C2).
widget_to_share_serial_with (richardview.majumdar_lab_widgets.mks_mfc_widget.MksMFCWidget, optional) – If this is the 2nd-6th MFC sharing the same control box, pass the widget for the first MFC on that control box as this argument. If not, the arguments device_ID and default_serial_port are required.
device_ID (str, optional) – The ID of the MKS control box / vacuum system controller, which is a string of a 3-digit number, e.g. ‘001’. Can be set on the control box.
default_serial_port (str, optional) – The name of the default selected serial port, e.g. ‘COM9’
force_scale_factor (float, optional) – Optionally set a certain scale factor and disable adjusting the scale factor via the interface. See the MKS manual to select factors for different gases.
calibration (tuple, optional) – a tuple containing two tuples of ints or floats with the results of calibrating the MFC. The first should contain a range of flow commands sent to the MFC. The second should contain the result flows according to an external flow meter. (0,0) should be included, as should a value above the highest flow you expect to use. For example, ( (0,10,20,30), (0,11.5,20.7,33.4) ).
- on_failed_serial_open()
If serial opened unsuccessfully, set readouts to ‘No Reading’
- on_handshake()
This function gets called whenever the widget is initialized. If the widget uses a Serial connection, you can assume that the serial connection was already initialized successfully. If not, you’ll need to initialize whatever objects are needed to update the widget in this method (say, an OEM Python driver).
By default, it just calls on_update(), assuming that the handshake was successful if (and only if) no exception was raised.
- on_update()
Send four queries to the serial device asking for the gas scale factor, mode, setpoint, and actual flow rate. Mode refers to open, closed, or setpoint. Process the results.
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
- on_confirm()
When ‘confirm’ is pressed, send the appropriate commands to the MFC. Prints warnings to console if the entered parameters are invalid.
pyopticon.majumdar_lab_widgets.omega_usb_utc_widget module
- class pyopticon.majumdar_lab_widgets.omega_usb_utc_widget.OmegaUSBUTCWidget(parent_dashboard, name, nickname, default_serial_port)
Bases:
GenericWidgetWidget for an Omega USB-UTC thermocouple reader. A USB-UTC converts a single thermocouple (using the usual 2-prong thermocouple connection) into a USB signal. The Omega thermocouple reader desktop app can be used to set what type of thermocouple (K-type, etc.) is assumed.
- Parameters:
parent_dashboard (pyopticon.dashboard.PyOpticonDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’
- on_failed_serial_open()
If serial opened unsuccessfully, set readouts to ‘No Reading’
- on_update()
Update the device by polling the serial connection.
- on_serial_query()
Send a query to the serial device asking for the temperature.
- on_serial_read()
Parse the responses from the previous serial query and update the display. Return True if valid and and error string if not.
- Returns:
True if the response was of the expected format, an error string otherwise.
- Return type:
bool or str
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
pyopticon.majumdar_lab_widgets.picarro_crd_widget module
- class pyopticon.majumdar_lab_widgets.picarro_crd_widget.PicarroCRDWidget(parent_dashboard, name, nickname, default_serial_port)
Bases:
GenericWidgetWidget for a Picarro GG201-i isotopic analyzer that measures 0-30 ppm CH4, 200-2000+ ppm CO2, and 0-100% relative humidity.
Refer to the Picarro manual to configure one of its extra serial ports for data logging to an external device. Two modes are possible. In one, the Picarro listens for a query and replies with its latest measurements. In the other, the Picarro sends its latest measurements every second. We chose to use the ‘send measurements every second’ option. This means that the Picarro widget only listens for measurements, and doesn’t ever send any queries via the serial line. There wasn’t a super strong reason for choosing one over the other, except for slightly more resilience to the Picarro ‘lagging’ for a few seconds when it receives a methane concentration above its 30 ppm ‘limit’.
The Picarro needs to be set to send (in this order) the CH4 concentration in ppm, the water concentration in volume percent, and the CO2 concentration in ppm. This is done using the Picarro’s own monitor and interface, as described in its manual – contact the manufacturer if your manual doesn’t tell you how to do this.
- Parameters:
parent_dashboard (richardview.dashboard.RichardViewDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’
- on_failed_serial_open()
If serial opened unsuccessfully, set readouts to ‘No Reading’
- on_update()
Parse the latest message from the Picarro and update the display.
Note that sometimes we get unlucky with the timing and a valid Picarro message gets chopped off halfway through and fails to parse. So occasionally we get a ‘read error’ when the instrument is behaving just fine. This is easy to fix in data post-processing, but we might also consider fixing it by switching to a query-response setup.
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
pyopticon.majumdar_lab_widgets.valco_2_way_valve_widget module
- class pyopticon.majumdar_lab_widgets.valco_2_way_valve_widget.Valco2WayValveWidget(parent_dashboard, name, nickname, default_serial_port, valve_positions, valve_id='1')
Bases:
GenericWidgetWidget for a VICI Valco 2-position valve, like this: https://www.vici.com/vval/vval_2pos.php . These valves have two positions that are internally referred to as ‘A’ and ‘B’. In the widget, the positions can be labeled whatever you want.
Valco produces many other valves, e.g. 9-way selector valves. To control one of them, you could probably copy-paste the source code of this module and make pretty minor modifications to on_serial_query, on_serial_read, on_confirm, and the serial emulator class. Refer to the valve’s documentation and/or mess around manually with a serial connection (Pyserial in a shell like IDLE is probably easiest) to figure out the serial protocol for controlling a different type of Valco valve – e.g., valves with more than 2 positions may label the positions with numbers rather than letters in the serial protocol.
- Parameters:
parent_dashboard (pyopticon.dashboard.PyOpticonDashboard) – The dashboard object to which this device will be added
name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”
nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”
default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’
valve_positions (list) – A list of strings with which to label the valve positions. For a 2-way valve, this should be a 2-element list with the labels for valve positions A and B respectively.
valve_id – A string representing the ID of the valve, which goes at the beginning of each command. This seems to always be ‘1’. However, if there are issues, going into a serial shell
(e.g. Pyserial in IDLE) and sending the message b’*IDr’ to the valve should cause it to respond with its ID.
- on_failed_serial_open(success)
Set fields to no reading if serial failed to open.
- on_update()
Update the widget by querying and reading the serial port.
- on_serial_query()
Send a query to the valve asking for its current position.
- on_serial_read()
Parse the responses from the previous serial query and update the display. Return True if the response is valid and an error string if not.
- on_serial_close()
When serial is closed, set all readouts to ‘None’.
- on_confirm()
When ‘confirm’ is pressed, send the appropriate commands to the valve.