15
15
16
16
FIXTURE_REBOOT_TIME = 2
17
17
FIXTURE_NUM_CHANNELS : Final [int ] = 8
18
+ FIXTURE_NUM_CHANNELS_96 : Final [int ] = 96
18
19
FIXTURE_BAUD_RATE : Final [int ] = 115200
19
20
FIXTURE_VERSION_REQUIRED = "1.0.0"
21
+ FIXTURE_VERSION_REQUIRED2 = "0.0.1"
20
22
21
23
FIXTURE_CMD_TERMINATOR = "\r \n "
22
24
FIXTURE_CMD_GET_VERSION = "VERSION"
23
25
FIXTURE_CMD_GET_ALL_PRESSURE = "GETPRESSURE:15"
26
+ FIXTURE_CMD_GET_ALL_PRESSURE_96 = "GETPRESSURE:255"
24
27
25
28
LOCATION_A1_LEFT = Point (x = 14.4 , y = 74.5 , z = 71.2 )
26
29
LOCATION_A1_RIGHT = LOCATION_A1_LEFT ._replace (x = 128 - 14.4 )
@@ -40,6 +43,11 @@ def connect(self) -> None:
40
43
"""Connect to the Mark10 Force Gauge."""
41
44
...
42
45
46
+ @abstractmethod
47
+ def connect_96 (self ) -> None :
48
+ """Connect to the Mark10 Force Gauge."""
49
+ ...
50
+
43
51
@abstractmethod
44
52
def disconnect (self ) -> None :
45
53
"""Disconnect from the Mark10 Force Gauge."""
@@ -54,6 +62,11 @@ def firmware_version(self) -> str:
54
62
def read_all_pressure_channel (self ) -> List [float ]:
55
63
"""Read all pressure channels on fixture in Pascals."""
56
64
...
65
+ @abstractmethod
66
+ def read_all_pressure_channel_96 (self ) -> List [float ]:
67
+ """Read all pressure channels on fixture in Pascals."""
68
+ ...
69
+
57
70
58
71
def position_in_slot (self , side : Literal ["left" , "right" ] = "left" ) -> Point :
59
72
"""Position in slot."""
@@ -101,6 +114,10 @@ def read_all_pressure_channel(self) -> List[float]:
101
114
"""Read Pressure for all channels."""
102
115
pressure = [random .uniform (2.5 , 2 ) for _ in range (FIXTURE_NUM_CHANNELS )]
103
116
return pressure
117
+ def read_all_pressure_channel_96 (self ) -> List [float ]:
118
+ """Read Pressure for all channels."""
119
+ pressure = [random .uniform (2.5 , 2 ) for _ in range (FIXTURE_NUM_CHANNELS_96 )]
120
+ return pressure
104
121
105
122
106
123
def connect_to_fixture (
@@ -136,6 +153,38 @@ def connect_to_fixture(
136
153
ui .print_info ("no fixture found returning simulator" )
137
154
return SimPressureFixture ()
138
155
156
+ def connect_to_fixture96 (
157
+ simulate : bool , side : str = "left" , autosearch : bool = True
158
+ ) -> PressureFixtureBase :
159
+ """Try to find and return an presure fixture, if not found return a simulator."""
160
+ ui .print_title ("Connecting to presure fixture" )
161
+ if not simulate :
162
+ if not autosearch :
163
+ port = list_ports_and_select (device_name = "Pressure fixture" )
164
+ fixture = PressureFixture .create (port = port , slot_side = side )
165
+ fixture .connect_96 ()
166
+ ui .print_info (f"Found fixture on port { port } " )
167
+ return fixture
168
+ else :
169
+ ports = comports ()
170
+ assert ports
171
+ for _port in ports :
172
+ port = _port .device # type: ignore[attr-defined]
173
+ try :
174
+ ui .print_info (
175
+ f"Trying to connect to Pressure fixture on port { port } "
176
+ )
177
+ fixture = PressureFixture .create (port = port , slot_side = side )
178
+ fixture .connect_96 ()
179
+ ui .print_info (f"Found fixture on port { port } " )
180
+ return fixture
181
+ except : # noqa: E722
182
+ pass
183
+ use_sim = ui .get_user_answer ("No pressure sensor found, use simulator?" )
184
+ if not use_sim :
185
+ raise SerialException ("No sensor found" )
186
+ ui .print_info ("no fixture found returning simulator" )
187
+ return SimPressureFixture ()
139
188
140
189
class PressureFixture (PressureFixtureBase ):
141
190
"""OT3 Pressure Fixture Driver."""
@@ -162,9 +211,22 @@ def connect(self) -> None:
162
211
# NOTE: device might take a few seconds to boot up
163
212
sleep (FIXTURE_REBOOT_TIME )
164
213
fw_version = self .firmware_version ()
214
+ print (f"unexpected pressure-fixture version: { fw_version } " )
165
215
assert (
166
216
fw_version == FIXTURE_VERSION_REQUIRED
167
217
), f"unexpected pressure-fixture version: { fw_version } "
218
+
219
+ def connect_96 (self ) -> None :
220
+ """Connect."""
221
+ self ._port .open ()
222
+ self ._port .flushInput ()
223
+ # NOTE: device might take a few seconds to boot up
224
+ sleep (FIXTURE_REBOOT_TIME )
225
+ fw_version = self .firmware_version ()
226
+ print (f"unexpected pressure-fixture version: { fw_version } " )
227
+ assert (
228
+ fw_version == FIXTURE_VERSION_REQUIRED2
229
+ ), f"unexpected pressure-fixture version: { fw_version } "
168
230
169
231
def disconnect (self ) -> None :
170
232
"""Disconnect."""
@@ -190,14 +252,57 @@ def read_all_pressure_channel(self) -> List[float]:
190
252
if self ._slot_side == "left" :
191
253
data .reverse () # reverse order, so pipette channel 1 is at index 0
192
254
return data
255
+
256
+ def read_all_pressure_channel_96 (self ) -> List [float ]:
257
+ """Reads from all the channels from the fixture."""
258
+ cmd_str = f"{ FIXTURE_CMD_GET_ALL_PRESSURE_96 } { FIXTURE_CMD_TERMINATOR } "
259
+ self ._port .write (cmd_str .encode ("utf-8" ))
260
+ response = self ._port .readlines ()#.decode("utf-8")
261
+ datalist = []
262
+ for res in response :
263
+ res_list = res .decode ("utf-8" ).split ("," )[:- 1 ] # ignore the last comma
264
+ data_str = [d .split ("=" )[- 1 ].strip () for d in res_list ] # remove PRESSURE=
265
+ # for i in range(len(data_str)): # replace all -0.00 with 0.00
266
+ # if data_str[i] == "-0.00":
267
+ # data_str[i] = "0.00"
268
+ data = [float (d ) for d in data_str ] # convert to float
269
+ data .reverse
270
+ #print("yuans",data)
271
+ # datalist.extend(data)
272
+ datalist = data + datalist
273
+ # if self._slot_side == "left":
274
+ # data.reverse() # reverse order, so pipette channel 1 is at index 0
275
+ #print("datalist",datalist)
276
+ #datalist.reverse()
277
+ return datalist
278
+ def print_pressure_datas (self ,data_list ):
279
+ row_labels = ['A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' ]
280
+ col_labels = list (range (1 , 13 ))
281
+ cell_width = 9
282
+
283
+ # 打印表头
284
+ print (" " * 3 + "" .join (f"{ col :>{cell_width }} " for col in col_labels ))
285
+
286
+ # 打印每一行
287
+ for i in range (8 ):
288
+ row_data = data_list [i * 12 :(i + 1 ) * 12 ]
289
+ row_str = f"{ row_labels [i ]} : "
290
+ for val in row_data :
291
+ try :
292
+ row_str += f"{ float (val ):>{cell_width }.2f} "
293
+ except :
294
+ row_str += f"{ str (val ):>{cell_width }} "
295
+ print (row_str )
193
296
194
297
195
298
if __name__ == "__main__" :
196
- port_name = input ("type the port of the device (eg: COM1): " )
299
+ port_name = list_ports_and_select (device_name = "Pressure fixture" )
300
+ #port_name = input("type the port of the device (eg: COM1): ")
197
301
fixture = PressureFixture .create (port = port_name , slot_side = "left" )
198
- fixture .connect ()
302
+ fixture .connect_96 ()
199
303
print (f"Device firmware version: { fixture .firmware_version ()} " )
200
304
while True :
201
- readings = fixture .read_all_pressure_channel ()
202
- print (readings )
305
+ readings = fixture .read_all_pressure_channel_96 ()
306
+ print ("zuihoujieguo:" ,readings )
307
+ fixture .print_pressure_datas (readings )
203
308
sleep (0.1 )
0 commit comments