-
Notifications
You must be signed in to change notification settings - Fork 1
/
2230G.py
1345 lines (1187 loc) · 47.9 KB
/
2230G.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
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 18 15:07:47 2020
@author: Aaron Mott
"""
import visa
class KEI2230G():
def __init__(self,
inst_address,
baud_rate = 9600,
term_chars = '\n',
timeout = 2000):
"""
Initializes the instrument with instrument address, baud rate,
termination characters, and timeout.
Parameters
----------
inst_address : str
The port address of the instrument.
baud_rate : int, optional
The default is 9600, but may be set to 4800, 9600, 19200, 38400,
57600, or 115200.
term_chars : str, optional
The termination character for the instrument.
timeout : int, float
Amount of time to wait for a response before a timeout error in
milliseconds.
"""
self.rm = visa.ResourceManager()
self.inst = self.rm.open_resource(self.instr_address,
baud_rate,
term_chars,
timeout)
def clear_status(self):
"""Clears all the event registers and error queue."""
self.inst.write("*CLS")
def set_eser(self, NR1):
"""
Sets the Standard Event Enable Register.
Parameters
----------
NR1 : int
A value from 0 through 255. The binary bits of the ESER are set
according to this value.
"""
if int(NR1) in range(256):
self.inst.write(f"*ESE {NR1}")
else:
raise ValueError("Value Error. Please enter an integer between "
"0 and 255.")
def get_standard_event(self):
"""Reads the Standard Event Enable Register."""
current_register = str(self.inst.query("*ESE?"))
return(current_register)
def get_standard_event_and_clear(self):
"""Reads the Standard Event Status Register and clears it."""
current_register = str(self.inst.query("*ESR?"))
return(current_register)
def get_info(self):
"""
Returns the instrument manufacturer, model, serial number, and firmware
revision level.
"""
info = str(self.inst.query("*IDN?")).split(',')
return(" Manufacturer: " + info[0] + '\n',
"Model: " + info[1] + '\n',
"Serial Number: " + info[2]+'\n',
" Firmware Version: " + info[3])
def get_model(self):
"""Returns model type (30-3, 30-6, or 60-3)."""
model = (str(self.get_info.split('\n')[1].split(":")
[1].replace(" ", ""))[6:10])
return(model)
def set_op_complete(self):
"""
Set the Operation Complete bit in the Standard Event Status Register
#to 1 after all pending commands have been executed.
"""
self.inst.write("*OPC")
def get_op_complete(self):
"""Indicates whether all pending OPC operations are finished."""
op = self.inst.query("*OPC?")
if int(op) == 1:
return("All OPC operations are finished.")
else:
return("Some OPC operations are still ongoing.")
def set_psc(self, NR1):
"""
This command specifies sets the power status clear flag to true
or false. 0 is false and 1 is true.
Parameters
----------
NR1 : int
Either 0 or 1.
Raises
------
ValueError
DESCRIPTION.
Returns
-------
None.
"""
if int(NR1) in range(2):
self.inst.write(f"*PSC {NR1}")
else:
raise ValueError("Value Error. Please enter 0 for false or 1 for "
"true.")
def set_setup(self, NR1):
"""
Recalls the setups you saved in the specified memory location.
Parameters
----------
NR1 : int
An integer value from 1 to 36 that specifies the location of setup
memory.
"""
if int(NR1) in range(1, 37):
self.inst.write(f"*RCL {NR1}")
else:
raise ValueError("Value Error. Please enter an integer between 1 "
"and 36.")
def reset_settings(self):
"""Resets the power supply to default settings."""
self.inst.write("*RST")
def save_to(self, NR1):
"""
Saves the present current, voltage, and maximum voltage settings
of the power supply into specified memory.
Parameters
----------
NR1 : int
An integer value from 1 to 36.
"""
if int(NR1) in range(1, 37):
self.inst.write(f"*SAV {NR1}")
else:
raise ValueError("Value Error. Please enter an integer between 1 "
"and 36.")
def set_status_byte(self, NR1):
"""
Sets or the bits in the Status Byte Enable Register.
Parameters
----------
NR1 : int
An integer value 0 to 255. The binary bits of the Status Request
Enable Register (SRER) are set according to this value. Using an
out-of-range value causes an execution error.
"""
if int(NR1) in range(256):
self.inst.write(f"*SRE {NR1}")
else:
raise ValueError("Value Error. Please enter an integer between 0 "
"and 255.")
def get_status_byte(self):
"""Returns Status Byte Enable Register."""
status_byte = str(self.inst.query("*SRE"))
return(status_byte)
def get_sbr(self):
"""Reads the data in the Status Byte Register."""
sbr = str(self.inst.query("*STB"))
return(sbr)
def self_test(self):
"""Initiates a self-test and reports any errors."""
error_code = str(self.inst.query("*TST"))
return(error_code)
def wait(self):
"""
Prevents the instrument from executing further commands or queries
until all pending commands are complete.
"""
self.inst.write("*WAI")
def cal_cle(self):
"""Clears the calibration information on the instrument."""
self.inst.write("CAL:CLE")
def cal_curr(self, NR2):
"""
Sets the actual output current value of the calibration point.
Parameters
----------
NR2 : float
Current value of the calibration point.
"""
self.inst.write(f"CAL:CURR {NR2}")
def cal_curr_lev(self, point):
"""
Sets the current calibration points.
Parameters
----------
point : str
Points P1 and P2 must be calibrated in numeric order..
"""
if str(point).upper() in ['P1', 'P2']:
self.inst.write(f"CAL:CURR:LEV {point}.upper()")
else:
raise ValueError("Value Error. Please enter P1 or P2.")
def cal_init(self):
"""Sets the current calibration coefficient as the default value."""
self.inst.write("CAL:INIT")
def cal_sav(self):
"""Saves the calibration coefficient into nonvolatile memory."""
self.inst.write("CAL:SAV")
def cal_sec(self, boolean, password):
"""
Enables or disables calibration mode.
Parameters
----------
boolean : int
0 enables the calibration mode, 1 disables calibration mode.
password : int
The password is the model number of the power supply..
"""
#Gets serial number.
code = str(self.get_info.split('\n')[1].split(":")[1].replace(" ", ""))
#Checks if state and password are correct.
if boolean in range(2) and str(password) == code:
self.inst.write(f"CAL:SEC {boolean} {password}")
else:
raise ValueError("Value Error. Please refer to the manual for "
"correct inputs.")
def cal_sec_unsecure(self, boolean):
"""
Enables or disables calibration mode without asking for password.
Parameters
----------
boolean : int
0 enables the calibration mode, 1 disables calibration mode.
"""
code = str(self.get_info.split('\n')[1].split(":")[1].replace(" ", ""))
if boolean in range(2):
self.inst.write(f"CAL:SEC {boolean} {code}")
else:
raise ValueError("Value Error. Please enter 0 or 1.")
def cal_str(self, string):
"""
Writes the calibration information of the instrument.
Parameters
----------
string : str
The maximum length of the string is 22 bytes.
"""
if 0 <= len(str(string).encode('utf8')) <= 22:
self.inst.write(f"CAL:STR {string}")
else:
raise ValueError("Value Error. Please enter a string no more than "
"22 bytes.")
def get_cal(self):
"""Returns calibration information of the intrsument."""
cal = str(self.inst.query("CAL:STR?"))
return(cal)
def cal_volt(self, NR2):
"""
Sets the actual output voltage value of the calibration point.
Parameters
----------
NR2 : float
The voltage value of the calibration point.
"""
if 0 <= float(NR2) <= 30:
self.inst.write(f"CAL:VOLT {NR2}")
else:
raise ValueError("Value Error. Please refer to the manual for "
"correct inputs.")
def cal_volt_lev(self, point):
"""
Sets the voltage calibration points. The second if statement is if the
user only enters the number and is checked as an integer instead of a
string to help differentiate between entering the command with or
without "P" trailing the point.
Parameters
----------
point : str, int
Points P1, P2, P3, and P4 must be calibrated in numeric order.
"""
if str(point).upper() in ['P1', 'P2', 'P3', 'P4']:
self.inst.write(f"CAL:VOLT:LEV {point}.upper()")
if int(point) in range(1, 5):
self.inst.write(f"CAL:VOLT:LEV P{point}")
else:
raise ValueError("Value Error. Please enter P1, P2, P3, or P4.")
def inst_com(self):
"""Returns connection state of the channels."""
comb = str(self.inst.query("INST:COMB?"))
return(comb)
def inst_comb_off(self):
"""Turns off the connection of channels."""
self.inst.write("INST:COM:OFF")
def set_parallel(self, level):
"""
Specifies that the instrument combines the present readings of
channels when they are connected in parallel. The two last if
statements are if the user only enters numbers and are checked as
integers instead of a string to help differentiate between entering
the command with or without "CH" trailing the channel number.
Parameters
----------
level : str, int
Channels to be combined in parallel.
"""
if str(level).upper() in ["CH1CH2", "CH2CH3", "CH1CH2CH3"]:
self.inst.write(f"INST:COMB:PAR {level}.upper()")
if int(level) in [12, 23]:
self.inst.write(f"INST:COMB:PAR CH{str(level)[0]}"
"CH{str(level)[1]}")
if int(level) == 123:
self.inst.write(f"INST:COMB:PAR CH1CH2CH3")
else:
raise ValueError("Value Error. Please enter CH1CH2, CH2CH3, or "
"CH1CH2CH3.")
def inst_com_ser(self):
"""
Combines the present voltage readings on channel 1 (CH1) and
channel 2 (CH2) when they are connected in series.
"""
self.inst.write("INST:COMB:SER")
def set_track(self, level):
"""
Sets channels to tracking mode. The two last if statesments
are if the user only enters numbers and are checked as integers
instead of a string to help differentiate between entering the
command with or without "CH" trailing the channel number.
Parameters
----------
level : str
The channels to be set to tracking mode.
"""
if str(level).upper() in ['CH1CH2', 'CH2CH3', 'CH1CH2CH3']:
self.inst.write(f"INST:COMB:TRAC {level}.upper()")
if int(level) in [12, 23]:
self.inst.write(f"INST:COMB:TRAC CH{str(level)[0]}"
"CH{str(level)[1]")
if int(level) == 123:
self.inst.write(f"INST:COMB:TRAC CH1CH2CH3")
else:
raise ValueError("Value Error. Please enter CH1CH2, CH2CH3, or "
"CH1CH2CH3.")
def select_channel(self, NR1):
"""
Selects channel number.
Parameters
----------
NR1 : int
The channel number.
"""
if int(NR1) in range(1, 4):
self.inst.write(f"INST:NSEL {NR1}")
else:
raise ValueError("Value Error. Please enter 1, 2, or 3.")
def set_channel(self, level):
"""
Selects the channel.
Parameters
----------
level : str
The channel.
"""
if str(level).upper() in ["CH1", "CH2", "CH3"]:
self.inst.write(f"INST {level}.upper()")
if int(level) in range(1, 4):
self.inst.write(f"INST CH{level}")
else:
raise ValueError("Value Error. Please enter CH1, CH2, or CH3.")
def get_channel(self):
"""Queries selected channel."""
channel = str(self.inst.query("INST?"))
return(channel)
def get_channel_curr(self, level):
"""
Queries the current reading on the specified channel.
Parameters
----------
level : str, int
The selected channel or channels with the current readings to
return.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
reading = str(self.inst.query(f"FETC:CURR? {level}.upper()"))
return(reading)
if int(level) in range(1, 4):
reading = str(self.inst.query(f"FETC:CURR? CH{level}"))
return(reading)
if int(level) == 123:
reading = str(self.inst.query(f"FETC:CURR? ALL"))
return(reading)
else:
raise ValueError("Value Error. Please enter CH1, CH2, CH3, or "
"ALL.")
def get_power(self, level):
"""
Queries the present power measurement on a specified channel or
channels.
Parameters
----------
level : str, int
The channel or channels with the measurement to return.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
power = str(self.inst.query(f"FETC:POW? {level}.upper()"))
return(power)
if int(level) in range(1, 4):
power = str(self.inst.query(f"FETC:POW? CH{level}"))
return(power)
if int(level) == 123:
power = str(self.inst.query(f"FETC:POW? ALL"))
return(power)
else:
raise ValueError("Value error. Please enter CH1, CH2, CH3, or "
"ALL.")
def get_volt(self, level):
"""
Returns new current voltage on a specified channel or channels.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
volt = str(self.inst.query(f"FETC:VOLT? {level}.upper()"))
return(volt)
else:
raise ValueError("Value Error. Please enter CH1, CH2, CH3, or "
"ALL.")
def meas_curr(self, level):
"""
Initiates and executes a new current measurement or queries the
new measured current on a specified channel or channels.
Parameters
----------
level : str, int
The channel or channels on which to make a new current measurement.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
curr_meas = str(self.inst.query(f"MEAS:CURR? {level}.upper()"))
return(curr_meas)
if int(level) in range(1, 4):
curr_meas = str(self.inst.query(f"MEAS:CURR? CH{level}"))
return(curr_meas)
if int(level) == 123:
curr_meas = str(self.inst.query(f"MEAS:CURR? ALL"))
return(curr_meas)
else:
raise ValueError("Value Error. Please enter CH1, CH2, CH3, or "
"ALL.")
def meas_power(self, level):
"""
Initiates and executes a new power measurement or queries the new
measured power.
Parameters
----------
level : str, int
The channel or channels on which to make a new power measurement.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
pow_meas = str(self.inst.query(f"MEAS:POW? {level}.upper()"))
return(pow_meas)
if int(level) in range(1, 4):
pow_meas = str(self.inst.query(f"MEAS:POW? CH{level}"))
return(pow_meas)
if int(level) == 123:
pow_meas = str(self.inst.query(f"MEAS:POW? ALL"))
return(pow_meas)
else:
raise ValueError("Value Error. Please enter CH1, CH2, CH3, or "
"ALL.")
def meas_volt(self, level):
"""
Initiates and executes a new voltage measurement or queries the new
measured voltage.
Parameters
----------
level : str, int
The channel or channels on which to make a new voltage measurement.
"""
if str(level).upper() in ["CH1", "CH2", "CH3", "ALL"]:
volt_meas = str(self.inst.query(f"MEAS:VOLT? {level}.upper()"))
return(volt_meas)
if int(level) in range(1, 4):
volt_meas = str(self.inst.query(f"MEAS:VOLT? CH{level}"))
return(volt_meas)
if int(level) == 123:
volt_meas = str(self.inst.query(f"MEAS:VOLT? ALL"))
return(volt_meas)
else:
raise ValueError("Value Error. Please enter CH1, CH2, CH3, or "
"ALL.")
def apply_volt(self, level, volt, curr):
"""
Sets voltage and current levels on a specified channel with a single
command message.
Parameters
----------
level : str, int
The channel to apply the settings to.
volt : str, int
The voltage value to apply.
curr : str, int
The current value to apply.
"""
if self.get_model == '30-3':
if str(level.upper()) in ["CH1", "CH2"]:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 31 and 0 <= float(curr) <= 4):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) in range(1, 3):
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 31 and 0 <= float(curr) <= 4):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
if str(level.upper()) == 'CH3':
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) in 0 <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) == 3:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) in 0 <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
if self.get_model == '30-6':
if str(level.upper()) in ["CH1", "CH2"]:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 30 and 0 <= float(curr) <= 6):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) in range(1, 3):
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 30 and 0 <= float(curr) <= 6):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
if str(level.upper()) == 'CH3':
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) == 3:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
if self.get_model == '60-3':
if str(level.upper()) in ["CH1", "CH2"]:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 60 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) in range(1, 3):
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 60 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
if str(level.upper()) == 'CH3':
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL {level}.upper(), {volt}.upper,"
"{curr}.upper()"))
if int(level) == 3:
if (str(volt).upper() and str(curr).upper() in
["MAX", "MIN", "DEF", "UP", "DOWN"] or
0 <= float(volt) <= 5 and 0 <= float(curr) <= 3):
self.inst.write((f"APPL CH{level}, {volt}.upper,"
"{curr}.upper()"))
else:
raise ValueError("Value Error. Please refer to the manual for "
"correct inputs.")
def set_output(self, boolean):
"""
Sets the output state of the presently selected channel.
Parameters
----------
boolean : bool
The output state.
"""
if str(boolean).upper() in ["ON", "OFF"]:
self.inst.write(f"CHAN:OUTP {boolean}.upper()")
if int(boolean) in range(2):
self.inst.write(f"CHAN:OUTP {boolean}.upper()")
else:
raise ValueError("Value Error. Please enter ON, OFF, 0, or 1.")
def get_output(self):
"""Returns the output state of the presently selected channel."""
channel_output = str(self.inst.query("CHAN:OUTP?"))
return(channel_output)
def set_curr_step(self, step, unit = 'A'):
"""
Sets the amount to increase current level.
Parameters
----------
step : float
The amount to increase the current.
unit : str, optional
Unit of measure for the specified current value.
"""
if str(unit).upper() == 'MA' and float(step):
step = float(step) / 1000
self.inst.write(f"CURR:STEP {step}A")
def get_curr_step(self):
"""Returns the current step amount."""
curr_step = str(self.inst.query("CURR:STEP?"))
return(curr_step)
def curr_down(self):
"""
Decreases the current value of the present channel by one step.,
as specified by the set_curr_step command.
"""
self.inst.write("CURR:DOWN")
def curr_up(self):
"""
Increases the current value of the present channel by one step,
as specified by the set_curr_step command.
"""
self.inst.write("CURR:UP")
def set_curr(self, NRf, unit = 'A'):
"""
Sets the current value of the power supply.
Parameters
----------
curr : str, int
The current value.
unit : str, optional
Unit of measure (amperes).
"""
if str(unit).upper() == 'MA' and float(NRf):
NRf = float(NRf) / 1000
if self.get_model == '30-3':
if str(NRf).upper in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 3:
self.inst.write(f"CURR {NRf}")
if self.get_model == '30-6':
if self.get_channel in ['CH1', 'CH2']:
if str(NRf).upper in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 6:
self.inst.write(f"CURR {NRf}")
if self.get_channel == 'CH3':
if str(NRf).upper in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 4:
self.inst.write(f"CURR {NRf}")
if self.get_model == '60-3':
if str(NRf).upper in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 3:
self.inst.write(f"CURR {NRf}")
else:
raise ValueError("Value Error. Please refer to the manual for "
"correct inputs.")
def get_curr(self):
"""Returns the current value of the power supply."""
curr = str(self.inst.query("CURR?"))
return(curr)
def set_output_state(self, boolean):
"""
Sets the output state of the power supply.
Parameters
----------
boolean : bool
The output state of the power supply.
"""
if str(boolean).upper() in ['ON', 'OFF']:
self.inst.write(f"OUTP:ENAB {boolean}.upper()")
if int(boolean) in range(2):
self.inst.write(f"OUTP:ENAB {boolean}")
else:
raise ValueError("Value Error. Please enter ON, OFF, 0, or 1.")
def set_output_parrallel(self, channels):
"""
Sets the parallel synchronization state of the three channels.
Parameters
----------
channels : str, int
The channel that the parallel synchronization state is applied to.
"""
if str(channels).upper() in ['CH1CH2', 'CH2CH3', 'CH1CH2CH3']:
self.inst.write(f"OUTP:PAR {channels}.upper()")
if int(channels) in [12, 23]:
self.inst.write(f"OUTP:PAR CH{str(channels)[0]}"
"CH{str(channels)[1]}")
if int(channels) == 123:
self.inst.write("OUTP:PAR CH1CH2CH3")
else:
raise ValueError("Value Error. Please enter CH1CH2, CH2CH3, or "
"CH1CH2CH3.")
def get_output_parrallel(self):
"""Returns the parallel synchronization state of the three channels."""
output_parrallel = str(self.inst.query("OUTP:PAR?"))
return(output_parrallel)
def clear_state(self):
"""Clears the protection state of the power supply."""
self.inst.write("OUTP:PROT:CLE")
def set_output_series(self, boolean):
"""
Sets the series synchronization state of channel 1 (CH1)
and channel 2 (CH2). If channel 3 (CH3) and CH1 or CH3 and CH2 are
in parallel synchronization states, an error is generated after
the command is executed.
Parameters
----------
boolean : str, int
The series synchronization state.
"""
if str(boolean).upper() in ['ON', 'OFF']:
self.inst.write(f"OUTP:SER {boolean}.upper()")
if int(boolean) in range(2):
self.inst.write(f"OUTP:SER {boolean}")
else:
raise ValueError("Value Error. Please enter ON, OFF, 0, or 1.")
def get_output_series(self):
"""Returns the synchronization state of CH1 and CH2."""
output_series = str(self.inst.query("OUTP:SER?"))
return(output_series)
def set_output_states(self, boolean):
"""
Sets the output state of all three channels.
Parameters
----------
boolean : str, int
The output state.
"""
if str(boolean).upper() in ['ON', 'OFF']:
self.inst.write(f"OUTP {boolean}.upper()")
if int(boolean) in range(2):
self.inst.write(f"OUTP {boolean}")
else:
raise ValueError("Value Error. Please enter ON, OFF, 0, or 1.")
def get_output_states(self):
"""Returns the output state of all three channels."""
output_states = str(self.inst.query("OUTP?"))
return(output_states)
def set_time_delay(self, NR2, unit = 'S'):
"""
Sets the delay time for the output timer function.
Parameters
----------
NR2 : float
The delay time.
unit : str, optional
Unit of measure for the delay time.
"""
if str(unit).upper() == 'MS' and float(NR2):
NR2 = float(NR2) / 1000
if 0.1 <= float(NR2) <= 99999.9:
self.inst.write(f"OUTP:TIM:DEL {NR2}")
else:
raise ValueError("Value Error. Please enter a value between 0.1 "
"and 99999.9.")
def get_time_delay(self):
"""Returns the delay time for the output timer function."""
time_delay = str(self.inst.query("OUTP:TIM:DEL?"))
return(time_delay)
def set_time_delay_channel(self, boolean):
"""
Sets the output timer state for the presently selected channel.
Parameters
----------
boolean : str, int
The output timer state.
"""
if str(boolean).upper() in ['ON', 'OFF']:
self.inst.write(f"OUTP:TIM {boolean}.upper()")
if int(boolean) in range(2):
self.inst.write(f"OUTP:TIM {boolean}")
else:
raise ValueError("Value Error. Please enter ON, OFF, 0, or 1.")
def get_time_delay_channel(self):
"""Returns output timer state for presently selected channel."""
time_delay_channel = str(self.inst.query("OUTP:TIM?"))
return(time_delay_channel)
def set_volt_step(self, NR2, unit = 'V'):
"""
Sets the value of the voltage step.
Parameters
----------
NR2 : int
The value of the voltage step.
unit : str, optional
Unit of measure for the voltage step.
"""
if str(unit).upper() == 'MV' and float(NR2):
NR2 = float(NR2) / 1000
if str(unit).upper() == 'KV' and float(NR2):
NR2 = float(NR2) * 1000
self.inst.write(f"VOLT:STEP {NR2}")
def get_volt_step(self):
"""Returns value of the voltage step."""
volt_step = str(self.inst.query("VOLT:STEP?"))
return(volt_step)
def volt_down(self):
"""
Decreases the voltage value of the present channel by one step,
as specified by the set_volt_step command.
"""
self.inst.write("VOLT:DOWN")
def volt_up(self):
"""
Increases the voltage value of the present channel by one step,
#as specified by the set_volt_step command.
"""
self.inst.write("VOLT:UP")
def set_volt(self, NRf, unit = 'V'):
"""
Sets the voltage value of the power supply.
Parameters
----------
NRf : str, int
The voltage value.
unit: str, optional
Sets the voltage value of the power supply.
"""
if self.get_model == '30-3':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or
0 <= float(NRf) <= 30):
self.inst.write(f"VOLT {NRf}.upper()")
if self.get_channel == 'CH3':
if str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 5:
self.inst.write(f"VOLT {NRf}.upper()")
if self.get_model == '30-6':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or
0 <= float(NRf) <= 30):
self.inst.write(f"VOLT {NRf}.upper()")
if self.get_channel == 'CH3':
if (str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or
0 <= float(NRf) <= 5):
self.inst.write(f"VOLT {NRf}.upper()")
if self.get_model == '60-3':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or
0 <= float(NRf) <= 60):
self.inst.write(f"VOLT {NRf}.upper()")
if self.get_channel == 'CH3':
if str(NRf).upper() in ['MIN TO MAX', 'MIN', 'MAX', 'UP',
'DOWN', 'DEF'] or 0 <= float(NRf) <= 5:
self.inst.write(f"VOLT {NRf}.upper()")
else:
raise ValueError("Value Error. Please refer to the manual for "
"correct inputs.")
def get_volt_power(self):
"""Returns the voltage value of the power supply."""
volt_power = str(self.inst.quert("VOLT?"))
return(volt_power)
def set_volt_limit(self, NRf):
"""
Sets the voltage limit for the present channel.
Parameters
----------
NRf : str, int
The voltage limit, 0 to the maximum rated voltage.
"""
if self.get_model == '30-3':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 30):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
if self.get_channel == 'CH3':
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 5):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
if self.get_model == '30-6':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 30):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
if self.get_channel == 'CH3':
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 5):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
if self.get_model == '60-3':
if self.get_channel in ['CH1', 'CH2']:
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 60):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
if self.get_channel == 'CH3':
if (str(NRf).upper() in ['MIN', 'MAX', 'DEF'] or
0 <= float(NRf) <= 5):
self.inst.write(f"VOLT:LIM {NRf}.upper()")
else:
raise ValueError("Value Error. Please refer to the manual for "