/ hardware_communication / lakeshore372device.py
lakeshore372device.py
1 from lakeshore.model_372 import Model372 2 3 4 class LakeShore372Device: 5 """ 6 Class to interact with the Lake Shore 372 Temperature Controller using the official driver. 7 """ 8 9 def __init__(self, port, name = None): 10 try: 11 if Model372 is not None: 12 self.device = Model372(com_port=port, baud_rate=57600) 13 else: 14 raise ImportError("Lake Shore Model372 driver not available.") 15 self.port = port 16 self.address = port # Added to store the address 17 self.input_channels = [] 18 self.output_channels = [] 19 self.list_channels() 20 self.name = name 21 print( 22 f"Connected to Lake Shore 372 on {port} with input channels {self.input_channels} and output channels {self.output_channels}") 23 except Exception as e: 24 raise e 25 26 def get_input_channels(self): 27 return self.input_channels 28 29 def get_output_channels(self): 30 return self.output_channels 31 32 def get_temperature(self, channel): 33 try: 34 if channel == 'A': 35 temp = self.device.get_all_input_readings(channel)['kelvin'] 36 else: 37 temp = self.device.get_all_input_readings(int(channel))['kelvin'] 38 return temp 39 except Exception as e: 40 print( 41 f"Error reading temperature from Lake Shore 372 (Channel {channel}): {e}" 42 ) 43 return None 44 45 def read_all_channels(self): 46 readings = {} 47 for channel in self.input_channels: 48 temp = self.get_temperature(channel) 49 readings[channel] = temp 50 return readings 51 52 # def set_heater_output(self, heater_number=1, heat_percent=0.0): 53 # try: 54 # # Setting heater output percentage according to the official driver methods 55 # heater_number = int(heater_number) 56 # if heater_number == 1: 57 # self.device.set_heater_output_percentage(heat_percent) 58 # elif heater_number == 2: 59 # self.device.set_analog_heater_output(heat_percent) 60 # return True 61 # except Exception as e: 62 # print(f"Error setting heater output on Lake Shore 372: {e}") 63 # return False 64 def get_sensor(self, channel): 65 try: 66 if channel == 'A': 67 temp = self.device.get_all_input_readings(channel)['resistance'] 68 else: 69 temp = self.device.get_all_input_readings(int(channel))['resistance'] 70 return temp 71 except Exception as e: 72 print( 73 f"Error reading temperature from Lake Shore 372 (Channel {channel}): {e}" 74 ) 75 return None 76 77 def list_channels(self): 78 """ 79 List available input and output channels on the Lake Shore 372. 80 81 Input channels are '1' - '16', or 'A'. 82 Output channels are '1' (Warm-up heater), '2' (Analog output). 83 """ 84 self.input_channels = [str(i) for i in range(1, 17)] + ['A'] 85 self.output_channels = ['sample_heater', 'still_heater'] 86 87 def sample_heater_output_percentage(self): 88 return float(self.device.query('HTR?')) 89 90 def still_heater_output_query(self): 91 return self.device.get_still_output() 92 93 def get_output(self, channel): 94 if channel is 'sample_heater': 95 return self.sample_heater_output_percentage() 96 elif channel is 'still_heater': 97 return self.still_heater_output_query() 98 99 def set_still_voltage(self, voltage_percentage): 100 self.device.set_still_output(voltage_percentage) 101 102 def set_MC_setpoint(self, setpoint): 103 self.device.set_setpoint_kelvin(0, setpoint)