Repository navigation
Expand file tree
/
Copy pathcontroller.py
More file actions
701 lines (571 loc) · 31.2 KB
/
Copy pathcontroller.py
File metadata and controls
701 lines (571 loc) · 31.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
import yaml
from typing import Optional, Dict, Any, Union, List
from .serial_client import SerialClient
from .drivers import TesController, LnaController, FluxRampController
class DeviceController:
"""High-level controller that encapsulates SerialClient, TesController and LnaController.
Usage:
# from file
ctrl = DeviceController.from_config('path/to/config.yaml')
# or construct directly
ctrl = DeviceController(port='/dev/ttyACM0', baud=115200, timeout=1.0, num_tes=6, num_lna=6)
The DeviceController exposes:
- client: SerialClient
- tes: TesController
- lna: LnaController
- num_tes, num_lna
Note: the underlying drivers are thin wrappers that send commands and parse YAML responses.
"""
def __init__(self, port: str = '/dev/ttyACM0', baud: int = 115200, timeout: float = 1.0,
num_tes: int = 6, num_lna: int = 6, auto_open: bool = True):
self.port = port
self.baud = baud
self.timeout = timeout
self.num_tes = num_tes
self.num_lna = num_lna
self.client = SerialClient(self.port, baud=self.baud, timeout=self.timeout)
if auto_open:
self.client.open()
# Create per-channel controller instances bound to their channel numbers.
# tes and lna are lists indexed by (channel-1).
self.tes: List[TesController] = [TesController(self.client, i + 1) for i in range(self.num_tes)]
self.lna: List[LnaController] = [LnaController(self.client, i + 1) for i in range(self.num_lna)]
# DAC controller (single instance, no channel binding)
self.dac = FluxRampController(self.client)
@classmethod
def from_config(cls, path: str, auto_open: bool = True) -> 'DeviceController':
"""Load controller config from a YAML file.
Expected keys: port, baud, timeout, num_tes, num_lna
"""
with open(path, 'r', encoding='utf-8') as f:
cfg = yaml.safe_load(f) or {}
port = cfg.get('port', '/dev/ttyACM0')
baud = cfg.get('baud', 115200)
timeout = cfg.get('timeout', 1.0)
num_tes = cfg.get('num_tes', 6)
num_lna = cfg.get('num_lna', 6)
return cls(port=port, baud=baud, timeout=timeout, num_tes=num_tes, num_lna=num_lna, auto_open=auto_open)
def close(self):
try:
self.client.close()
except Exception:
pass
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
self.close()
# ========== DAC Convenience Methods ==========
def flux_ramp_set(self, value: int) -> Dict[str, Any]:
"""Set DAC value (0-0xFFFF)."""
return self.dac.set_dac(value)
def flux_ramp_get(self) -> Dict[str, Any]:
"""Get current DAC value."""
return self.dac.get_dac()
# ========== TES Convenience Methods ==========
def tes_get_all(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get all TES channel data.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_all() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_all() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_all()
def tes_enable(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Enable TES channel(s).
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].enable() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].enable() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].enable()
def tes_disable(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Disable TES channel(s).
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].disable() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].disable() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].disable()
def tes_set_current(self,
channel: Union[int, List[int], None] = None,
current_mA: Union[float, List[float], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Set TES current in mA (0-20.0).
Args:
channel: int for single, list for multiple, None for all channels
current_mA: float for single value, list for multiple values
Examples:
tes_set_current(1, 5.0) # Set channel 1 to 5.0 mA
tes_set_current(current_mA=5.0) # Set all channels to 5.0 mA
tes_set_current(current_mA=[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]) # Set all channels to different values
tes_set_current([1, 3, 5], 5.0) # Set channels 1, 3, 5 to 5.0 mA
tes_set_current([1, 3, 5], [1.0, 2.0, 3.0]) # Set channels to different values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if current_mA is None:
raise ValueError("current_mA must be provided")
# Case 1: Single channel, single value
if isinstance(channel, int) and not isinstance(current_mA, list):
self._check_tes_channel(channel)
return self.tes[channel - 1].set_current(current_mA)
# Case 2: All channels, single value
if channel is None and not isinstance(current_mA, list):
return [self.tes[i].set_current(current_mA) for i in range(self.num_tes)]
# Case 3: All channels, array of values
if channel is None and isinstance(current_mA, list):
if len(current_mA) != self.num_tes:
raise ValueError(f"current_mA list length {len(current_mA)} must match num_tes {self.num_tes}")
return [self.tes[i].set_current(current_mA[i]) for i in range(self.num_tes)]
# Case 4: Array of channels, single value
if isinstance(channel, list) and not isinstance(current_mA, list):
return [self.tes[ch - 1].set_current(current_mA) for ch in channel]
# Case 5: Array of channels, array of values
if isinstance(channel, list) and isinstance(current_mA, list):
if len(channel) != len(current_mA):
raise ValueError(f"channel and current_mA lists must have same length")
return [self.tes[ch - 1].set_current(curr) for ch, curr in zip(channel, current_mA)]
raise ValueError("Invalid combination of channel and current_mA arguments")
def tes_inc_current(self,
channel: Union[int, List[int], None] = None,
delta: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Increment TES current by delta.
Args:
channel: int for single, list for multiple, None for all channels
delta: int for single value, list for multiple values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if delta is None:
raise ValueError("delta must be provided")
if isinstance(channel, int) and not isinstance(delta, list):
self._check_tes_channel(channel)
return self.tes[channel - 1].inc_current(delta)
if channel is None and not isinstance(delta, list):
return [self.tes[i].inc_current(delta) for i in range(self.num_tes)]
if channel is None and isinstance(delta, list):
if len(delta) != self.num_tes:
raise ValueError(f"delta list length {len(delta)} must match num_tes {self.num_tes}")
return [self.tes[i].inc_current(delta[i]) for i in range(self.num_tes)]
if isinstance(channel, list) and not isinstance(delta, list):
return [self.tes[ch - 1].inc_current(delta) for ch in channel]
if isinstance(channel, list) and isinstance(delta, list):
if len(channel) != len(delta):
raise ValueError(f"channel and delta lists must have same length")
return [self.tes[ch - 1].inc_current(d) for ch, d in zip(channel, delta)]
raise ValueError("Invalid combination of channel and delta arguments")
def tes_dec_current(self,
channel: Union[int, List[int], None] = None,
delta: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Decrement TES current by delta.
Args:
channel: int for single, list for multiple, None for all channels
delta: int for single value, list for multiple values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if delta is None:
raise ValueError("delta must be provided")
if isinstance(channel, int) and not isinstance(delta, list):
self._check_tes_channel(channel)
return self.tes[channel - 1].dec_current(delta)
if channel is None and not isinstance(delta, list):
return [self.tes[i].dec_current(delta) for i in range(self.num_tes)]
if channel is None and isinstance(delta, list):
if len(delta) != self.num_tes:
raise ValueError(f"delta list length {len(delta)} must match num_tes {self.num_tes}")
return [self.tes[i].dec_current(delta[i]) for i in range(self.num_tes)]
if isinstance(channel, list) and not isinstance(delta, list):
return [self.tes[ch - 1].dec_current(delta) for ch in channel]
if isinstance(channel, list) and isinstance(delta, list):
if len(channel) != len(delta):
raise ValueError(f"channel and delta lists must have same length")
return [self.tes[ch - 1].dec_current(d) for ch, d in zip(channel, delta)]
raise ValueError("Invalid combination of channel and delta arguments")
def tes_set_bits(self,
channel: Union[int, List[int], None] = None,
value: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Set TES DAC bits directly (0-0xFFFFF).
Args:
channel: int for single, list for multiple, None for all channels
value: int for single value, list for multiple values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if value is None:
raise ValueError("value must be provided")
if isinstance(channel, int) and not isinstance(value, list):
self._check_tes_channel(channel)
return self.tes[channel - 1].set_bits(value)
if channel is None and not isinstance(value, list):
return [self.tes[i].set_bits(value) for i in range(self.num_tes)]
if channel is None and isinstance(value, list):
if len(value) != self.num_tes:
raise ValueError(f"value list length {len(value)} must match num_tes {self.num_tes}")
return [self.tes[i].set_bits(value[i]) for i in range(self.num_tes)]
if isinstance(channel, list) and not isinstance(value, list):
return [self.tes[ch - 1].set_bits(value) for ch in channel]
if isinstance(channel, list) and isinstance(value, list):
if len(channel) != len(value):
raise ValueError(f"channel and value lists must have same length")
return [self.tes[ch - 1].set_bits(v) for ch, v in zip(channel, value)]
raise ValueError("Invalid combination of channel and value arguments")
def tes_get_bits(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get TES DAC bits.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_bits() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_bits() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_bits()
def tes_get_shunt(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get TES shunt voltage.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_shunt() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_shunt() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_shunt()
def tes_get_bus(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get TES bus voltage.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_bus() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_bus() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_bus()
def tes_get_current(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get TES current.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_current() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_current() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_current()
def tes_get_power(self, channel: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get TES power.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if channel is None:
return [self.tes[i].get_power() for i in range(self.num_tes)]
elif isinstance(channel, list):
return [self.tes[ch - 1].get_power() for ch in channel]
else:
self._check_tes_channel(channel)
return self.tes[channel - 1].get_power()
# ========== LNA Convenience Methods ==========
def lna_get_all(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get all LNA data for target (GATE or DRAIN).
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].get_all(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].get_all(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].get_all(target)
def lna_enable(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Enable LNA target (GATE or DRAIN).
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].enable(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].enable(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].enable(target)
def lna_disable(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Disable LNA target (GATE or DRAIN).
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].disable(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].disable(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].disable(target)
def lna_set_dac(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None,
value: Union[int, List[int], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Set LNA DAC value for target (0-0xFFFF).
Args:
channel: int for single, list for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
value: int for single value, list for multiple values
Examples:
lna_set_dac(1, 'GATE', 0x8000) # Set channel 1 gate to 0x8000
lna_set_dac(target='GATE', value=0x8000) # Set all channels gate to 0x8000
lna_set_dac(target='GATE', value=[0x1000, 0x2000, ...]) # Set all channels to different values
lna_set_dac([1, 3], 'GATE', 0x8000) # Set channels 1, 3 gate to 0x8000
lna_set_dac([1, 3], 'GATE', [0x1000, 0x2000]) # Set channels to different values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if value is None:
raise ValueError("value must be provided")
# Case 1: Single channel, single value
if isinstance(channel, int) and not isinstance(value, list):
self._check_lna_channel(channel)
return self.lna[channel - 1].set_dac(target, value)
# Case 2: All channels, single value
if channel is None and not isinstance(value, list):
return [self.lna[i].set_dac(target, value) for i in range(self.num_lna)]
# Case 3: All channels, array of values
if channel is None and isinstance(value, list):
if len(value) != self.num_lna:
raise ValueError(f"value list length {len(value)} must match num_lna {self.num_lna}")
return [self.lna[i].set_dac(target, value[i]) for i in range(self.num_lna)]
# Case 4: Array of channels, single value
if isinstance(channel, list) and not isinstance(value, list):
return [self.lna[ch - 1].set_dac(target, value) for ch in channel]
# Case 5: Array of channels, array of values
if isinstance(channel, list) and isinstance(value, list):
if len(channel) != len(value):
raise ValueError(f"channel and value lists must have same length")
return [self.lna[ch - 1].set_dac(target, v) for ch, v in zip(channel, value)]
raise ValueError("Invalid combination of channel and value arguments")
def lna_set_voltage(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None,
voltage_V: Union[float, List[float], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Set LNA voltage for target (0.0-5.0 V).
Args:
channel: int for single, list for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
voltage_V: float for single value, list for multiple values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if voltage_V is None:
raise ValueError("voltage_V must be provided")
# Case 1: Single channel, single value
if isinstance(channel, int) and not isinstance(voltage_V, list):
self._check_lna_channel(channel)
return self.lna[channel - 1].set_voltage(target, voltage_V)
# Case 2: All channels, single value
if channel is None and not isinstance(voltage_V, list):
return [self.lna[i].set_voltage(target, voltage_V) for i in range(self.num_lna)]
# Case 3: All channels, array of values
if channel is None and isinstance(voltage_V, list):
if len(voltage_V) != self.num_lna:
raise ValueError(f"voltage_V list length {len(voltage_V)} must match num_lna {self.num_lna}")
return [self.lna[i].set_voltage(target, voltage_V[i]) for i in range(self.num_lna)]
# Case 4: Array of channels, single value
if isinstance(channel, list) and not isinstance(voltage_V, list):
return [self.lna[ch - 1].set_voltage(target, voltage_V) for ch in channel]
# Case 5: Array of channels, array of values
if isinstance(channel, list) and isinstance(voltage_V, list):
if len(channel) != len(voltage_V):
raise ValueError(f"channel and voltage_V lists must have same length")
return [self.lna[ch - 1].set_voltage(target, v) for ch, v in zip(channel, voltage_V)]
raise ValueError("Invalid combination of channel and voltage_V arguments")
def lna_set_current(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None,
current_mA: Union[float, List[float], None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Set LNA current for target (0.0-64.0 mA).
Args:
channel: int for single, list for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
current_mA: float for single value, list for multiple values
Returns:
Single dict if setting one channel, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if current_mA is None:
raise ValueError("current_mA must be provided")
# Case 1: Single channel, single value
if isinstance(channel, int) and not isinstance(current_mA, list):
self._check_lna_channel(channel)
return self.lna[channel - 1].set_current(target, current_mA)
# Case 2: All channels, single value
if channel is None and not isinstance(current_mA, list):
return [self.lna[i].set_current(target, current_mA) for i in range(self.num_lna)]
# Case 3: All channels, array of values
if channel is None and isinstance(current_mA, list):
if len(current_mA) != self.num_lna:
raise ValueError(f"current_mA list length {len(current_mA)} must match num_lna {self.num_lna}")
return [self.lna[i].set_current(target, current_mA[i]) for i in range(self.num_lna)]
# Case 4: Array of channels, single value
if isinstance(channel, list) and not isinstance(current_mA, list):
return [self.lna[ch - 1].set_current(target, current_mA) for ch in channel]
# Case 5: Array of channels, array of values
if isinstance(channel, list) and isinstance(current_mA, list):
if len(channel) != len(current_mA):
raise ValueError(f"channel and current_mA lists must have same length")
return [self.lna[ch - 1].set_current(target, curr) for ch, curr in zip(channel, current_mA)]
raise ValueError("Invalid combination of channel and current_mA arguments")
def lna_get_shunt(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get LNA shunt voltage for target.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].get_shunt(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].get_shunt(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].get_shunt(target)
def lna_get_bus(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get LNA bus voltage for target.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].get_bus(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].get_bus(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].get_bus(target)
def lna_get_current(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get LNA current for target.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].get_current(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].get_current(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].get_current(target)
def lna_get_power(self,
channel: Union[int, List[int], None] = None,
target: Union[str, None] = None) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
"""Get LNA power for target.
Args:
channel: int for single channel, list of ints for multiple, None for all channels
target: 'GATE' or 'DRAIN' (required)
Returns:
Single dict if channel is int, list of dicts otherwise
"""
if target is None:
raise ValueError("target must be provided ('GATE' or 'DRAIN')")
if channel is None:
return [self.lna[i].get_power(target) for i in range(self.num_lna)]
elif isinstance(channel, list):
return [self.lna[ch - 1].get_power(target) for ch in channel]
else:
self._check_lna_channel(channel)
return self.lna[channel - 1].get_power(target)
# ========== Direct Controller Access ==========
def get_tes_controller(self, channel: int) -> TesController:
"""Return the TesController instance bound to the given channel."""
self._check_tes_channel(channel)
return self.tes[channel - 1]
def get_lna_controller(self, channel: int) -> LnaController:
"""Return the LnaController instance bound to the given channel."""
self._check_lna_channel(channel)
return self.lna[channel - 1]
def _check_tes_channel(self, channel: int) -> None:
"""Validate a TES channel is within configured bounds (1-based)."""
if not isinstance(channel, int):
raise TypeError(f"TES channel must be int, got {type(channel).__name__}")
if channel < 1 or channel > self.num_tes:
raise ValueError(f"TES channel {channel} out of range (1..{self.num_tes})")
def _check_lna_channel(self, channel: int) -> None:
"""Validate an LNA channel is within configured bounds (1-based)."""
if not isinstance(channel, int):
raise TypeError(f"LNA channel must be int, got {type(channel).__name__}")
if channel < 1 or channel > self.num_lna:
raise ValueError(f"LNA channel {channel} out of range (1..{self.num_lna})")