forked from on1arf/jds6600_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jds6600.py
1893 lines (1396 loc) · 45.8 KB
/
jds6600.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
# jds6600.py
# library to remote-control a JDS6600 signal generator
# Kristoff Bonne (c) 2018
# published under MIT license. See file "LICENSE" for full license text
# Revisions:
# Version 0.0.1: 2018/01/19: initial release, reading basic parameters
# version 0.0.2: 2018/01/28: added "measure" menu + support functions, documentation
# version 0.0.3: 2018/02/07: added "counter" and "sweep" menu
# version 0.0.4: 2018/02/14: added "pulse" and "burst" menu + code cleanup
# version 0.0.5: 2018/02/16: added system menu
# version 0.1.0: 2018/02/17: added arbitrary waveform
import serial
import binascii
###########
# Errors #
###########
class UnknownChannelError(ValueError):
pass
class UnexpectedValueError(ValueError):
pass
class UnexpectedReplyError(ValueError):
pass
class FormatError(ValueError):
pass
class WrongMode(RuntimeError):
# called when commands are issued with the jds6600 not in the correct
# mode
pass
#################
# jds6600 class #
#################
class jds6600:
'jds6600 top-level class'
# serial device (opened during object init))
ser = None
# commands
DEVICETYPE=0
SERIALNUMBER=1
CHANNELENABLE=20
WAVEFORM1=21
WAVEFORM2=22
FREQUENCY1=23
FREQUENCY2=24
AMPLITUDE1=25
AMPLITUDE2=26
OFFSET1=27
OFFSET2=28
DUTYCYCLE1=29
DUTYCYCLE2=30
PHASE=31
ACTION=32
MODE=33
MEASURE_COUP=36 # coupling (AC or DC)
MEASURE_GATE=37 # gatetime
MEASURE_MODE=38 # mode (Freq or Periode)
COUNTER_COUPL=MEASURE_COUP
COUNTER_RESETCOUNTER=39
SWEEP_STARTFREQ=40
SWEEP_ENDFREQ=41
SWEEP_TIME=42
SWEEP_DIRECTION=43
SWEEP_MODE=44 # mode: linair or Log
PULSE_PULSEWIDTH=45
PULSE_PERIOD=46
PULSE_OFFSET=47
PULSE_AMPLITUDE=48
BURST_NUMBER=49
BURST_MODE=50
SYSTEM_SOUND=51
SYSTEM_BRIGHTNESS=52
SYSTEM_LANGUAGE=53
SYSTEM_SYNC=54
SYSTEM_ARBMAXNUM=55
PROFILE_SAVE=70
PROFILE_LOAD=71
PROFILE_CLEAR=72
COUNTER_DATA_COUNTER=80
MEASURE_DATA_FREQ_LOWRES=81 # low resolution freq counter, used for mode "frequency"
MEASURE_DATA_FREQ_HIGHRES=82 # high resolution freq. counter, usef for mode "period". UI: valid up to 2 Khz
MEASURE_DATA_PW1=83
MEASURE_DATA_PW0=84
MEASURE_DATA_PERIOD=85
MEASURE_DATA_DUTYCYCLE=86
MEASURE_DATA_U1=87
MEASURE_DATA_U2=88
MEASURE_DATA_U3=89
# waveforms: registers 21 (ch1) and 22 (ch2))
# 0 to 16: predefined waveforms
__wave=("SINE","SQUARE","PULSE","TRIANGLE","PARTIALSINE","CMOS","DC","HALF-WAVE","FULL-WAVE","POS-LADDER","NEG-LADDER", "NOISE", "EXP-RIZE","EXP-DECAY","MULTI-TONE","SINC","LORENZ")
# 101 to 160: arbitrary waveforms
__awave=[]
for a in range(1,10):
__awave.append("ARBITRARY0"+str(a))
for a in range(10,61):
__awave.append("ARBITRARY"+str(a))
# end for
# modes: register 33
# note: use lowest 4 bits for wrting
# note: use highest 4 bits for reading
__modes = ((0,"WAVE_CH1"),(0,"WAVE_CH1"),(1,"WAVE_CH2"),(1,"WAVE_CH2"),(2,"SYSTEM"),(2,"SYSTEM"),(-1,""),(-1,""),(4,"MEASURE"),(5,"COUNTER"),(6,"SWEEP_CH1"),(7,"SWEEP_CH2"),(8,"PULSE"),(9,"BURST"))
# action: register 32
__actionlist=(("STOP","0,0,0,0"),("COUNT","1,0,0,0"),("SWEEP","0,1,0,0"),("PULSE","1,0,1,1"),("BURST","1,0,0,1"))
__action={}
for (actionname,actioncode) in __actionlist:
__action[actionname]=actioncode
# end for
# measure mode parameters
__measure_coupling=("AC(EXT.IN)","DC(EXT.IN)")
__measure_mode=("M.FREQ","M.PERIOD")
# sweep parameters
__sweep_direction=("RISE","FALL","RISE&FALL")
__sweep_mode=("LINEAR","LOGARITHM")
# burst parameters
__burst_mode=["MANUAL TRIG.","CH2 TRIG.","EXT.TRIG(AC)","EXT.TRIG(DC)"]
# frequency multiplier
__freqmultiply=(1,1,1,1/1000,1/1000000)
# language
__system_language=("ENGLISH","CHINESE")
###############
# oonstructor #
###############
def __init__(self,fname):
jds6600.ser = serial.Serial(
port= fname,
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1 )
# end constructor
#####################
# support functions #
#####################
#####
# low-level support function
# parse data from read command
def __parsedata(self,reg,data,a):
if a not in (0,1): raise RuntimeError(a)
try:
(one,two)=data.split("=")
except ValueError:
raise FormatError("Parsing Returned data: Invalid format, missing \"=\"")
two_b=two.split(".")
# reads from register are terminated by a "."
# reads of arbitrary waveform are not
if a == 0:
if len(two_b) < 2:
raise FormatError("Parsing Returned data: Invalid format, missing \".\"")
if len(two_b) > 2:
raise FormatError("Parsing Returned data: Invalid format, too many \".\"")
# end if
# command to look for;
# "r" for register read, "b" for arbitrary waveform read
c = 'r' if a == 0 else 'b'
# check if returned data matches reg that was send
if reg != None:
if one != ":"+c+reg:
errmsg="Parsing Return data: send/received reg mismatch: "+data+" / expected :"+c+reg
raise FormatError(errmsg)
# end if
# end if
# done: return data: part between "=" and ".", split on ","
return two_b[0].split(",")
# end __parsedata
# command in textual form
def __reg2txt(self,reg):
return "0"+str(reg) if int(reg) < 10 else str(reg)
# end reg2txt
# send read command (for n datapoint)
def __sendreadcmd(self,reg,n,a):
if type(n) != int: raise TypeError(n)
if a not in (0,1): raise ValueError(a)
regtxt=self.__reg2txt(reg)
if (n < 1):
raise ValueError(n)
if a == 0:
# a (arbitrary waveform) is 0 -> register read
c='r' # register
else:
c='b' # arbitrary waveform
# for n to 1
n=1
# end else - if
# "n" in command start with 0 for 1 read-request
n -= 1
if self.ser.is_open == True:
tosend=":"+c+regtxt+"="+str(n)+"."+chr(0x0a)
self.ser.write(tosend.encode())
# end __sendreadcmd
# get responds of read-request and parse ("n" reads)
def __getrespondsandparse(self,reg, n, a):
if type(n) != int: raise ValueError(n)
if a not in (0,1): raise ValueError(a) # a=0-> register read, a=1 -> arbitrary waveform read
ret=[] # return value
c = int(reg) # counter
c_expect=self.__reg2txt(c)
for l in range(n):
# get one line responds from serial device
retserial=self.ser.readline()
# convert bytearray into string, then strip off terminating \n and \r
retserial=str(retserial,'utf-8').rstrip()
# get parsed data
# assume all data are single-value fields
parseddata=self.__parsedata(c_expect,retserial,a)
# we receive a list of strings, all containing numeric (integer) values
if len(parseddata) == 1:
# if list with one value, return that value (converted to integer)
ret.append(int(parseddata[0]))
else:
# if list with multiple values, convert all strings to integers and return list
retlist=[]
retcount=0
for data in parseddata:
if data == "":
# we should not receive empty datafields, except for after the last element of an arbitrary waveform
if not ((a == 1) and (retcount == 2048)):
raise UnexpectedValueError(parseddata)
else:
retlist.append(int(data))
# end else - if
retcount += 1
# end for
ret.append(retlist)
# end else - if
# increase next expected to-receive data
c += 1
c_expect=self.__reg2txt(c)
# end for
# return parsed data
# if only one element, return that element
# if multiple elements, return list
return ret[0] if n == 1 else ret
# end __get responds and parse 1
# get data
def __getdata(self,reg, n=1, a=0):
if type(reg) != int: raise TypeError(reg)
if type(n) != int: raise TypeError(n)
# a is "arbitrary waveform or register"
# a=0 -> register read
# a=1 -> arbitrary waveform read
# send "read" commandline for "n" lines
# copy "a" parameter from calling function
self.__sendreadcmd(reg,n,a)
return self.__getrespondsandparse(reg,n,a)
# end __getdata 1
# send write command and wait for "ok"
def __sendwritecmd(self,reg, val, a=0):
# note: a = "arbitrary waveform?": 0 = no (register write), 1 = yes (arb. waveform write)
# add a "0" to the command if it one single character
reg=self.__reg2txt(reg)
# command to send: "w" for register write, "b" for arbitrary waveform write
cmd = "w" if a == 0 else "a"
if self.ser.is_open == True:
if type(val) == int: val = str(val)
if type(val) != str: raise TypeError(val)
tosend=":"+cmd+reg+"="+val+"."+chr(0x0a)
self.ser.write(tosend.encode())
# wait for "ok"
# get one line responds from serial device
ret=self.ser.readline()
# convert bytearray into string, then strip off terminating \n and \r
ret=str(ret,'utf-8').rstrip()
if ret != ":ok":
raise UnexpectedReplyError(ret)
# end if
#end if
# end __sendwritecmd
#####
# high-level support function
# set action
def __setaction(self,action):
# type check
if type(action) != str:
raise TypeError(action)
# end if
try:
self.__sendwritecmd(jds6600.ACTION,jds6600.__action[action])
except KeyError:
errmsg="Unknown Action: "+action
raise ValueError(errmsg)
# end try
# end set action
###################
# DEBUG functions #
###################
def DEBUG_readregister(self,register,count):
if self.ser.is_open == True:
regtxt=self.__reg2txt(register)
tosend=":r"+regtxt+"="+str(count)+"."+chr(0x0a)
self.ser.write(tosend.encode())
ret=self.ser.readline()
while ret != b'':
print(str(ret))
ret=self.ser.readline()
# end while
# end if
# end readregister
def DEBUG_writeregister(self,register,value):
if self.ser.is_open == True:
regtxt=self.__reg2txt(register)
if type(value) == int:
value=str(value)
tosend=":w"+regtxt+"="+value+"."+chr(0x0a)
self.ser.write(tosend.encode())
ret=self.ser.readline()
while ret != b'':
print(str(ret))
ret=self.ser.readline()
# end while
# end if
# end write register
##############
# PUBLIC API #
##############
#########################
# Part 0: API information
# API version
def getAPIinfo_version(self):
return 1
# end getAPIversion
# API release number
def getAPIinfo_release(self):
return "0.1.0 2018-02-17"
# end get API release
#############################
# Part 1: information queries
# list of waveforms
def getinfo_waveformlist(self):
waveformlist=list(enumerate(jds6600.__wave))
for aw in (enumerate(jds6600.__awave,101)):
waveformlist.append(aw)
# end for
return waveformlist
# end get waveform list
# get list of modes
def getinfo_modelist(self):
modelist=[]
lastmode=-1
# create list of modes, removing dups
for (modeid,modetxt) in jds6600.__modes:
# ignore modes with modeid < 0 (unused mode)
if modeid < 0:
continue
# end if
if modeid != lastmode:
modelist.append((modeid,modetxt))
lastmode = modeid
# end if
# end for
return modelist
# end getinfo modelist
##################################
# Part 2: reading basic parameters
# get device type
def getinfo_devicetype(self):
return self.__getdata(jds6600.DEVICETYPE)
# end get device type
# get serial number
def getinfo_serialnumber(self):
return self.__getdata(jds6600.SERIALNUMBER)
# end get serial number
# get channel enable status
def getchannelenable(self):
(ch1,ch2)=self.__getdata(jds6600.CHANNELENABLE)
try:
return (False,True)[ch1], (False,True)[ch2]
except IndexError:
errmsg="Unexpected value received: {},{}".format(ch1,ch2)
raise UnexpectedValueError(errmsg)
# end get channel enable status
# get waveform
def getwaveform(self, channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
#WAVEFORM for channel 2 is WAVEFORM1 + 1
waveform=self.__getdata(jds6600.WAVEFORM1+channel-1)
# waveform 0 to 16 are in "wave" list, 101 to 160 are in __awave
try:
return (waveform,jds6600.__wave[waveform])
except IndexError:
pass
try:
return (waveform,jds6600.__awave[waveform-101])
except IndexError:
raise UnexpectedValueError(waveform)
# end getwaveform
# get frequency _with multiplier
def getfrequency_m(self,channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
(f1,f2)=self.__getdata(jds6600.FREQUENCY1+channel-1)
# parse multiplier (value after ",")
# 0=Hz, 1=KHz,2=MHz, 3=mHz,4=uHz)
# note f1 is frequency / 100
try:
return((f1/100*self.__freqmultiply[f2],f2))
except IndexError:
# unexptected value of frequency multiplier
raise UnexpectedValueError(f2)
# end elsif
# end function getfreq
# get frequency _no multiplier information
def getfrequency(self,channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
(f1,f2)=self.__getdata(jds6600.FREQUENCY1+channel-1)
# parse multiplier (value after ","): 0=Hz, 1=KHz,2=MHz, 3=mHz,4=uHz)
# note1: frequency unit is Hz / 100
# note2: multiplier 1 (khz) and 2 (mhz) only changes the visualisation on the
# display of the jfs6600. The frequency itself is calculated in
# the same way as for multiplier 0 (Hz)
# mulitpliers 3 (mHZ) and 4 (uHz) do change the calculation of the frequency
try:
return(f1/100*self.__freqmultiply[f2])
except IndexError:
# unexptected value of frequency multiplier
raise UnexpectedValueError(f2)
# end elsif
# end function getfreq
# get amplitude
def getamplitude(self, channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
amplitude=self.__getdata(jds6600.AMPLITUDE1+channel-1)
# amplitude is mV -> so divide by 1000
return amplitude/1000
# end getamplitude
# get offset
def getoffset(self, channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
offset=self.__getdata(jds6600.OFFSET1+channel-1)
# offset unit is 10 mV, and then add 1000
return (offset-1000)/100
# end getoffset
# get dutcycle
def getdutycycle(self, channel):
if type(channel) != int: raise TypeError(channel)
if not (channel in (1,2)): raise ValueError(channel)
dutycycle=self.__getdata(jds6600.DUTYCYCLE1+channel-1)
# dutycycle unit is 0.1 %, so divide by 10
return dutycycle/10
# end getdutycycle
# get phase
def getphase(self):
phase=self.__getdata(jds6600.PHASE)
# phase unit is 0.1 degrees, so divide by 10
return phase/10
# end getphase
##################################
# Part 3: writing basic parameters
# set channel enable
def setchannelenable(self,ch1,ch2):
if type(ch1) != bool: raise TypeError(ch1)
if type(ch2) != bool: raise TypeError(ch1)
# channel 1
if ch1 == True: enable = "1"
else: enable = "0" # end else - if
if ch2 == True: enable += ",1"
else: enable += ",0" # end else - if
# write command
self.__sendwritecmd(jds6600.CHANNELENABLE,enable)
# end set channel enable
# set waveform
def setwaveform(self,channel,waveform):
if type(channel) != int: raise TypeError(channel)
if (type(waveform) != int) and (type(waveform) != str): raise TypeError(waveform)
if not (channel in (1,2)): raise ValueError(channel)
# wzveform can be integer or string
w=None
if type(waveform) == int:
# waveform is an integer
if waveform < 101:
try:
jds6600.__wave[waveform]
except IndexError:
raise ValueError(waveform)
# end try
else:
try:
jds6600.__awave[waveform-101]
except IndexError:
raise ValueError(waveform)
# end try
# end if
# ok, it exists!
w=waveform
else:
# waveform is a string
# make everything uppercase
waveform=waveform.upper()
# check all waveform descriptions in wave and __awave
# w is already initialised as "none" above
try:
# try in "wave" list
w=jds6600.__wave.index(waveform)
except ValueError:
pass
if w == None:
#if not found in "wave", try the "awave" list
try:
w=jds6600.__awave.index(waveform)+101 # arbitrary waveforms state are index 101
except ValueError:
pass
# end try
# end if
if w == None:
# not in "wave" and "awave" error
errmsg="Unknown waveform "+waveform
raise ValueError (errmsg)
# end if
# ens else - if
self.__sendwritecmd(jds6600.WAVEFORM1+channel-1,w)
# end function set waveform
# set frequency (with multiplier)
def setfrequency(self,channel,freq,multiplier=0):
if type(channel) != int: raise TypeError(channel)
if (type(freq) != int) and (type(freq) != float): raise TypeError(freq)
if type(multiplier) != int: raise TypeError(multiplier)
if not (channel in (1,2)): raise ValueError(channel)
if (freq < 0):
raise ValueError(freq)
# do not execute set-frequency when the device is in sweepfrequency mode
currentmode=self.getmode()
if (channel == 1) and (currentmode[1] == "SWEEP_CH1"):
# for channel 1
raise WrongMode()
elif (channel == 2) and (currentmode[1] == "SWEEP_CH2"):
# for channel 2
raise WrongMode()
# end elsif - if
# freqmultier should be one of the "frequency multiply" values
try:
self.__freqmultiply[multiplier]
except IndexError:
raise ValueError[multiplier]
# frequency limit:
# 60 Mhz for multiplier 0 (Hz), 1 (KHz) and 2 (MHz)
# 80 Khz for multiplier 3 (mHz)
# 80 Hz for multiplier 4 (uHz)
# trying to configure a higher value can result in incorrect frequencies
if multiplier < 3:
if freq > 60000000:
errmsg="Maximum frequency using multiplier {} is 60 MHz.".format(multiplier)
raise ValueError(errmsg)
# end if
elif multiplier == 3:
if freq > 80000:
errmsg="Maximum frequency using multiplier 3 is 80 KHz."
raise ValueError(errmsg)
# end if
else: # multiplier == 4
if freq > 80:
errmsg="Maximum frequency using multiplier 4 is 80 Hz."
raise ValueError(errmsg)
# end if
# end else - elsif - if
# round to nearest 0.01 value
freq=int(round(freq*100/jds6600.__freqmultiply[multiplier]))
value=str(freq)+","+str(multiplier)
self.__sendwritecmd(jds6600.FREQUENCY1+channel-1,value)
# end set frequency (with multiplier)
# set amplitude
def setamplitude(self, channel, amplitude):
if type(channel) != int: raise TypeError(channel)
if (type(amplitude) != int) and (type(amplitude) != float): raise TypeError(amplitude)
if not (channel in (1,2)): raise ValueError(channel)
# amplitude is between 0 and 20 V
if not (0 <= amplitude <= 20):
raise ValueError(amplitude)
# round to nearest 0.001 value
amplitude=int(round(amplitude*1000))
self.__sendwritecmd(jds6600.AMPLITUDE1+channel-1,amplitude)
# end setamplitude
# set offset
def setoffset(self, channel, offset):
if type(channel) != int: raise TypeError(channel)
if (type(offset) != int) and (type(offset) != float): raise TypeError(offset)
if not (channel in (1,2)): raise ValueError(channel)
# offset is between -10 and +10 volt
if not (-10 <= offset <= 10):
raise ValueError(offset)
# note: althou the value-range for offset is able
# to accomodate an offset between -10 and +10 Volt
# the actual offset seams to be lmited to -2.5 to +2.5
# round to nearest 0.01 value
offset=int(round(offset*100))+1000
self.__sendwritecmd(jds6600.OFFSET1+channel-1, offset)
# end set offset
# set dutcycle
def setdutycycle(self, channel, dutycycle):
if type(channel) != int: raise TypeError(channel)
if (type(dutycycle) != int) and (type(dutycycle) != float): raise TypeError(dutycycle)
if not (channel in (1,2)): raise ValueError(channel)
# dutycycle is between 0 and 100 %
if not (0 <= dutycycle <= 100):
raise ValueError(dutycycle)
# round to nearest 0.1 value
dutycycle=int(round(dutycycle*10))
self.__sendwritecmd(jds6600.DUTYCYCLE1+channel-1,dutycycle)
# end set dutycycle
# set phase
def setphase(self,phase):
if (type(phase) != int) and (type(phase) != float):
raise TypeError(phase)
# hase is between -360 and 360
if not (-360 <= phase <= 360):
raise ValueError(phase)
if phase < 0:
phase += 3600
# round to nearest 0.1 value
phase=int(round(phase*10))
self.__sendwritecmd(jds6600.PHASE,phase)
# end getphase
#######################
# Part 4: reading / changing mode
# get mode
def getmode(self):
mode=self.__getdata(jds6600.MODE)
# mode is in the list "modes". mode-name "" means undefinded
mode=int(mode)>>3
try:
(modeid,modetxt)=jds6600.__modes[mode]
except IndexError:
raise UnexpectedValueError(mode)
# modeid 3 is not valid and returns an id of -1
if modeid >= 0:
return modeid,modetxt
# end if
# modeid 4
raise UnexpectedValueError(mode)
# end getmode
# set mode
def setmode(self,mode, nostop=False):
if (type(mode) != int) and (type(mode) != str): raise TypeError(mode)
modeid=-1
# if mode is an integer, it should be between 0 and 9
if type(mode) == int:
if not (0 <= mode <= 9):
raise ValueError(mode)
# end if
# modeid 3 / modetxt "" does not exist
if mode == 3:
raise ValueError("mode 3 does not exist")
# end if
# valid modeid
modeid = mode
else:
# modeid 3 / modetxt "" does not exist
if mode == "":
raise ValueError("mode 3 does not exist")
# end if
# mode is string -> check list
# (note: the modes-list is not enumerated like the other lists, so an "array.index("text")" search is not possible
for mid,mtxt in jds6600.__modes:
if mode.upper() == mtxt:
# found it!!!
modeid=mid
break
# end if
else:
# mode not found -> error
raise ValueError(mode)
# end for
# end else - if
# before changing mode, disable all actions (unless explicitally asked not to do)
if nostop == False:
self.__setaction("STOP")
# endif
# set mode
self.__sendwritecmd(jds6600.MODE,modeid)
# if new mode is "burst", reset burst counter
if modeid == 9:
self.burst_resetcounter()
# end if
# end setmode
#######################
# Part 5: functions common for all modes
def stopallactions(self):
# just send stop
self.__setaction("STOP")
# end stop all actions
#######################
# Part 6: "measure" mode
# get coupling parameter (measure mode)
def measure_getcoupling(self):
coupling=self.__getdata(jds6600.MEASURE_COUP)
try:
return (coupling,jds6600.__measure_coupling[coupling])
except IndexError:
raise UnexpectedValueError(coupling)
# end try
# end get coupling (measure mode)
# get gate time (measure mode)
# get (measure mode)
def measure_getgate(self):
gate=self.__getdata(jds6600.MEASURE_GATE)
# gate unit is 0.01 seconds
return gate / 100
# end get gate (measure mode)
# get Measure mode (freq or period)
def measure_getmode(self):
mode=self.__getdata(jds6600.MEASURE_MODE)
try:
return (mode,jds6600.__measure_mode[mode])
except IndexError:
raise UnexpectedValueError(mode)
# end try
# end get mode (measure)
# set measure coupling
def measure_setcoupling(self,coupling):
# type checks
if (type(coupling) != int) and (type(coupling) != str): raise TypeError(coupling)
if type(coupling) == int:
# coupling is 0 (DC) or 1 (AC)
if not (coupling in (0,1)):
raise ValueError(coupling)
coupl=coupling
else:
# string based
coupling=coupling.upper()
# spme shortcuts:
if coupling == "AC": coupling = "AC(EXT.IN)"
if coupling == "DC": coupling = "DC(EXT.IN)"
try:
coupl=jds6600.__measure_coupling.index(coupling)
except ValueError:
errmsg="Unknown measure-mode coupling: "+coupling
raise ValueError(errmsg)
# end try
# end else ) if (type is int or str?)
# set mode
self.__sendwritecmd(jds6600.MEASURE_COUP,coupl)
# end set measure_coupling
# set gate time (measure mode)
def measure_setgate(self, gate):
# check type
if (type(gate) != int) and (type(gate) != float): raise TypeError(gate)
# gate unit is 0.01 and is between 0 and 10
if not (0 < gate <= 1000):
raise ValueError(gate)
gate = int(round(gate*100))