-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBurnIn_Worker.py
More file actions
1703 lines (1495 loc) · 86.6 KB
/
Copy pathBurnIn_Worker.py
File metadata and controls
1703 lines (1495 loc) · 86.6 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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys, os
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal
import time
from datetime import datetime,timedelta
import subprocess
from __Constant import *
import json
import math
def computeTempFromTargetRH(dewPoint: float, targetRH: float = 0.10) -> float:
"""
Calculates the temperature required to achieve a specific target relative humidity
for a given dew point using the Magnus-Tetens formula.
:param dewPoint: The current dew point temperature in Celsius.
:param targetRH: The desired relative humidity percentage (e.g., 10.0 for 10%).
:return: The calculated temperature in Celsius.
"""
# Safeguard against mathematically invalid relative humidity inputs
if targetRH <= 0 or targetRH > 100:
raise ValueError("Target relative humidity must be between 0% (exclusive) and 100% (inclusive).")
# Magnus-Tetens constants for water vapor
a = 17.625
b = 243.04
# Saturated vapor pressure parameter at the dew point
alpha_dp = (a * dewPoint) / (b + dewPoint)
# Rearranged equation variable
K = alpha_dp - math.log(targetRH)
# Solve for the target temperature
targetTemp = (K * b) / (a - K)
return targetTemp
## Class implementation for the Worker module of the GUI controller.
#
# The worker is a inheriting from pyQt library in order to create assign slots and signals
class BurnIn_Worker(QObject):
Request_msg = pyqtSignal(str,str)
Request_confirm_sig = pyqtSignal(str)
Request_input_dsb = pyqtSignal(str,float,float,float)
BI_terminated = pyqtSignal()
BI_Update_GUI_sig = pyqtSignal(dict)
BI_CheckID_isOK_sig = pyqtSignal(int,int)
BI_Clear_Monitor_sig = pyqtSignal()
BI_Update_PowerStatus_sig = pyqtSignal(int,bool,str)
## Init function.
def __init__(self,configDict,logger, SharedDict, Julabo, FNALBox, CAENController, DB_interface):
super(BurnIn_Worker,self).__init__();
self.configDict=configDict
self.logger = logger
self.Julabo = Julabo
self.FNALBox = FNALBox
self.DB_interface = DB_interface
self.CAENController = CAENController
self.SharedDict = SharedDict
self.BIcwd = configDict.get(("BITest","cwd"),"NOKEY")
if self.BIcwd == "NOKEY":
self.BIcwd = "/home/thermal/BurnIn_moduleTest"
self.logger.warning("cwd directory parameter not found. Using default")
self.Ph2_ACF_version = configDict.get(("BITest","version"),"NOKEY")
if self.Ph2_ACF_version == "NOKEY":
self.Ph2_ACF_version = "latest"
self.logger.warning("Ph2_ACF_version parameter not found. Using latest")
self.IV_scanType = configDict.get(("IVScan","scanType"),"NOKEY")
if self.IV_scanType == "NOKEY":
self.IV_scanType = "before_encapsulation"
self.logger.warning("IV_scanType parameter not found. Using before_encapsulation")
self.IV_delay = configDict.get(("IVScan","delay"),"NOKEY")
if self.IV_delay == "NOKEY":
self.IV_delay = "5.0"
self.logger.warning("IV_delay parameter not found. Using 5.0")
self.IV_settlingTime = configDict.get(("IVScan","settlingTime"),"NOKEY")
if self.IV_settlingTime == "NOKEY":
self.IV_settlingTime = "0.5"
self.logger.warning("IV_settlingTime parameter not found. Using 0.5")
self.logger.info("Worker class initialized")
self.last_op_ok= True
#################################################################
## Basic functions. directly called from "Test Operation tab"
#################################################################
## Function to send a cmd string to the Julabo interface
# implemented as a is a Pyqt slot
# NOT executed if:
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: none
@pyqtSlot(str)
def SendJulaboCmd(self,cmd):
self.Julabo.lock.acquire()
self.logger.info("Sending Julabo cmd "+cmd)
if not self.Julabo.is_connected :
self.Julabo.connect()
if self.Julabo.is_connected :
self.Julabo.sendTCP(cmd)
self.logger.info(self.Julabo.receive())
else:
self.last_op_ok= False
self.Julabo.lock.release()
## Function to send a cmd string to the CAEN controller interface
# implemented as a is a Pyqt slot
# NOT executed if:
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: none
@pyqtSlot(str)
def SendCAENControllerCmd(self,cmd):
self.CAENController.lock.acquire()
self.logger.info("Sending CAENController cmd "+cmd)
if not self.CAENController.is_connected :
self.CAENController.connect()
if self.CAENController.is_connected :
self.CAENController.sendTCP(cmd)
time.sleep(CAEN_SLEEP_AFTER_TCP)
self.logger.info(self.CAENController.receive())
self.CAENController.close()
else:
self.last_op_ok= False
self.CAENController.lock.release()
## Function to send a cmd string to the Julabo interface
# implemented as a is a Pyqt slot
# NOT executed if:
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: none
@pyqtSlot(str)
def SendFNALBoxCmd(self,cmd):
self.logger.info("WORKER: Requesting lock on FNALBox")
self.FNALBox.lock.acquire()
self.logger.info("Sending FNALBox cmd "+cmd)
if not self.FNALBox.is_connected :
self.FNALBox.connect()
if self.FNALBox.is_connected :
self.FNALBox.sendTCP(cmd)
time.sleep(FNAL_SLEEP_AFTER_TCP)
self.logger.info(self.FNALBox.receive())
else:
self.last_op_ok= False
self.FNALBox.lock.release()
self.logger.info("WORKER: lock on FNALBox released")
## Function to start a test
# implemented as a is a Pyqt slot
@pyqtSlot(str)
def SendModuleTestCmd(self,cmd):
self.logger.info("Starting custom shell command...")
cmdSplit = cmd.split()
try:
proc = subprocess.Popen(cmdSplit, cwd=self.BIcwd,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(proc.returncode==None):
try:
outs, errs = proc.communicate(timeout=TEST_PROCESS_SLEEP)
self.logger.info("Custom command output: "+outs.decode())
#self.logger.error("BI TEST SUBPROCESS: "+errs.decode())
break
except subprocess.TimeoutExpired:
self.logger.info("WORKER: Waiting command completion....")
if proc.returncode ==0:
self.logger.info("Command executed with return code "+str(proc.returncode))
elif proc.returncode==None:
self.logger.info("Command executed with return code NONE")
else:
self.logger.error("Command failed with return code "+str(proc.returncode))
except Exception as e:
self.logger.error("Erro while executing custom command")
self.logger.error(e)
###########################################################################
## Safe operation functions. Directly called from "Manual Operation tab"
###########################################################################
## Function to select the SetPoint of the Julabo
# implemented as a is a Pyqt slot
# NOT Executed if:
# - JULABO and FNAL info are not updated
# - JULABO is ON and the selected setpoint has a target temperature below the DewPoint
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: read back from instrument
@pyqtSlot(int)
def Ctrl_SelSp_Cmd(self,Sp_id, PopUp=True):
self.last_op_ok= True
self.logger.info("WORKER: Selecting JULABO Sp"+str(Sp_id+1))
if not (self.SharedDict["Julabo_updated"] and self.SharedDict["FNALBox_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "Julabo and/or FNAL box info are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (self.SharedDict["Ctrl_StatusJulabo"].text().find("START") != -1):
targetT = -100.0
if Sp_id == 0 :
targetT = float(self.SharedDict["Ctrl_Sp1"].text())
if targetT < float(self.SharedDict["Ctrl_IntDewPoint"].text()):
Warning_str = "Operation can't be performed"
Reason_str = "Set point is configured with a temperature below internal dew point"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.Julabo.lock.acquire()
self.logger.debug("WORKER: Sending Julabo cmd" )
if not self.Julabo.is_connected :
self.Julabo.connect()
if self.Julabo.is_connected :
try:
self.Julabo.sendTCP("out_mode_01 "+str(Sp_id))
self.logger.info("WORKER: JULABO cmd sent")
self.Julabo.sendTCP("in_mode_01")
reply = self.Julabo.receive()
if (reply != "None" and reply != "TCP error"):
Sp = str(int(reply.replace(" ", ""))+1)
self.SharedDict["Ctrl_TSp"].setText(Sp)
if self.SharedDict["Ctrl_TSp"].text()[:1]=="1":
self.SharedDict["Ctrl_TargetTemp"].setText(self.SharedDict["Ctrl_Sp1"].text())
except Exception as e:
self.logger.error(e)
self.last_op_ok= False
else:
Warning_str = "Operation can't be performed"
Reason_str = "Can't connect to JULABO"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
self.Julabo.lock.release()
## Function to select the target temperature of a JULABO SetPoint
# implemented as a is a Pyqt slot
# NOT Executed if:
# - JULABO and FNAL info are not updated
# - JULABO is ON and the selected setpoint has a target temperature below the DewPoint
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: read back from instrument
@pyqtSlot(int,float)
def Ctrl_SetSp_Cmd(self,Sp_id,value, PopUp=True):
self.last_op_ok= True
self.logger.info("WORKER: Setting JULABO Sp"+str(Sp_id+1)+ " to " +str(value))
if not (self.SharedDict["Julabo_updated"] and self.SharedDict["FNALBox_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "Julabo and/or FNAL box info are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (self.SharedDict["Ctrl_StatusJulabo"].text().find("START") != -1):
Sp_actual = int(self.SharedDict["Ctrl_TSp"].text())-1
if Sp_actual==Sp_id and value < float(self.SharedDict["Ctrl_IntDewPoint"].text()):
Warning_str = "Operation can't be performed"
Reason_str = "Attempting to set target temperature of the active set point below internal dew point"
self.logger.warning(Warning_str)
self.logger.warning(Reason_str)
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.Julabo.lock.acquire()
self.logger.debug("WORKER: Sending Julabo cmd" )
if not self.Julabo.is_connected :
self.Julabo.connect()
if self.Julabo.is_connected :
try:
self.Julabo.sendTCP("out_sp_0"+str(Sp_id)+" "+str(value))
self.logger.info("WORKER: JULABO cmd sent")
self.Julabo.sendTCP("in_sp_0"+str(Sp_id))
reply = self.Julabo.receive()
if (reply != "None" and reply != "TCP error"):
self.SharedDict["Ctrl_Sp"+str(Sp_id+1)].setText(reply.replace(" ", ""))
if self.SharedDict["Ctrl_TSp"].text()[:1]=="1":
self.SharedDict["Ctrl_TargetTemp"].setText(self.SharedDict["Ctrl_Sp1"].text())
except Exception as e:
self.logger.error(e)
self.last_op_ok= False
else:
Warning_str = "Operation can't be performed"
Reason_str = "Can't connect to JULABO"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
self.Julabo.lock.release()
## Function to power ON/OFF the JULABO
# implemented as a is a Pyqt slot
# NOT Executed if:
# - POWERING ON with JULABO and FNAL info are not updated
# - POWERING ON with target temp below DewPoint
# - POWERING ON with door not locked
# - POWERING ON with door not closed
# - POWERING OFF with LV ON
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: read back from instrument
@pyqtSlot(bool)
def Ctrl_PowerJulabo_Cmd(self,switch, PopUp=True):
self.last_op_ok= True
if not switch: # power off
self.logger.info("WORKER: Powering Julabo OFF")
if self.SharedDict["LV_on"]:
Warning_str = "Operation can't be performed"
Reason_str = "At least one LV channel status is ON"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.Julabo.lock.acquire()
self.logger.debug("WORKER: Sending Julabo cmd" )
if not self.Julabo.is_connected :
self.Julabo.connect()
if self.Julabo.is_connected :
try:
self.Julabo.sendTCP("out_mode_05 0")
self.logger.info("WORKER: JULABO cmd sent")
self.Julabo.sendTCP("status")
reply = self.Julabo.receive()
if (reply != "None" and reply != "TCP error"):
self.SharedDict["Ctrl_StatusJulabo"].setText(reply)
if self.SharedDict["Ctrl_StatusJulabo"].text().find("START")!=-1:
self.SharedDict["Ctrl_StatusJulabo"].setStyleSheet("color: rgb(0, 170, 0);font: 9pt ");
else:
self.SharedDict["Ctrl_StatusJulabo"].setStyleSheet("color: rgb(255, 0, 0);font: 9pt ");
except Exception as e:
self.logger.error(e)
self.last_op_ok= False
self.Julabo.lock.release()
else:
self.logger.info("WORKER: Powering Julabo ON")
if not (self.SharedDict["Julabo_updated"] and self.SharedDict["FNALBox_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "Julabo and/or FNAL box info are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if float(self.SharedDict["Ctrl_TargetTemp"].text())< float(self.SharedDict["Ctrl_IntDewPoint"].text()):
Warning_str = "Operation can't be performed"
Reason_str = "Attempting to start unit with target temperature below internal dew point"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if self.SharedDict["Ctrl_StatusLock"].text() != "LOCKED":
Warning_str = "Operation can't be performed"
Reason_str = "Attempting to start unit with door magnet not locked"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if not (self.SharedDict["Ctrl_StatusDoor"].text() == "CLOSED"):
Warning_str = "Operation can't be performed"
Reason_str = "BurnIn door is NOT CLOSED"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.Julabo.lock.acquire()
self.logger.debug("WORKER: Sending Julabo cmd" )
if not self.Julabo.is_connected :
self.Julabo.connect()
if self.Julabo.is_connected :
try:
self.Julabo.sendTCP("out_mode_05 1")
self.logger.info("WORKER: JULABO cmd sent")
self.Julabo.sendTCP("status")
reply = self.Julabo.receive()
if (reply != "None" and reply != "TCP error"):
self.SharedDict["Ctrl_StatusJulabo"].setText(reply)
if self.SharedDict["Ctrl_StatusJulabo"].text().find("START")!=-1:
self.SharedDict["Ctrl_StatusJulabo"].setStyleSheet("color: rgb(0, 170, 0);font: 9pt ");
else:
self.SharedDict["Ctrl_StatusJulabo"].setStyleSheet("color: rgb(255, 0, 0);font: 9pt ");
except Exception as e:
self.logger.error(e)
self.last_op_ok= False
else:
Warning_str = "Operation can't be performed"
Reason_str = "Can't connect to JULABO"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
self.Julabo.lock.release()
## Function to lock/unlock the door (magnet)
# implemented as a is a Pyqt slot
# NOT Executed if:
# - UNLOCK with JULABO/FNAL/M5 info not updated
# - UNLOCK with minimal internal temp below EXTERNAL DewPoint
# - UNLOCK with JULABO ON and taget temp below external dewpoint
# - status of at least one defined HV channels is ON or UNKNOWN
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: reply check from FNAL Box
@pyqtSlot(bool)
def Ctrl_SetLock_Cmd(self,switch, PopUp=True):
self.last_op_ok= True
lock = "LOCKED" if switch else "UNLOCK"
cmd = "[5011]" if switch else "[5010]"
self.logger.info("WORKER: Setting door magnet to: "+lock)
if (not switch):
if not (self.SharedDict["Julabo_updated"] and self.SharedDict["FNALBox_updated"] and self.SharedDict["M5_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "Julabo, FNAL box or M5 infos are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (self.SharedDict["Ctrl_StatusJulabo"].text().find("START")!=-1) and (float(self.SharedDict["Ctrl_TargetTemp"].text()) < float(self.SharedDict["Ctrl_ExtDewPoint"].text())):
Warning_str = "Operation can't be performed"
Reason_str = "JULABO is ON with target temp below external dew point"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if self.SharedDict["Ctrl_LowerTemp"] < float(self.SharedDict["Ctrl_ExtDewPoint"].text()):
Warning_str = "Operation can't be performed"
Reason_str = "Internal minimum temperature below external dew point. Retry later"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if self.SharedDict["HV_on"]:
Warning_str = "Operation can't be performed"
Reason_str = "At least one HV channel status is ON"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.FNALBox.lock.acquire()
self.logger.debug("WORKER: Sending FNAL Box cmd" )
if not self.FNALBox.is_connected :
self.FNALBox.connect()
if self.FNALBox.is_connected :
try:
self.FNALBox.sendTCP(cmd)
self.logger.info("WORKER: FNAL Box cmd sent: " + cmd)
time.sleep(FNAL_SLEEP_AFTER_TCP)
reply = self.FNALBox.receive()
if reply[-3:]=="[*]":
self.SharedDict["Ctrl_StatusLock"].setText(lock)
self.logger.info("WORKER: Done")
else:
self.SharedDict["Ctrl_StatusLock"].setText("?")
self.logger.error("WORKER: uncorrect reply from FNAL Box: "+reply)
self.last_op_ok= False
except Exception as e:
self.logger.error(e)
self.SharedDict["Ctrl_StatusLock"].setText("?")
self.last_op_ok= False
else:
Warning_str = "Operation can't be performed"
Reason_str = "Can't connect to FNAL box"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
self.FNALBox.lock.release()
## Function to select LOW/HIGH dry air flow
# implemented as a is a Pyqt slot
# NOT Executed if:
# - TCP socket is not connected and connection attempt fails
# Control on cmd execution: reply check from FNAL Box
@pyqtSlot(bool)
def Ctrl_SetHighFlow_Cmd(self,switch, PopUp=True):
self.last_op_ok= True
flow = "HIGH" if switch else "LOW"
cmd = "[5021]" if switch else "[5020]"
self.logger.info("WORKER: Switching dry air flow to "+flow)
self.FNALBox.lock.acquire()
self.logger.debug("WORKER: Sending FNAL Box cmd" )
if not self.FNALBox.is_connected :
self.FNALBox.connect()
if self.FNALBox.is_connected :
try:
self.FNALBox.sendTCP(cmd)
self.logger.info("WORKER: FNAL Box cmd sent: " + cmd)
time.sleep(FNAL_SLEEP_AFTER_TCP)
reply = self.FNALBox.receive()
if reply[-3:]=="[*]":
self.SharedDict["Ctrl_StatusFlow"].setText(flow)
self.logger.info("WORKER: Done")
else:
self.SharedDict["Ctrl_StatusFlow"].setText("?")
self.logger.error("WORKER: uncorrect reply from FNAL Box: "+reply)
self.last_op_ok= False
except Exception as e:
self.logger.error(e)
self.SharedDict["Ctrl_StatusFlow"].setText("?")
self.last_op_ok= False
else:
Warning_str = "Operation can't be performed"
Reason_str = "Can't connect to FNAL box"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
self.FNALBox.lock.release()
## Function to power ON/OFF individual LV channels
# implemented as a is a Pyqt slot
# NOT Executed if:
# - CAEN INFO are not updated
# - POWER ON with JULABO OFF
# - one of the slots selected by the user does not have a defined LV channel
# - trying to switch off a slot with HV ON
# - trying to switch off a slot with HV OFF but unknown/too high voltage
# Control on cmd execution: none
@pyqtSlot(bool)
def Ctrl_PowerLV_Cmd(self,switch,Channel_list=[], PopUp=True):
self.last_op_ok= True
if PopUp:
Channel_list.clear()
power = "On" if switch else "Off"
if not (self.SharedDict["CAEN_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "CAEN infos are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if switch and self.SharedDict["Ctrl_StatusJulabo"].text().find("START")==-1:
Warning_str = "Operation can't be performed"
Reason_str = "JULABO is not ON"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if len(Channel_list)==0:
for row in range(NUM_BI_SLOTS):
if self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_NAME_COL).isSelected():
ch_name = self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_NAME_COL).text()
if (ch_name == "?"):
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF LV for slot "+str(row+1)+ " beacause LV ch. name is UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
HV_defined = True if self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_NAME_COL).text() != "?" else False
if (not switch) and HV_defined and (self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_STAT_COL).text() != "OFF"): # attempt to power down LV with HV not off
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF LV for slot "+str(row+1)+ " beacause HV is ON or UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
try:
HV_value = float(self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_VREAD_COL).text())
except Exception as e:
self.logger.error(e)
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF LV for slot "+str(row+1)+ " beacause HV value is invalid"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (not switch) and HV_defined and (self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_STAT_COL).text() != "OFF"): # attempt to power down LV with HV not off
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF LV for slot "+str(row+1)+ " beacause HV is ON or UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (not switch) and HV_value > HV_ON_THR : # attempt to power down LV with HV not zero (i.e. still ramping down)
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF LV for slot "+str(row+1)+ " beacause HV value still too high"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
Channel_list.append(ch_name)
self.BI_Update_PowerStatus_sig.emit(row,True,power)#isLV=True means LV
print("Updating", row, power)
self.logger.info("WORKER: Setting LV "+power+ " for ch " +str(Channel_list))
for channel in Channel_list:
self.SendCAENControllerCmd("Turn"+power+",PowerSupplyId:caen,ChannelId:"+channel)
## Function to power ON/OFF individual HV channels
# implemented as a is a Pyqt slot
# NOT Executed if:
# - CAEN INFO are not updated
# - POWER ON with door not CLOSED
# - one of the slots selected by the user does not have a defined HV channel
# - trying to switch on a slot with LV OFF
# Control on cmd execution: none
@pyqtSlot(bool)
def Ctrl_PowerHV_Cmd(self,switch,Channel_list=[],PopUp=True):
self.last_op_ok= True
if PopUp:
Channel_list.clear()
power = "On" if switch else "Off"
if not (self.SharedDict["CAEN_updated"] and self.SharedDict["FNALBox_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "CAEN and/or FNAL infos are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if switch and (not (self.SharedDict["Ctrl_StatusDoor"].text() == "CLOSED")):
Warning_str = "Operation can't be performed"
Reason_str = "BurnIn door is NOT CLOSED"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if len(Channel_list)==0:
for row in range(NUM_BI_SLOTS):
if self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_NAME_COL).isSelected():
ch_name = self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_NAME_COL).text()
if (ch_name == "?"):
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF HV for slot "+str(row+1)+ " beacause HV ch. name is UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (switch) and (self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_STAT_COL).text() != "ON"): # attempt to power up HV with LV not on
Warning_str = "Operation can't be performed"
Reason_str = "Can't turn OFF HV for slot "+str(row+1)+ " beacause LV is OFF or UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
Channel_list.append(ch_name)
self.BI_Update_PowerStatus_sig.emit(row,False,power)#isLV=False means HV
self.logger.info("WORKER: Setting HV "+power+ " for ch " +str(Channel_list))
for channel in Channel_list:
self.SendCAENControllerCmd("Turn"+power+",PowerSupplyId:caen,ChannelId:"+channel)
## Function to set indicidual LV/HV channels
# implemented as a is a Pyqt slot
# NOT Executed if:
# - CAEN INFO are not updated
# - POWER ON with door not CLOSED
# - one of the slots selected by the user does not have a defined LV/HV setpoint
# Control on cmd execution: none
@pyqtSlot(str)
def Ctrl_VSet_Cmd(self,VType,Channel_list=[],NewValue_list=[], PopUp=True):
self.last_op_ok= True
if PopUp:
Channel_list.clear()
NewValue_list.clear()
if VType != "LV" and VType != "HV":
self.logger.error("WORKER: Received unknow Voltage type string ")
return
ColOffset = CTRLTABLE_LV_NAME_COL if VType=="LV" else CTRLTABLE_HV_NAME_COL;
if not (self.SharedDict["CAEN_updated"]):
Warning_str = "Operation can't be performed"
Reason_str = "CAEN infos are not updated"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if len(Channel_list) != len(NewValue_list):
Warning_str = "Operation can't be performed"
Reason_str = "Provided ch list and value list doesn not match in length"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if len(Channel_list)==0:
for row in range(NUM_BI_SLOTS):
if self.SharedDict["CAEN_table"].item(row,ColOffset).isSelected():
ch_name = self.SharedDict["CAEN_table"].item(row,ColOffset).text()
if (ch_name == "?"):
Warning_str = "Operation can't be performed"
Reason_str = "Can't set LV for slot "+str(row+1)+ " beacause LV ch. name is UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
if (self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_VSET_COL+ColOffset).text() == "?"):
Warning_str = "Operation can't be performed"
Reason_str = "Can't set LV/HV for slot "+str(row+1)+ " beacause current setpoint is UNKNOWN"
if PopUp:
self.Request_msg.emit(Warning_str,Reason_str)
self.last_op_ok= False
return
self.SharedDict["WaitInput"]=True
Request_str="New " +VType+ " Slot "+str(row+1)
ValueNow = 0.0
try :
ValueNow = float(self.SharedDict["CAEN_table"].item(row,2+ColOffset).text())
except Exception as e:
self.logger.error(e)
if VType == "LV":
self.Request_input_dsb.emit(Request_str,ValueNow,MIN_LV,MAX_HV)
else:
self.Request_input_dsb.emit(Request_str,ValueNow,MIN_HV,MAX_HV)
while self.SharedDict["WaitInput"]:
time.sleep(0.1)
if self.SharedDict["Input"]!=-1:
NewValue_list.append(self.SharedDict["Input"])
Channel_list.append(ch_name)
self.logger.info("WORKER: Setting LV for ch " +str(Channel_list))
self.logger.info("WORKER: New values: " +str(NewValue_list))
for idx,channel in enumerate(Channel_list):
self.SendCAENControllerCmd("SetVoltage,PowerSupplyId:caen,ChannelId:"+channel+",Voltage:"+str(NewValue_list[idx]))
###########################################################################
## BI main function and related
###########################################################################
#Check IDs failure
def BI_CheckIDs_failed_terminate(self, Reason_str):
self.logger.error("WORKER: Check IDs procedure failed. "+Reason_str)
self.SharedDict["BI_Status"].setText("Failed CheckIDs")
self.SharedDict["BI_Action"].setText("None")
self.BI_terminated.emit()
return False
## CheckIDs function
# implemented as a Pyqt slot
@pyqtSlot()
def BI_CheckIDs_Cmd(self):
self.SharedDict["BI_Status"].setText("CheckIDs Setup")
self.SharedDict["BI_Action"].setText("Setup")
session_dict={}
session_dict["ActiveSlots"] = self.SharedDict["BI_ActiveSlots"]
session_dict["ModuleIDs"] = self.SharedDict["BI_ModuleIDs"]
session_dict["fc7ID"] = "fc7ot2"
session_dict["Current_ModuleID"] = "unknown"
session_dict["fc7Slot"] = "0"
session_dict["TestType"] = "readOnlyID"
#checking sub-system information
if not (self.SharedDict["CAEN_updated"] and self.SharedDict["FNALBox_updated"] and self.SharedDict["Julabo_updated"]):
return self.BI_CheckIDs_failed_terminate("JULABO/CAEN/FNAL info are not updated.")
if not (self.SharedDict["Ctrl_StatusDoor"].text() == "CLOSED"):
return self.BI_CheckIDs_failed_terminate("Door is not closed.")
self.logger.info("BurnIn CheckIDs started...")
#selecting slots under test : LV/HV names defined && slot marked as active in BI tab
LV_Channel_list=[]
HV_Channel_list=[]
Slot_list=[]
for row in range(NUM_BI_SLOTS):
LV_ch_name = self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_NAME_COL).text()
HV_ch_name = self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_NAME_COL).text()
if (LV_ch_name != "?" and HV_ch_name != "?" and session_dict["ActiveSlots"][row]):
LV_Channel_list.append(LV_ch_name)
HV_Channel_list.append(HV_ch_name)
Slot_list.append(row)
if len(Slot_list)==0:
return self.BI_CheckIDs_failed_terminate("Please enable at least one slot.")
self.logger.info("BurnIn CheckIDs active slots: "+str(Slot_list))
self.logger.info("BurnIn CheckIDs HV names: "+str(HV_Channel_list))
self.logger.info("BurnIn CheckIDs LV names: "+str(LV_Channel_list))
PopUp=False
#lock magnet
self.Ctrl_SetLock_Cmd(True,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Failed to lock door.")
#sel SP
self.Ctrl_SelSp_Cmd(0,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't select Julabo SP.")
#put JULABO to 20 degree
self.Ctrl_SetSp_Cmd(0,20.,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't set Julabo temperature.")
#start JULABO
self.Ctrl_PowerJulabo_Cmd(True,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't power ON Julabo.")
##start LV
self.SharedDict["BI_Action"].setText("Start LVs")
self.BI_Update_PowerStatus_sig.emit(-2,True,"ON_dummy")#isLV=True means LV,slot=-2 means all, but command only started
self.Ctrl_PowerLV_Cmd(True,LV_Channel_list,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't start LVs.")
#wait a bit then check all LVs are ON
time.sleep(BI_SLEEP_AFTER_LVSET)
for row in Slot_list:
if(self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_STAT_COL).text()!="ON"):
return self.BI_CheckIDs_failed_terminate("LVs check failed.")
self.BI_Update_PowerStatus_sig.emit(-1,True,"ON_dummy")#isLV=True means LV,slot=-1 means all, update GUI-side
#Do *not* turn on HVs
##checking IDS
self.SharedDict["BI_Status"].setText("CheckingIDs")
self.SharedDict["BI_Action"].setText("Testing")
for slot in Slot_list:
self.SharedDict["BI_SUT"].setText(str(slot+1))
session_dict["fc7ID"]=self.SharedDict["BI_fc7IDs"][slot]
session_dict["fc7Slot"]=self.SharedDict["BI_fc7Slots"][slot]
session_dict["Current_ModuleID"] = self.SharedDict["BI_ModuleIDs"][slot]
self.logger.info("BI: Checking ID for BI slot "+str(slot)+": module name "+session_dict["Current_ModuleID"]+", fc7 slot "+session_dict["fc7Slot"]+",board "+session_dict["fc7ID"])
self.BI_CheckID_isOK_sig.emit(slot,0)#0 means we just started testing
self.BI_StartTest_Cmd(session_dict)
if not self.last_op_ok:
self.SharedDict["BI_Status"].setText("Failed CheckIDs")
#let's comment these for now and continue testing even if the label is wrong
#self.SharedDict["BI_Action"].setText("None")
#self.SharedDict["BI_SUT"].setText("None")
self.logger.error("WORKER: Check IDs procedure failed. Error returned while checking slot "+str(slot+1))
self.BI_CheckID_isOK_sig.emit(slot,2)#2 means failure
#self.BI_terminated.emit()
#return
else:
self.BI_CheckID_isOK_sig.emit(slot,1)#1 means success
self.SharedDict["BI_SUT"].setText("None")
self.SharedDict["BI_Status"].setText("CheckIDs stopping")
#verify that HVs are off before turning off LVs
found_HV_ON = False
for row in Slot_list:
if(self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_STAT_COL).text()!="OFF"):
found_HV_ON = True
self.logger.info("WORKER: Slot " + " HV is on after CheckID for some reason. Turning off.")
if found_HV_ON:
self.BI_Update_PowerStatus_sig.emit(-2,False,"OFF_dummy")#isLV=False means HV,slot=-2 means all, but command only started
self.SharedDict["BI_Action"].setText("Stop HVs")
self.Ctrl_PowerHV_Cmd(False,HV_Channel_list,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't stop HVs.")
time.sleep(BI_SLEEP_AFTER_HVSET)
#check HV stop
for row in Slot_list:
if(self.SharedDict["CAEN_table"].item(row,CTRLTABLE_HV_STAT_COL).text()!="OFF"):
return self.BI_CheckIDs_failed_terminate("Found HVs ON after CheckID and failed to turn them off.")
self.BI_Update_PowerStatus_sig.emit(-1,False,"OFF_dummy")#isLV=False means HV,slot=-1 means all, but command only started
#stop LV
self.SharedDict["BI_Action"].setText("Stop LVs")
self.BI_Update_PowerStatus_sig.emit(-2,True,"OFF_dummy")#isLV=True means LV,slot=-2 means all, but command only started
self.Ctrl_PowerLV_Cmd(False,LV_Channel_list,PopUp)
if not self.last_op_ok:
return self.BI_CheckIDs_failed_terminate("Can't stop LVs.")
time.sleep(BI_SLEEP_AFTER_LVSET)
#check LV stop
for row in Slot_list:
if(self.SharedDict["CAEN_table"].item(row,CTRLTABLE_LV_STAT_COL).text()!="OFF"):
return self.BI_CheckIDs_failed_terminate("LVs check failed.")
self.BI_Update_PowerStatus_sig.emit(-1,True,"OFF_dummy")#isLV=True means LV,slot=-1 means all, update GUI-side
self.SharedDict["BI_Action"].setText("None")
self.SharedDict["BI_Status"].setText("Idle")
self.logger.info("BurnIn CheckIDs COMPLETED SUCCESFULLY!")
self.BI_terminated.emit()
## BI main function
# implemented as a is a Pyqt slot
@pyqtSlot()
def BI_Start_Cmd(self):
stepAllowed = ["COOL","HEAT","LV_ON","LV_OFF","HV_ON","HV_OFF","SCANIV"]#WAIT and DAQ are treated separately
self.SharedDict["BI_Active"]=True
self.logger.info("Starting BurnIN...")
#creating parameter dictionary for the current session
session_dict={}
session_dict["Step"] = 1
session_dict["StepList"] = self.SharedDict["StepList"]
session_dict["Action"] = "Undef"
session_dict["Cycle"] = 0
session_dict["Status"] = "Setup"
session_dict["LowTemp"] = self.SharedDict["BI_LowTemp"]
session_dict["LowRamp"] = self.SharedDict["BI_LowRamp"]
session_dict["LowKeep"] = self.SharedDict["BI_LowKeep"]
session_dict["HighTemp"] = self.SharedDict["BI_HighTemp"]
session_dict["HighRamp"] = self.SharedDict["BI_HighRamp"]
session_dict["HighKeep"] = self.SharedDict["BI_HighKeep"]
session_dict["Operator"] = self.SharedDict["BI_Operator"]
session_dict["Description"] = self.SharedDict["BI_Description"]
session_dict["Session"] = "-1"
session_dict["ActiveSlots"] = self.SharedDict["BI_ActiveSlots"]
session_dict["ModuleIDs"] = self.SharedDict["BI_ModuleIDs"]
session_dict["TestType"] = "Undef"
session_dict["Timestamp"] = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
session_dict["CycleTimestamp"] = "NoCycleNoTime"
session_dict["fc7ID"] = "Undef"
session_dict["Current_ModuleID"] = "Undef"
session_dict["fc7Slot"] = "Undef"
session_dict["Current_ModuleHV"] = "Undef"
session_dict["Current_Slot"] = -1
session_dict["WorkingTemp"] = 20
session_dict["NCycles"] = [item.upper() for item in session_dict["StepList"]].count("COOL")
#check if file session already exists (aka a session was stopped or crashed)
if (os.path.exists("Session.json")):
self.logger.info("Found session file.")
self.SharedDict["WaitInput"]=True
self.Request_confirm_sig.emit("Resume last session?")
while self.SharedDict["WaitInput"]:
time.sleep(0.1)
if self.SharedDict["Confirmed"]:
try:
with open('Session.json') as json_file:
session_dict={}
session_dict = json.load(json_file)
self.logger.info(session_dict)
#updating values in main GUI tab
self.BI_Update_GUI_sig.emit(session_dict)
self.logger.info("BI :Previous session parameters loaded")
self.logger.info("Current Session: "+session_dict["Session"])
self.logger.info("Current Thermal Cycle: "+str(session_dict["Cycle"]))
self.logger.info("Current Step: "+str(session_dict["Step"]))
self.logger.info("Current Action: "+session_dict["Action"])
session_dict["Status"] = "Recovery"
if len(session_dict["StepList"])==0:
self.BI_Abort("Empty cycle description")
return
for step in self.SharedDict["StepList"]:
if not ((step.upper() in stepAllowed)) and (step[0:3].upper()!="DAQ") and (step[0:4].upper()!="WAIT"):
self.BI_Abort("Undefined step in cycle description")
return
except Exception as e:
self.logger.error(e)
self.logger.error("BI :Error reloading session parameters from Json file")
self.BI_Abort("Error while recovering session info. Please start new session")
return
else:
self.logger.info("Previous session overridden. Starting new session")
if len(session_dict["StepList"])==0:
self.BI_Abort("Empty cycle description")
return
for step in self.SharedDict["StepList"]:
if not ((step.upper() in stepAllowed)) and (step[0:3].upper()!="DAQ") and (step[0:4].upper()!="WAIT"):