/ hardware_communication / lakeshore224device.py
lakeshore224device.py
1 from lakeshore.model_224 import Model224 2 3 4 class LakeShore224Device: 5 """ 6 Class to interact with the Lake Shore 224 Temperature Monitor using the official driver. 7 """ 8 9 def __init__(self, port, name = None): 10 try: 11 if Model224 is not None: 12 self.device = Model224(com_port=port) 13 else: 14 raise ImportError("Lake Shore Model224 driver not available.") 15 self.port = port 16 self.address = port # Added to store the address 17 self.input_channels = [] 18 self.list_channels() 19 self.name = name 20 print( 21 f"Connected to Lake Shore 224 on {port} with channels {self.input_channels}") 22 except Exception as e: 23 raise e 24 25 def get_input_channels(self): 26 return self.input_channels 27 28 def get_output_channels(self): 29 return [] # Lake Shore 224 has no output channels 30 31 def get_temperature(self, channel): 32 try: 33 temp = self.device.get_kelvin_reading(channel) 34 return temp 35 except Exception as e: 36 print( 37 f"Error reading temperature from Lake Shore 224 (Channel {channel}): {e}" 38 ) 39 return None 40 41 def read_all_channels(self): 42 readings = {} 43 for channel in self.input_channels: 44 temp = self.get_temperature(channel) 45 readings[channel] = temp 46 return readings 47 48 def list_channels(self): 49 """ 50 List available input channels on the Lake Shore 224. 51 52 Channel names are 'A', 'B', 'C1' - 'C5', 'D1' - 'D5'. 53 """ 54 self.input_channels = ['A', 'B'] + \ 55 [f'C{i}' for i in range(1, 6)] + [f'D{i}' for i in range(1, 6)]