This example uses
instro-unstable. This code is new and may change without notice.alicat_mc.py
"""Example: Alicat MC low-level control.
Most users should instead use the very high level tooling provided by InstroFlowController.
For lower-level control, including the ability to query metadata from the device, the driver
can be accessed directly.
"""
from decimal import Decimal
from instro.lib.transports.visa import SerialConfig, TerminatorConfig, VisaConfig
from instro.unstable.flowcontroller.drivers.alicat_constants import LoopVariable
from instro.unstable.flowcontroller.drivers.alicat_mc import AlicatMC, GasMixEntry
VISA_RESOURCE = "ASRL7::INSTR"
device = AlicatMC(
VisaConfig(
visa_resource=VISA_RESOURCE,
serial_config=SerialConfig(baud_rate=19200),
terminator=TerminatorConfig(read="\r", write="\r"),
),
device_id="A",
)
print(f"Opening connection to alicat on visa resource: {VISA_RESOURCE}")
device.open()
###Tare types
print(f"Performing Tare command on alicat")
print(device.tare_flow())
print(f"Performing barometer tare command on alicat -- this is device-specific and may fail")
try:
print(device.tare_barometer())
except Exception as e:
print(f"Barometer tare not supported: {e}")
print(f"Querying for gas types on alicat")
###GAS TYPES
gastypes = device.list_gas_types()
print(f"Found {len(gastypes)}, printing first: {gastypes[:5]}")
gas_type = "h2"
print(f"Setting alicat to {gas_type}")
gas_type_ret = device.select_working_fluid(gas_type)
print(f"Set alicat to {gas_type_ret}")
gas_type = "air"
print(f"Setting alicat to {gas_type}")
gas_type_ret = device.select_working_fluid(gas_type)
print(f"Set alicat to {gas_type_ret}")
gas_mix_name = "tstmix"
gas_mix_id = 255
print(f'Defining a gas mixture "{gas_mix_name}" that is 74.99% air and 25.01% h2 as gas id {gas_mix_id}')
new_gas_mix = device.define_gas_mixture(
gas_mix_name, [GasMixEntry(Decimal("74.99"), 0), GasMixEntry(Decimal("25.01"), 6)], gas_id=gas_mix_id
)
print(f"New gas mix defined: {new_gas_mix}")
###META
print(f"Querying for measurement metadata")
meas_heads = device.get_flow_sample_metadata()
print(f"Found {len(meas_heads)} columns, printing first: {meas_heads[:8]}")
###Normal commanding
setpoint = 1.23
print(f"setting alicat setpoint to {setpoint}")
setpoint_ret = device.set_setpoint(setpoint)
print(f"Set alicat setpoint to {setpoint_ret}")
print(f"Current flow reading = {device.get_flow_data()}")
setpoint = 2.34
print(f"setting alicat setpoint to {setpoint} using integer setpoint")
setpoint_ret = device.set_setpoint_int(setpoint, 100, 0)
print(f"Set alicat setpoint to {setpoint_ret}")
print(f"Current flow reading = {device.get_flow_data()}")
###Single-value convenience properties
print(f"Setpoint = {device.setpoint}")
print(f"Mass flow = {device.mass_flow}")
print(f"Volumetric flow = {device.volumetric_flow}")
print(f"Pressure = {device.pressure}")
###Loop control variable (process value source) demonstration
print(f"\nQuerying current loop control variable...")
print(f"Process value (current loop var measurement) = {device.process_value}")
print(f"Process value source key = {device.process_value_source}")
print(f"\nSetting loop control variable to VOLUMETRIC_FLOW...")
setpoint_ret = device.set_loop_control_variable(LoopVariable.VOLUMETRIC_FLOW)
print(f"Set loop variable, device returned setpoint: {setpoint_ret}")
print(f"Process value after change = {device.process_value}")
print(f"Process value source after change = {device.process_value_source}")
print(f"\nSetting loop control variable back to MASS_FLOW...")
setpoint_ret = device.set_loop_control_variable(LoopVariable.MASS_FLOW)
print(f"Set loop variable, device returned setpoint: {setpoint_ret}")
print(f"Process value after change = {device.process_value}")
print(f"Process value source after change = {device.process_value_source}")
###Valve hold commands
print(f"\nForcing valve to closed position on alicat")
print(device.hold_valve_closed())
print(f"Current flow reading = {device.get_flow_data()}")
print(f"Un-forcing valve closed on alicat")
print(device.cancel_valve_hold())
print(f"Current flow reading = {device.get_flow_data()}")
print(f"\nForcing valve to current position on alicat")
print(device.hold_valve_at_position())
print(f"Current flow reading = {device.get_flow_data()}")
print(f"Un-forcing valve position on alicat")
print(device.cancel_valve_hold())
print(f"Current flow reading = {device.get_flow_data()}")
###Cleanup
print(f"\nClosing connection to alicat")
device.close()