-
Notifications
You must be signed in to change notification settings - Fork 0
/
gas_control_nist.py
1576 lines (1417 loc) · 57.1 KB
/
gas_control_nist.py
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
"""Valve and Mass flow control module
__author__ = "Jorge Moncada Vivas"
__version__ = "1.0"
__email__ = "[email protected]"
Notes:
This module is based on the code written by Jorge Moncada Vivas and Ryuichi Shimogawa
"""
import os
import time
import serial
from serial.tools import list_ports
import propar
# The HID for the valve 3. This is should ideally be a specified in a different file.
# HID_VALVE = "USB VID:PID=067B:2303 SER= LOCATION=1-11" #RS232
HID_VALVE = "COM3" #RS485
HID_MFC = "COM4"
# This is a dictionary that maps the valve position and ID to an integer.
VALVE_POSITION = {"A": 0, "B": 1, "Unknown": 1, "pulse": 0, "cont": 1, "mix": 1}
VALVE_ID = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8, "I": 9}
class GasControl:
def __init__(
self,
control_hid: str = HID_VALVE,
control_comport: str = None,
num_valves=9,
mfc_hid: str = HID_MFC,
mfc_comport: str = None,
) -> None:
"""Initialize the valve control device
You can specify the HID or the comport of the valve control device
It will print the available comports if no comport is specified
Args:
control_hid (str): HID of the valve control device, you can also specify the name or hid of the comport [default: HID_VALVE]
control_comport (str): Comport of the valve control device [default: None]
num_valves (int): Number of valves connected to the valve control device [default: 8]
mfc_hid (str): HID of the mfc device, you can also specify the name or hid of the comport [default: HID_MFC]
mfc_comport (str): Comport of the mfc device [default: None]
"""
self.status: list[str] = [None] * num_valves
self.control_hid: str = control_hid
self.control_comport: str = control_comport
self.init_control_comport()
print("Valve comport: {}".format(self.control_comport))
self.serial_connection_valves()
self.mfc_hid: str = mfc_hid
self.mfc_comport: str = mfc_comport
self.init_mfc_comport()
print("MFC comport: {}".format(self.mfc_comport))
self.mfc_master = propar.master(self.mfc_comport, 38400)
self.define_flowsms()
def init_control_comport(self):
"""Initialize the comport of the valve control device
It will print the available comports if no comport is specified
"""
if self.control_hid:
control_port = list_ports.grep(self.control_hid)
control_port = list(control_port)
if (len(control_port) == 0) and (self.control_comport is None):
self.print_available_comports()
raise ValueError(
"No comport found for control_hid: {}".format(self.control_hid)
)
elif len(control_port) == 1:
self.control_comport = control_port[0].device
else:
self.print_available_comports()
raise ValueError(
"Multiple comports found for control_hid: {}".format(
self.control_hid
)
)
if self.control_comport is None:
self.print_available_comports()
raise ValueError("No comport specified")
def init_mfc_comport(self):
"""Initialize the comport of the mfc device
It will print the available comports if no comport is specified
"""
if self.mfc_hid:
mfc_port = list_ports.grep(self.mfc_hid)
mfc_port = list(mfc_port)
if (len(mfc_port) == 0) and (self.mfc_comport is None):
self.print_available_comports()
raise ValueError(
"No comport found for mfc_hid: {}".format(self.mfc_hid)
)
elif len(mfc_port) == 1:
self.mfc_comport = mfc_port[0].device
else:
self.print_available_comports()
raise ValueError(
"Multiple comports found for mfc_hid: {}".format(self.mfc_hid)
)
if self.mfc_comport is None:
self.print_available_comports()
raise ValueError("No comport specified")
def print_available_comports(self):
"""Prints the available comports along with their description and hardware id"""
comports_available = list_ports.comports()
print("Available comports:")
for comport in comports_available:
print(
"{}: {} [{}]".format(comport.device, comport.description, comport.hwid)
)
def serial_connection_valves(self):
"""Function that establishes the serial connection with the valve controller
It will connect to the comport specified in self.control_comport
"""
self.ser = serial.Serial()
self.ser.baudrate = 9600
self.ser.port = self.control_comport
parity = serial.PARITY_NONE
stopbits = serial.STOPBITS_ONE
bytesize = serial.EIGHTBITS
if self.ser.isOpen() == False:
self.ser.timeout = 0.5
self.ser.open()
else:
print("The Port is closed: " + self.ser.portstr)
<<<<<<< HEAD
def carrier_He_mix(self):
"""Fuction that selects He as carrier gas for the mixing line"""
self.ser.write(b'/GCW\r')
current_position_A = self.ser.readline().decode('utf-8').strip()
# print(current_position_A)
valve_no_A = current_position_A[1]
position_A = current_position_A[-2]
if position_A == 'A':
position_is_A = 'OFF'
elif position_A == 'B':
position_is_A = 'ON'
else:
position_is_A = 'Unknown'
print("Feeding He to mixing line")
=======
def get_valve_position(self, valve):
self.ser.write('/{}CP\r'.format(valve).encode())
current_position = self.ser.readline().decode('utf-8').strip()
valve_no = current_position[1]
position = current_position[-2]
if position == 'A':
return valve_no, 'OFF'
elif position == 'B':
return valve_no, 'ON'
else:
return valve_no, 'Unknown'
def display_valve_positions(self, valve=None):
if valve is not None:
valve_no, position = self.get_valve_position(valve)
print('Valve "{}" position is {}'.format(valve_no, position))
else:
valves = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
positions = [self.get_valve_position(valve) for valve in valves]
for valve_no, position in positions:
print('Valve "{}" position is {}'.format(valve_no, position))
>>>>>>> 0ca7ae02ff2bc16d8fe76b6bcc8df453cf84052d
def move_valve_to_position(self, valve, position):
if position == 'ON':
position_real = 'B'
command = 'CC'
elif position == 'OFF':
position_real = 'A'
command = 'CW'
else:
print('Invalid position specified.')
return
self.ser.write('/{}{}\r'.format(valve, command).encode())
time.sleep(0.3)
self.ser.write('/{}CP\r'.format(valve).encode())
new_position = self.ser.readline().decode('utf-8').strip()[-2]
if new_position != position_real:
self.ser.write('/{}{}\r'.format(valve, command).encode())
else:
# print('Valve "{}" successfully moved to position {}'.format(valve, position))
pass
def carrier_He_A(self):
"""Fuction that selects He as carrier gas for the Gas Line A"""
self.move_valve_to_position('G', 'OFF')
# self.ser.write(b'/GCW\r')
print("Feeding He to Gas Line A")
def carrier_Ar_A(self):
"""Fuction that selects Ar as carrier gas for Gas Line A"""
self.move_valve_to_position('G', 'ON')
# self.ser.write(b"/GCC\r")
print("Feeding Ar to Gas Line A")
def carrier_He_B(self):
"""Fuction that selects He as carrier gas for Gas Line B"""
self.move_valve_to_position('F', 'ON')
# self.ser.write(b"/FCC\r")
print("Feeding He to Gas Line B")
def carrier_Ar_B(self):
"""Function that selects Ar as carrier gas for Gas Line B"""
self.move_valve_to_position('F', 'OFF')
# self.ser.write(b"/FCW\r")
print("Feeding Ar to Gas Line B")
def feed_CO2_AB(self):
"""Fuction that selects carbon monoxide as gas source for Gas Line A and B"""
self.move_valve_to_position('D', 'ON')
# self.ser.write(b"/DCC\r")
print("Feeding CO2 to Gas Line A and B")
def feed_CO_AB(self):
"""Fuction that selects carbon monoxide as gas source for Gas Line A and B"""
self.move_valve_to_position('D', 'OFF')
# self.ser.write(b"/DCW\r")
print("Feeding CO to Gas Line A and B")
def feed_H2_A(self):
"""Function that selects hydrogen as gas source for Gas Line A"""
self.move_valve_to_position('I', 'OFF')
# self.ser.write(b"/ICW\r")
print("Feeding H2 to Gas Line A")
def feed_D2_A(self):
"""Function that selects deuterium as gas source for Gas Line A"""
self.move_valve_to_position('I', 'ON')
# self.ser.write(b"/ICC\r")
print("Feeding D2 to Gas Line A")
def feed_H2_B(self):
"""Function that selects hydrogen as gas source for Gas Line B"""
self.move_valve_to_position('H', 'ON')
# self.ser.write(b"/HCC\r")
print("Feeding H2 to Gas Line B")
def feed_D2_B(self):
"""Function that selects deuterium as gas source for Gas Line B"""
self.move_valve_to_position('H', 'OFF')
# self.ser.write(b"/HCW\r")
print("Feeding D2 to Gas Line B")
def feed_CH4_AB(self):
"""Fuction that selects methane as gas source for Gas Line A and B"""
self.move_valve_to_position('E', 'ON')
# self.ser.write(b"/ECC\r")
print("Feeding CH4 to Gas Line A and B")
def feed_C2H6_AB(self):
"""Function that selects ethane as gas source for Gas Line A and B"""
self.move_valve_to_position('E', 'OFF')
# self.ser.write(b"/ECW\r")
print("Feeding C2H6 to Gas Line A and B")
def feed_O2_AB(self):
"""Fuction that selects CO as carbon monoxide gas source for the mixing line
This function is not implemented in the valve control module"""
pass
def valve_C(self, position: str):
"""Function that selects the position of Valve C (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the position Gas Line A/B -> reactor
"on" means that the valve is in the position Gas Line A/B -> gas loop
"""
if position == "OFF":
self.move_valve_to_position('C', position)
# self.ser.write(b"/CCW\r")
print("Gas Line A/B valve position: off (Gas Line A/B -> reactor)")
elif position == "ON":
self.move_valve_to_position('C', position)
# self.ser.write(b"/CCC\r")
print("Gas Line A/B valve position: on (Gas Line A/B -> loop)")
def valve_B(self, position: str):
"""Function that selects the position of Valve B (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the position Gas Line A -> reactor
"on" means that the valve is in the position Gas Line B -> reactor
"""
if position == "OFF":
self.move_valve_to_position('B', position)
# self.ser.write(b"/BCW\r")
print("Valve B position: off \n(Gas Line A -> reactor)\n(Gas Line B -> pulses)")
elif position == "ON":
self.move_valve_to_position('B', position)
# self.ser.write(b"/BCC\r")
print("Valve B position: off \n(Gas Line B -> reactor)\n(Gas Line A -> pulses)")
def valve_A(self, position: str):
"""Function that selects the position of Valve A (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the loop 1 -> reactor, loop 2 -> vent
"on" means that the valve is in the loop 2 -> reactor, loop 1 -> vent
"""
if position == "OFF":
self.move_valve_to_position('A', position)
# self.ser.write(b"/ACW\r")
print(
"Pulses line valve position: off (Gas Line A -> loop 1 -> vent / Gas Line B -> loop 2 -> reactor)"
)
elif position == "ON":
self.move_valve_to_position('A', position)
# self.ser.write(b"/ACC\r")
print(
"Pulses line valve position: on (Gas Line B -> loop 2 -> vent / Gas Line A -> loop 1 -> reactor)"
)
def cont_mode_A(self, verbose: bool = True):
"""Function that selects the position of the valves in the reaction mode selection
module to the continuous mode gas line A mode
Gas Line A -> reactor ... Gas Line B -> loops -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.move_valve_to_position('A', 'OFF')
self.move_valve_to_position('B', 'OFF')
self.move_valve_to_position('C', 'OFF')
# self.ser.write(b"/ACW\r")
# self.ser.write(b"/BCW\r")
# self.ser.write(b"/CCW\r")
if verbose:
print("Valves operation mode: continuous mode Gas Line A")
print("Gas Line A -> reactor ... Gas Line B -> loops -> vent")
def cont_mode_B(self, verbose: bool = True):
"""Function that selects the position of the valves in the reaction mode selection
module to the continuous mode gas line B mode
Gas Line B -> reactor ... Gas Line A -> loops -> waste
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.move_valve_to_position('A', 'OFF')
self.move_valve_to_position('B', 'ON')
self.move_valve_to_position('C', 'OFF')
# self.ser.write(b"/ACW\r")
# self.ser.write(b"/BCC\r")
# self.ser.write(b"/CCW\r")
if verbose:
print("Valves operation mode: continuous mode Gas Line B")
print("Gas Line B -> reactor ... Gas Line A -> loops -> waste")
# def modulation(
# self,
# pulses=10,
# time1=10,
# time2=10,
# start_gas="pulse",
# end_gas="pulse",
# monitoring_interval=0.01,
# save_log="./log.txt",
# ):
# """Function that modulates the valves in the reaction mode selection module
# between the cont_mode_A and cont_mode_B
# Args:
# pulses (int): Number of pulses to be performed [default: 10]
# time1 (int): Time in seconds for the valve to be in Gas Line B mode [default: 10]
# time2 (int): Time in seconds for the valve to be in Gas Line A mode [default: 10]
# start_gas (str): Gas to be used as carrier gas in the pulses line at the beginning of the modulation [default: "pulse"]
# end_gas (str): Gas to be used as carrier gas in the pulses line at the end of the modulation [default: "pulse"]
# monitoring_interval (float): Time in seconds between each valve status check [default: 0.01]
# save_log (str): Path to the file where the valve status will be saved [default: "log.txt"]
# """
# if save_log is not None:
# os.makedirs(os.path.dirname(save_log), exist_ok=True)
# if not os.path.isfile(save_log):
# with open(save_log, "w") as f:
# f.write("Time, Valve1\n")
# start_time = time.time()
# end_time = start_time + pulses * (time1 + time2)
# if start_gas == "pulse":
# valve_fun1 = self.pulses_mode
# valve_fun2 = self.cont_mode_dry
# else:
# valve_fun1 = self.cont_mode_dry
# valve_fun2 = self.pulses_mode
# self.get_status()
# if start_gas in VALVE_POSITION.keys():
# start_gas_id = VALVE_POSITION[start_gas]
# else:
# raise ValueError(f"start_gas must be in {VALVE_POSITION.keys()}")
# if end_gas in VALVE_POSITION.keys():
# end_gas_id = VALVE_POSITION[end_gas]
# else:
# raise ValueError(f"end_gas must be in {VALVE_POSITION.keys()}")
# if VALVE_POSITION[start_gas] == 1:
# valve_fun1 = self.pulses_mode
# valve_fun2 = self.cont_mode_dry
# else:
# valve_fun1 = self.cont_mode_dry
# valve_fun2 = self.pulses_mode
# if VALVE_POSITION[end_gas] == 0:
# valve_end_fun = self.pulses_mode
# else:
# valve_end_fun = self.cont_mode_dry
# while True:
# current_time = time.time()
# accumulated_time = current_time - start_time
# current_pulse = int(accumulated_time / (time1 + time2))
# current_time_in_pulse = accumulated_time - current_pulse * (time1 + time2)
# if current_time_in_pulse < time1:
# if VALVE_POSITION[self.status[0]] == start_gas_id:
# time.sleep(monitoring_interval)
# continue
# else:
# self.get_status()
# if VALVE_POSITION[self.status[0]] == start_gas_id:
# time.sleep(monitoring_interval)
# continue
# else:
# valve_fun1(verbose=False)
# if save_log is not None:
# self.get_status()
# with open(save_log, "a") as f:
# f.write(
# f"{current_time}, {VALVE_POSITION[self.status[0]]}\n"
# )
# else:
# if VALVE_POSITION[self.status[0]] != start_gas_id:
# time.sleep(monitoring_interval)
# continue
# else:
# self.get_status()
# if VALVE_POSITION[self.status[0]] != start_gas_id:
# time.sleep(monitoring_interval)
# continue
# else:
# valve_fun2(verbose=False)
# if save_log is not None:
# self.get_status()
# with open(save_log, "a") as f:
# f.write(
# f"{current_time}, {VALVE_POSITION[self.status[0]]}\n"
# )
# time.sleep(monitoring_interval)
# if current_time > end_time:
# break
# valve_end_fun()
def pulses_loop_mode_A(self, verbose=True):
"""Function that selects the position of the valves in the reaction mode selection
module to the pulses loop mode
Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.move_valve_to_position('A', 'ON')
self.move_valve_to_position('B', 'OFF')
self.move_valve_to_position('C', 'ON')
# self.ser.write(b"/ACC\r")
# self.ser.write(b"/BCW\r")
# self.ser.write(b"/CCC\r")
if verbose:
print("Valves operation mode: pulses with gas loops")
print("Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent")
def pulses_loop_mode_B(self, verbose=True):
"""Function that selects the position of the valves in the reaction mode selection
module to the pulses loop mode
Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.move_valve_to_position('A', 'ON')
self.move_valve_to_position('B', 'ON')
self.move_valve_to_position('C', 'ON')
# self.ser.write(b"/ACC\r")
# self.ser.write(b"/BCW\r")
# self.ser.write(b"/CCC\r")
if verbose:
print("Valves operation mode: pulses with gas loops")
print("Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent")
def send_pulses_loop_A(self,pulses,time_bp):
#total_time_loop = float(pulses) * float(time_bp)
#total_time.append(total_time_loop)
# tmp.pulse_ON()
self.pulses_loop_mode_A()
int_pulses = int(pulses)
float_time = float(time_bp)
print('Valves operation mode: pulses (dual loop alternation)')
print('Number of pulses (loop): {}\nTime in between pulses (s): {}'.format(pulses,time_bp))
print('Valve Position Off: Gas Line B -> loop 2 -> reactor /// Gas Line A -> loop 1 -> vent')
print('Valve Position On: Gas line B -> loop 1 -> reactor /// Gas Line A -> loop 2 -> vent')
for pulse in range(0, int_pulses):
# tmp.pulse_ON()
self.ser.write(b'/ATO\r') # Comand that executes the pulses valve actuation
print('Sending pulse number {} of {}'.format(pulse+1,int_pulses), end = "\r") # Pulse status message for terminal window
time.sleep(float_time) # Conversion of seconds to miliseconds
# tmp.pulse_OFF()
print('Pulses have finished') # End of the pulses message
def send_pulses_loop_B(self,pulses,time_bp):
#total_time_loop = float(pulses) * float(time_bp)
#total_time.append(total_time_loop)
# tmp.pulse_ON()
self.pulses_loop_mode_B()
int_pulses = int(pulses)
float_time = float(time_bp)
print('Valves operation mode: pulses (dual loop alternation)')
print('Number of pulses (loop): {}\nTime in between pulses (s): {}'.format(pulses,time_bp))
print('Valve Position Off: Gas Line A -> loop 2 -> reactor /// Gas Line B -> loop 1 -> vent')
print('Valve Position On: Gas Line A -> loop 1 -> reactor /// Gas Line B -> loop 2 -> vent')
for pulse in range(0, int_pulses):
# tmp.pulse_ON()
self.ser.write(b'/ATO\r') # Comand that executes the pulses valve actuation
print('Sending pulse number {} of {}'.format(pulse+1,int_pulses), end = "\r") # Pulse status message for terminal window
time.sleep(float_time) # Conversion of seconds to miliseconds
# tmp.pulse_OFF()
print('Pulses have finished') # End of the pulses message
def send_pulses_valve_A(self,pulses,time_vo,time_bp):
#total_time_loop = (float(pulses) * float(time_bp)) + (float(pulses) * float(time_vo))
#total_time.append(total_time_loop)
valve_actuation_time = 0.145
self.cont_mode_A()
int_pulses = int(pulses) # Preparing the integer input for the loop range
float_time_vo = float(time_vo) # Preparing the float input for the sleep function vo
float_time_bp = float(time_bp) # Preparing the float input for the sleep function bp
print('Valves operation mode: pulses (valve)')
print('Number of pulses (valve): {}\nTime valve open (s): {}\nTime in between pulses (s): {}'.format(pulses,time_vo,time_bp))
print('Valve Position Off: mixing line -> reactor /// pulses line carrier -> loop 2 -> loop 1 -> waste')
print('Valve Position On: pulses line carrier -> reactor /// mixing line -> loop 2 -> loop 1 -> waste')
for pulse in range(0, int_pulses):
self.cont_mode_B() # Comand that executes the pulses valve actuation
time.sleep(float_time_vo + valve_actuation_time) # Conversion of seconds to miliseconds
self.cont_mode_A() # Comand that executes the pulses valve actuation
print('Sending pulse number {} of {}'.format(pulse+1,int_pulses), end = "\r") # Pulse status message for terminal window
time.sleep(float_time_bp) # Conversion of seconds to miliseconds
print('Pulses have finished') # End of the pulses message
def define_flowsms(self):
"""Function to define the parameters of the Flow-SMS mass flow controllers
The parameters are defined in the following dictionaries:
gas_list: List of the available gases
gas_dict: Dictionary that assigns a number to each gas
gas_ID: Dictionary that assigns a node ID to each gas
gas_cal: Dictionary that assigns a calibration ID to each gas. If there it is applicable to one gas, the value is None.
gas_flow_range: Dictionary that assigns a flow range to each gas
calibration_factor: Dictionary that assigns a calibration factor to each gas
feed_gas_functions: Dictionary that assigns a function to each gas
gas_float_to_int_factor: Dictionary that assigns a conversion factor from float to int to each gas
"""
self.gas_list = [
"H2_A",
"H2_B",
"D2_A",
"D2_B",
"O2_A",
"O2_B",
"CO_AH",
"CO_AL",
"CO_BH",
"CO_BL",
"CO2_AH",
"CO2_AL",
"CO2_BH",
"CO2_BL",
"CH4_A",
"CH4_B",
"C2H6_A",
"C2H6_B",
"C3H8_A",
"C3H8_B",
"He_A",
"He_B",
"Ar_A",
"Ar_B",
"N2_A",
"N2_B",
]
self.gas_dict = {self.gas_list[i]: i for i in range(len(self.gas_list))}
self.gas_ID = {
"H2_A": 4,
"D2_A":4,
"O2_A": 5,
"CO_AH": 6,
"CO_AL": 6,
"CO2_AH": 6,
"CO2_AL": 6,
"CH4_A": 7,
"C2H6_A": 7,
"C3H8_A": 7,
"He_A": 8,
"Ar_A": 8,
"N2_A": 8,
"He_B": 9,
"Ar_B": 9,
"N2_B": 9,
"CH4_B": 10,
"C2H6_B": 10,
"C3H8_B": 10,
"CO_BH": 11,
"CO_BL": 11,
"CO2_BH": 11,
"CO2_BL": 11,
"O2_B": 12,
"H2_B": 13,
"D2_B":13,
}
self.gas_cal = {
"H2_A": 0,
"H2_B": 0,
"D2_A": 1,
"D2_B": 1,
"O2_A": 0,
"O2_B": 0,
"CO_AH": 0,
"CO_BH": 0,
"CO2_AH": 1,
"CO2_BH": 1,
"CO2_AL": 2,
"CO2_BL": 2,
"CO_AL": 3,
"CO_BL": 3,
"CH4_A": 0,
"CH4_B": 0,
"C2H6_A": 1,
"C2H6_B": 1,
"C3H8_A": 2,
"C3H8_B": 2,
"He_A": 0,
"He_B": 0,
"Ar_A": 1,
"Ar_B": 1,
"N2_A": 2,
"N2_B": 2,
}
self.gas_flow_range = {
"CO2_AH": [0.6, 30.0],
"CO2_AL": [0.26, 13.0],
"CO2_BH": [0.6, 30.0],
"CO2_BL": [0.26, 13.0],
"CO_AH": [0.6, 30.0],
"CO_AL": [0.36, 18.0],
"CO_BH": [0.6, 30.0],
"CO_BL": [0.36, 18.0],
"CH4_A": [0.6, 30.0],
"CH4_B": [0.6, 30.0],
"C2H6_A": [0.6, 30.0],
"C2H6_B": [0.6, 30.0],
"C3H8_A": [0.6, 30.0],
"C3H8_B": [0.6, 30.0],
"H2_A": [0.6, 30.0],
"H2_B": [0.6, 30.0],
"D2_A": [0.6, 30.0],
"D2_B": [0.6, 30.0],
"O2_A": [0.6, 30.0],
"O2_B": [0.6, 30.0],
"He_A": [1.2, 60.0],
"He_B": [1.2, 60.0],
"Ar_A": [1.2, 60.0],
"Ar_B": [1.2, 60.0],
"N2_A": [1.2, 60.0],
"N2_B": [1.2, 60.0],
}
self.calibration_factor = {
"H2_A": 1.0,
"H2_B": 1.0,
"D2_A": 1.0,
"D2_B": 1.0,
"O2_A": 1.0,
"O2_B": 1.0,
"CO_AH": 1.0,
"CO_AL": 1.0,
"CO_BH": 1.0,
"CO_BL": 1.0,
"CH4_A": 1.0,
"CH4_B": 1.0,
"C2H6_A": 1.0,
"C2H6_B": 1.0,
"C3H8_A": 1.0,
"C3H8_B": 1.0,
"CO2_AH": 1.0,
"CO2_AL": 1.0,
"CO2_BH": 1.0,
"CO2_AL": 1.0,
"He_A": 1.0,
"He_B": 1.0,
"Ar_A": 1.0,
"Ar_B": 1.0,
"N2_A": 1.0,
"N2_B": 1.0,
}
self.feed_gas_functions = {
"H2_A": self.feed_H2_A,
"H2_B": self.feed_H2_B,
"D2_A": self.feed_D2_A,
"D2_B": self.feed_D2_B,
"O2_A": self.feed_O2_AB,
"O2_B": self.feed_O2_AB,
"CO_AH": self.feed_CO_AB,
"CO_AL": self.feed_CO_AB,
"CO_BH": self.feed_CO_AB,
"CO_BL": self.feed_CO_AB,
"CH4_A": self.feed_CH4_AB,
"CH4_B": self.feed_CH4_AB,
"C2H6_A": self.feed_C2H6_AB,
"C2H6_B": self.feed_C2H6_AB,
"C3H8_A": self.feed_C2H6_AB,
"C3H8_B": self.feed_C2H6_AB,
"CO2_AH": self.feed_CO2_AB,
"CO2_AL": self.feed_CO2_AB,
"CO2_BH": self.feed_CO2_AB,
"CO2_AL": self.feed_CO2_AB,
"He_A": self.carrier_He_A,
"He_B": self.carrier_He_B,
"Ar_A": self.carrier_Ar_A,
"Ar_B": self.carrier_Ar_B,
"N2_A": self.carrier_Ar_A,
"N2_B": self.carrier_Ar_B,
}
self.gas_float_to_int_factor = {
"H2_A": 30,
"H2_B": 30,
"D2_A": 30,
"D2_B": 30,
"O2_A": 30,
"O2_B": 30,
"CO_AH": 30,
"CO_AL": 18,
"CO_BH": 30,
"CO_BL": 18,
"CH4_A": 30,
"CH4_B": 30,
"C2H6_A": 30,
"C2H6_B": 30,
"C3H8_A": 30,
"C3H8_B": 30,
"CO2_AH": 30,
"CO2_AL": 13,
"CO2_BH": 30,
"CO2_BL": 13,
"He_A": 60,
"He_B": 60,
"Ar_A": 60,
"Ar_B": 60,
"N2_A": 60,
"N2_B": 60,
}
def set_flowrate(
self,
gas: str,
flow: float,
):
"""Function that sets the flow rate of a gas in the Flow-SMS mass flow controllers
Args:
gas (str): Gas for which the flow rate will be set
flow (float): Flow rate in sccm
"""
if gas not in self.gas_list:
raise ValueError("Gas not in list of available gases")
while True:
if (flow is None) or (flow == 0.0):
flow_conv = 0.0
break
flow_conv = flow / self.calibration_factor[gas]
if flow_conv < self.gas_flow_range[gas][0]:
print(
f"{gas} flow lower than minimum {self.gas_flow_range[gas][0]} sccm"
)
interval = input(
'Write "Yes" for setting a new flow or "No" for quiting the program: '
)
if interval == "Yes":
flow = float(input("Enter new flow: "))
elif interval == "No":
raise SystemExit
else:
break
elif flow_conv > self.gas_flow_range[gas][1]:
print(
f"{gas} flow higher than maximum {self.gas_flow_range[gas][1]} sccm"
)
interval = input(
'Write "Yes" for setting a new flow or "No" for quiting the program: '
)
if interval == "Yes":
flow = float(input("Enter new flow: "))
elif interval == "No":
raise SystemExit
else:
break
else:
break
if flow_conv > 0.0:
self.feed_gas_functions[gas]()
flow_data = int(flow_conv * 32000 / self.gas_float_to_int_factor[gas])
param = []
if self.gas_cal[gas] is not None:
param.append(
{
"node": self.gas_ID[gas],
"proc_nr": 1,
"parm_nr": 16,
"parm_type": propar.PP_TYPE_INT8,
"data": self.gas_cal[gas],
}
)
param.append(
{
"node": self.gas_ID[gas],
"proc_nr": 1,
"parm_nr": 1,
"parm_type": propar.PP_TYPE_INT16,
"data": flow_data,
}
)
status = self.mfc_master.write_parameters(param)
def flowsms_setpoints(
self,
H2_A: float = None,
D2_A: float = None,
O2_A: float = None,
CO_AH: float = None,
CO2_AH: float = None,
CO_AL: float = None,
CO2_AL: float = None,
CH4_A: float = None,
C2H6_A: float = None,
C3H8_A: float = None,
He_A: float = None,
Ar_A: float = None,
N2_A: float = None,
He_B: float = None,
Ar_B: float = None,
N2_B: float = None,
CH4_B: float = None,
C2H6_B: float = None,
C3H8_B: float = None,
CO_BH: float = None,
CO2_BH: float = None,
CO_BL: float = None,
CO2_BL: float = None,
O2_B: float = None,
H2_B: float = None,
D2_B: float = None,
):
"""Function that sets the flow rates of the gases in the Flow-SMS mass flow controllers
Args:
H2_A (float): Flow rate of H2 in sccm for gas line A [default: None]
H2_B (float): Flow rate of H2 in sccm for gas line B [default: None]
D2_A (float): Flow rate of D2 in sccm for gas line A [default: None]
D2_B (float): Flow rate of D2 in sccm for gas line B [default: None]
O2_A (float): Flow rate of O2 in sccm for gas line A [default: None]
O2_B (float): Flow rate of O2 in sccm for gas line B [default: None]
CO_AH (float): Flow rate of CO in sccm for gas line A with high flow calibration curve [default: None]
CO_AL (float): Flow rate of CO in sccm for gas line A with low flow calibration curve [default: None]
CO_BH (float): Flow rate of CO in sccm for gas line B with high flow calibration curve [default: None]
CO_BL (float): Flow rate of CO in sccm for gas line B with low flow calibration curve [default: None]
CO2_AH (float): Flow rate of CO2 in sccm for gas line A with high flow calibration curve [default: None]
CO2_AL (float): Flow rate of CO2 in sccm for gas line A with low flow calibration curve [default: None]
CO2_BH (float): Flow rate of CO2 in sccm for gas line B with high flow calibration curve [default: None]
CO2_BL (float): Flow rate of CO2 in sccm for gas line B with low flow calibration curve [default: None]
CH4_A (float): Flow rate of CH4 in sccm for gas line A [default: None]
CH4_B (float): Flow rate of CH4 in sccm for gas line B [default: None]
C2H6_A (float): Flow rate of C2H6 in sccm for gas line A [default: None]
C2H46_B (float): Flow rate of C2H6 in sccm for gas line B [default: None]
He_A (float): Flow rate of He in sccm for gas line A [default: None]
He_B (float): Flow rate of He in sccm for gas line B [default: None]
Ar_A (float): Flow rate of Ar in sccm for gas line A [default: None]
Ar_B (float): Flow rate of Ar in sccm for gas line B [default: None]
N2_A (float): Flow rate of N2 in sccm for gas line A [default: None]
N2_B (float): Flow rate of N2 in sccm for gas line B [default: None]
"""
if CO_AH is not None and CO_AH > 0.0:
self.set_flowrate("CO_AH", CO_AH)
elif CO_AL is not None and CO_AL > 0.0:
self.set_flowrate("CO_AL", CO_AL)
elif CO2_AH is not None and CO2_AH > 0.0:
self.set_flowrate("CO2_AH", CO2_AH)
else:
self.set_flowrate("CO2_AL", CO2_AL)
if CO_BH is not None and CO_BH > 0.0:
self.set_flowrate("CO_BH", CO_BH)
elif CO_BL is not None and CO_BL > 0.0:
self.set_flowrate("CO_BL", CO_BL)
elif CO2_BH is not None and CO2_BH > 0.0:
self.set_flowrate("CO2_BH", CO2_BH)
else:
self.set_flowrate("CO2_BL", CO2_BL)
if CH4_A is not None and CH4_A > 0.0:
self.set_flowrate("CH4_A", CH4_A)
elif C2H6_A is not None and C2H6_A > 0.0:
self.set_flowrate("C2H6_A", C2H6_A)
else:
self.set_flowrate("C3H8_A", C3H8_A)
if CH4_B is not None and CH4_B > 0.0:
self.set_flowrate("CH4_B", CH4_B)
elif C2H6_B is not None and C2H6_B > 0.0:
self.set_flowrate("C2H6_B", C2H6_B)
else:
self.set_flowrate("C3H8_B", C3H8_B)
if H2_A is not None and H2_A > 0.0:
self.set_flowrate("H2_A", H2_A)
else:
self.set_flowrate("D2_A", D2_A)
if H2_B is not None and H2_B > 0.0:
self.set_flowrate("H2_B", H2_B)
else:
self.set_flowrate("D2_B", D2_B)
if He_A is not None and He_A > 0.0:
self.set_flowrate("He_A", He_A)
elif Ar_A is not None and Ar_A > 0.0:
self.set_flowrate("Ar_A", Ar_A)
else:
self.set_flowrate("N2_A", N2_A)
if He_B is not None and He_B > 0.0:
self.set_flowrate("He_B", He_B)
elif Ar_B is not None and Ar_B > 0.0:
self.set_flowrate("Ar_B", Ar_B)
else:
self.set_flowrate("N2_B", N2_B)
self.set_flowrate("O2_A", O2_A)
self.set_flowrate("O2_B", O2_B)
def flowsms_status(self, delay=0.0):