-
Notifications
You must be signed in to change notification settings - Fork 2
/
FY6xxx.py
1093 lines (978 loc) · 36.3 KB
/
FY6xxx.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
"""
Module: FY6xxx FeelElec FY6800 serial communication protocol library
Version: 0.1
Date: 17Feb2019
Author: Nikki Cooper
For documentation issue the following on the command line:
pydoc FY6xxx
Licensed under the GPL v3 by Nikki Cooper.
"""
import serial
"""
Any differences between the FY6800 and the FY6600 are likely to be in one or all
of the following arrays. Everything else should be transparent.
"""
waveForms = ("Sine", "Square", "CMOS", "Adj Pulse", "DC", "Triangle",
"Ramp", "Negative Ramp", "Stair Triangle", "Stairstep",
"Negative Stairstep", "Positive Exponent", "Negative Exponent",
"Positive Falling Exponent", "Negative Falling Exponent",
"Positive Logrithm", "Negative Logrithm", "Positive Falling Logrithm",
"Negative Falling Logrithm", "Positive Full Wave", "Negative Full Wave",
"Positive Half Wave", "Negative Half Wave", "Lorentz Pulse", "Multitone",
"Random Noise", "ECG", "Trapezoidal Pulse", "Sinc Pulse", "Impulse",
"Gauss White Noise", "AM", "FM", "Chirp")
Ch1WaveForms = {'Sine': '00', 'Square': '01', 'CMOS': '02', 'Adj Pulse': '03', 'DC': '04', 'Triangle': '05',
'Ramp': '06', 'Negative Ramp': '07', 'Stair Triangle': '08', 'Stairstep': '09',
'Negative Stairstep': '10', 'Positive Exponent': '11', 'Negative Exponent': '12',
'Positive Falling Exponent': '13', 'Negative Falling Exponent': '14',
'Positive Logrithm': '15', 'Negative Logrithm': '16', 'Positive Falling Logrithm': '17',
'Negative Falling Logrithm': '18', 'Positive Full Wave': '19', 'Negative Full Wave': '20',
'Positive Half Wave': '21', 'Negative Half Wave': '22', 'Lorentz Pulse': '23',
'Multitone': '24', 'Random Noise': '25', 'ECG': '26', 'Trapezoidal Pulse': '27',
'Sinc Pulse': '28', 'Impulse': '29', 'Gauss White Noise': '30', 'AM': '31',
'FM': '32', 'Chirp': '33'}
Ch2WaveForms = {'Sine': '00', 'Square': '01', 'CMOS': '02', 'DC': '03', 'Triangle': '04',
'Ramp': '05', 'Negative Ramp': '06', 'Stair Triangle': '07', 'Stairstep': '08',
'Negative Stairstep': '09', 'Positive Exponent': '10', 'Negative Exponent': '11',
'Positive Falling Exponent': '12', 'Negative Falling Exponent': '13',
'Positive Logrithm': '14', 'Negative Logrithm': '15', 'Positive Falling Logrithm': '16',
'Negative Falling Logrithm': '17', 'Positive Full Wave': '18', 'Negative Full Wave': '19',
'Positive Half Wave': '20', 'Negative Half Wave': '21', 'Lorentz Pulse': '22',
'Multitone': '23', 'Random Noise': '24', 'ECG': '25', 'Trapezoidal Pulse': '26',
'Sinc Pulse': '27', 'Impulse': '28', 'Gauss White Noise': '29', 'AM': '30',
'FM': '31', 'Chirp': '32'}
class FY6XXX_Serial(object):
def __init__(self, device=None, muteexceptions=False, readtimeout=1, writetimeout=0.25):
"""
Create a serial port object based on the FY6xxx device
:param device: string. Valid serial port such as "/dev/ttyUSB1"
:param muteexceptions: bool. Mute serial port open / read / write exceptions.
"""
self.device = device
self.muteexceptions = muteexceptions
self.port = serial.Serial(port=None, baudrate=115200,
bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, rtscts=False, dsrdtr=False,
xonxoff=False, timeout=readtimeout, write_timeout=writetimeout)
self.response = ''
self.LF = "\n"
self.cmd = ''
try:
self.port.port = self.device
if self.device is not None:
self.port.open()
except (Exception, e):
if not self.muteexceptions:
print(str(e))
exit(255)
if self.port.isOpen():
try:
self.port.reset_input_buffer()
self.port.reset_output_buffer()
except (Exception, e):
if not self.muteexceptions:
print("Error communicating... " + str(e))
self.port.close()
exit(254)
return
def __del__(self):
if self.port.isOpen():
self.port.close()
def read(self, size):
"""
read size number of bytes from serial device
:param size: integer
:return: the data read from serial device
"""
self.response = self.port.read(size)
return self.response
def readline(self):
"""
Read data from serial device until 1 of following occurs:
1. An 0xa (LF)is detected in data stream
2. serial.timeout seconds has elapsed
serial.timeout can be adjusted by specifying readtimeout=
:return: The data read from serial device
"""
self.port.reset_input_buffer()
# self.port.flush()
self.response = self.port.read_until(size=20)
return self.response
def write(self, cmd):
"""
Write data to the serial device
:return: integer, if write timeout is configured for the port and the time is exceeded.
"""
self.cmd = cmd + self.LF
self.port.reset_input_buffer()
self.port.write(self.cmd.encode())
self.port.flush()
return
def close(self):
"""
Closes the open serial port device
:return: None
"""
if self.port.isOpen():
self.port.close()
return
def flushinput(self):
"""
flushes the serial input buffers
:return: None
"""
self.port.reset_input_buffer()
return
class FY6800(object):
def __init__(self, device=None, printsettings=None, muteexceptions=False, readtimeout=1, writetimeout=0.25):
"""
Setup serial port the FY6800 is connected as and contains all the
necessary methods in order to read / write information to the FY6800
:param device: string, Serial port device such as /dev/ttyUSB1
:param printsettings: bool, Print serial port parameters and exit program
:param muteexceptions: bool, Mute printing of serial port exception errors to console
:param readtimeout: float, Set the read data from serial device timeout in sec. def: 1 sec
:param writetimeout: float, Set the write data to serial device timeout in sec. def: 0.25 sec
:return 0: Normal exit code
:return 255: Error opening serial device
:return 254: Error while reading or writing to / from serial device
:return 253: Serial port device was not specified. Default: None
:return 252: printsettings=True return code
Example invocation: fy6800 = FY6xxx.FY6800("/dev/ttyUSB1")
fy6800 = FY6XXX.FY6800(printsettings=True)
fy6800 = FY6XXX.FY6800("/dev/ttyUSB1",muteexceptions=True)
fy6800 = FY6XXX.FY6800("/dev/ttyUSB1", readtimeout=-0.80)
"""
self.printSettings = printsettings
self.LF = "\n"
self.settings = {'port': device, 'baudrate': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1,
'xonxoff': False, 'rtscts': False, 'dsrdtr': False, 'timeout': readtimeout,
'write_timeout': writetimeout, 'inter_byte_timeout': None}
if self.printSettings is not None:
for key, value in self.settings.items():
print(key, value)
exit(252)
if device is None:
print("device was specified as None. Use a valid serial port such as /dev/ttyUSB1")
exit(253)
self.fy6800 = FY6XXX_Serial(device, muteexceptions, readtimeout, writetimeout)
self.arbitrary = 0
self.cmd = ''
self.res = 0.0
self.freq = ''
self.response = ''
self.waveIndx = 0
self.waveForms = waveForms
self.Ch1WaveForms = Ch1WaveForms
self.Ch2WaveForms = Ch2WaveForms
return
# Ch 1 waveforms #
def getCh1Wave(self):
"""
Read the current waveform for channel 1
:return: integer index value for self.waveForms
"""
self.cmd = "RMW"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def getCh1WaveDesc(self):
"""
Read the current waveform descriptor for channel 1
:return: string, key from self.waveForms
"""
self.cmd = "RMW"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
if self.response > 33:
self.arbitrary = self.response - 33
if self.arbitrary < 10:
self.response = "Arbitrary 0" + str(self.arbitrary)
else:
self.response = "Arbitrary " + str(self.arbitrary)
return self.response
else:
return self.waveForms[self.response]
def setCh1Wave(self, waveindx):
"""
Set the active waveform for channel 1
:param waveindx: integer. Index to waveform in self.waveForms
:return: 0xa
"""
if waveindx < 10:
self.waveIndx = "0" + str(waveindx)
else:
self.waveIndx = str(waveindx)
self.cmd = "WMW" + self.waveIndx
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def setCh1WaveByKey(self, key):
"""
Set the active waveform by key value
:param key:string defined in self.Ch1WaveForms
:return: 0xa
"""
self.waveIndx = self.Ch1WaveForms[key]
self.cmd = "WMW" + self.waveIndx
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1WaveFreq(self):
"""
Read the frequency of current waveform set in channel 1
:return: string. The frequency in Hz
"""
self.cmd = "RMF"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def setCh1WaveFreq(self, freq):
"""
Set the waveform on channel 1
:param freq: 14 character string in Hz
:return: 0xa
"""
self.freq = freq
self.cmd = "WMF" + self.freq
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1WaveAmplitude(self):
"""
Read the amplitude of the waveform set in channel 1
:return: float, amplitude in volts
"""
self.cmd = "RMA"
self.fy6800.write(self.cmd)
self.response = (float(self.fy6800.readline()) / 10000.0)
return self.response
def setCh1WaveAmplitude(self, amplitude):
"""
Set the amplitude of the channel 1 waveform
:param amplitude: string in the form of x.xx
:return: 0xa
"""
self.cmd = "WMA" + amplitude
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1WaveOffset(self):
"""
Read channel 1 waveform offset voltage
:return: float, offset voltage in volts.
"""
self.cmd = "RMO"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline())
self.res = (self.response - 4294967296) / 1000.0
return self.res
def setCh1WaveOffset(self, offset):
"""
Set the channel 1 waveform offset voltage
:param offset: string in the form of x.xx
:return: 0xa
"""
self.cmd = "WMO" + offset
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1WavePhase(self):
"""
Read channel 1 waveform phase
:return: float, the phase in degrees
"""
self.cmd = "RMP"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline()) / 1000.0
return self.response
def setCh1WavePhase(self, phase):
"""
Set channel 1 waveform phase
:param phase: string in form of x.xx degrees
:return: 0xa
"""
self.cmd = "WMP" + phase
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1WaveDutyCycle(self):
"""
Read channel 1 waveform duty cycle percentage
:return: float representing duty cycle in percent
"""
self.cmd = "RMD"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline()) / 1000.0
return self.response
def setCh1WaveDutyCycle(self, dcycle):
"""
Set channel 1 waveform duty cycle percentage
:param dcycle: string in form of x.xx percent
:return: 0xa
"""
self.cmd = "WMD" + dcycle
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh1Status(self):
"""
Read the current enabled / disabled status of channel 1
:return: integer, 0 = disabled, 1 = enabled
"""
self.cmd = "RMN"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setCh1Status(self, status):
"""
Set the channel 1 enabled / disabled status
:param status: bool, 0 = disabled, 1 = enabled
:return: 0xa
"""
self.cmd = "WMN" + str(status)
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def setCh1WavePulsePeriod(self, period):
"""
Set the pulse period of the channel 1 waveform
:param period: string representing the period
:return: 0xa
"""
self.cmd = "WMS" + period
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
# Ch2 waveforms #
def getCh2Wave(self):
"""
Read the current waveform for channel 1
:return: integer index value for self.waveForms
"""
self.cmd = "RFW"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
"""
NOTE: There are some differences between the Ch1 wave table
and the Ch2 wave tables. For waves >= 3, the offset is
off by one, thus 1 is added to the index to get the values
to match. Therefore values returned by getCh1Wave() and getCh2Wave()
are NOT the same. This is a bug in the firmware.
getCh1WaveDesc and getCh2WaveDesc account for this.
"""
def getCh2WaveDesc(self):
"""
Read the current waveform descriptor for channel 2
:return: string, key from self.waveForms
"""
self.cmd = "RFW"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
if self.response >= 3:
self.response += 1
if self.response > 33:
self.arbitrary = self.response - 33
if self.arbitrary < 10:
self.response = "Arbitrary 0" + str(self.arbitrary)
else:
self.response = "Arbitrary " + str(self.arbitrary)
return self.response
else:
return self.waveForms[self.response]
def setCh2Wave(self, waveindx):
"""
Set the active waveform for channel 2
:param waveindx: integer. Index to waveform in self.waveForms
:return: 0xa
"""
if waveindx < 10:
self.waveIndx = "0" + str(waveindx)
else:
self.waveIndx = str(waveindx)
self.cmd = "WFW" + self.waveIndx
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def setCh2WaveByKey(self, key):
"""
Set the channel 2 active waveform by key value
:param key: string defined in self.Ch2WaveForms
:return: 0xa
"""
self.waveIndx = self.Ch2WaveForms[key]
self.cmd = "WFW" + self.waveIndx
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2WaveFreq(self):
"""
Read the frequency of current waveform set in channel 2
:return: string. The frequency in Hz
"""
self.cmd = "RFF"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def setCh2WaveFreq(self, freq):
"""
Set the waveform on channel 2
:param freq: string, 14 characters in Hz
:return: 0xa
"""
self.cmd = "WFF" + freq
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2WaveAmplitude(self):
"""
Read the amplitude of the waveform set in channel 2
:return: float, amplitude in volts
"""
self.cmd = "RFA"
self.fy6800.write(self.cmd)
self.response = self.fy6800.read(6)
self.amplitude = float(self.response) / 10000.0
return self.amplitude
def setCh2WaveAmplitude(self, amplitude):
"""
Set the amplitude of the channel 2 waveform
:param amplitude: string in the form of x.xx
:return: 0xa
"""
self.cmd = "WFA" + amplitude
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2WaveOffset(self):
"""
Read channel 2 waveform offset voltage
:return: float, offset voltage in volts.
"""
self.cmd = "RFO"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline())
self.res = (self.response - 4294967296) / 1000.0
return self.res
def setCh2WaveOffset(self, offset):
"""
Set the channel 2 waveform offset voltage
:param offset: string in the form of x.xx
:return: 0xa
"""
self.cmd = "WFO" + offset
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2WavePhase(self):
"""
Read channel 2 waveform phase
:return: float, the phase in degrees
"""
self.cmd = "RFP"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline()) / 1000.0
return self.response
def setCh2WavePhase(self, phase):
"""
Set channel 2 waveform phase
:param phase: string in form of x.xx degrees
:return: 0xa
"""
self.cmd = "WFP" + phase
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2WaveDutyCycle(self):
"""
Read channel 2 waveform duty cycle percentage
:return: float representing duty cycle in percent
"""
self.cmd = "RFD"
self.fy6800.write(self.cmd)
self.response = float(self.fy6800.readline()) / 1000.0
return self.response
def setCh2WaveDutyCycle(self, dcycle):
"""
Set channel 2 waveform duty cycle percentage
:param dcycle: string in form of x.xx percent
:return: 0xa
"""
self.cmd = "WFD" + dcycle
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCh2Status(self):
"""
Read the current enabled / disabled status of channel 2
:return: integer, 0 = disabled, 1 = enabled
"""
self.cmd = "RFN"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setCh2Status(self, status):
"""
Set the channel 2 enabled / disabled status
:param status: bool, 0 = disabled, 1 = enabled
:return: 0xa
"""
self.cmd = "WFN" + str(status)
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
# System Settings commands #
def loadParams(self, position):
"""
Load system configuration
:param position: string, representing saved positions 01 - 20
:return: 0xa
"""
self.cmd = "ULN" + position
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def saveParams(self, position):
"""
Save system configuration into position
:param position: string respresnting position to save to 01 - 20
:return: 0xa
"""
self.cmd = "USN" + position
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def addSyncMode(self, syncobj):
"""
Add synchronization mode
:param syncobj: string, one of:
0 = Set Waveform of CH2 sync'ed with CH1
1 = Set Frequency of CH2 sync'ed with CH1
2 = Set Amplitude of CH2 sync'ed with CH1
3 = Set Offset of CH2 sync'ed with CH1
4 = Set Duty Cycle of CH2 sync'ed with CH1
:return: 0xa
NOTE: This function not available in sweep status
"""
self.cmd = "USA" + syncobj
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def cancelSyncMode(self, syncobj):
"""
Cancel synchronization mode
:param syncobj: string, one of:
0 = Cancel Waveform of CH2 sync'ed with CH1
1 = Cancel Frequency of CH2 sync'ed with CH1
2 = Cancel Amplitude of CH2 channel sync'ed with CH1
3 = Cancel Offset of CH2 sync'ed with CH1
4 = Cancel Duty Cycle of CH2 sync'ed with CH1
:return: 0xa
"""
self.cmd = "USD" + syncobj
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getSyncInfo(self, syncobj):
"""
Read synchronization information
:param syncobj: string, one of:
0 = Read Waveform sync info
1 = Read Frequency sync info
2 = Read Amplitude sync info
3 = Read Offset sync info
4 = Read Duty Cycle sync info
:return: integer, one of:
0 = disabled
255 = enabled
"""
self.cmd = "RSA" + syncobj
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def getBuzzerStatus(self):
"""
Read the buzzer on/off status
:return: integer, 0 = disabled, 1 = enabled
"""
self.cmd = "RBZ"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
if self.response == 255:
self.response = 1
return self.response
def setBuzzerStatus(self, status):
"""
Set buzzer on/off
:param status: bool, 0 = off, 1 = on
:return: x0a
"""
self.cmd = "UBZ" + str(status)
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getUplinkMode(self):
"""
Read uplink mode.
:return: integer: 0 = master
255 = slave .
"""
self.cmd = "RMS"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setUplinkMode(self, mode):
"""
Set uplink mode
:param mode: string, 0 = master, 1 = slave
:return: x0a
"""
self.cmd = "UMS" + mode
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getUplinkStatus(self):
"""
Read the uplink on/off status.
:return: integer, 0 = off, 1 = on
"""
self.cmd = "RUL"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
if self.response == 255:
self.response = 1
return self.response
def setUplinkStatus(self, status):
"""
Set uplink on/off
:param status: bool, 0 = off, 1 = on
:return: x0a
"""
self.cmd = "UUL" + str(status)
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getID(self):
"""
Read serial number of the instrument
:return: string, instrument serial number
"""
self.cmd = "UID"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getModel(self):
"""
Read model number of instrument
:return: string, model number of instrument.
"""
self.cmd = "UMO"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
# Modulation commands #
def getTrigger(self):
"""
Read trigger mode of channel 1 waveform.
:return: integer, one of:
0 = No trigger
1 = CH1 waveform triggered by CH2 waveform
2 = CH1 waveform triggered by ExT.in connector
3 = CH1 waveform triggered manually (one shot triggering)
"""
self.cmd = "RPM"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setTrigger(self, triggersrc):
"""
Set trigger mode of channel 1 waveform.
:triggersrc: integer, one of:
0 = Trigger disabled
1 = CH1 waveform triggered by CH2 waveform
2 = CH1 waveform triggered by ExT.in connector
3 = CH1 waveform triggered manually (one shot triggering)
The CH1 waveform is triggered each time command is sent.
:return: x0a
"""
self.cmd = "WPM" + triggersrc
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def readPulseTrigger(self):
"""
Read pulse number of CH1 waveform
:return: string respresenting the pulse number.
"""
self.cmd = "RPN"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def setPulseTrigger(self, pulseamt):
"""
Set pulse number of CH1 waveform when triggered. Limits how many cycles
of the CH1 waveform will ouput.
:param pulseamt: string representing pulse number from 1 to 1048575
:return:
"""
self.cmd = "WPN" + pulseamt
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getASKmode(self):
"""
Read ASK modulation mode
:return: integer, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation.
"""
self.cmd = "RTA"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setASKmode(self, mode):
"""
Set ASK modulation mode of CH1 waveform
:param mode: string, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation
:return: x0a
"""
self.cmd = "WTA" + mode
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getFSKmode(self):
"""
Read FSK modulation mode
:return: integer, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation.
"""
self.cmd = "RTF"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setFSKmode(self, mode):
"""
Set FSK modulation mode of CH1 waveform
:param mode: string, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation
:return: x0a
"""
self.cmd = "WTF" + mode
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getFSKsecondaryFreq(self):
"""
Read FSK secondary frequency.
:return: string, representing the FSK secondary frequency in Hz
"""
self.cmd = "RFK"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def setFSKsecondaryFreq(self, freq):
"""
Set secondary frequency of CH1 waveform FSK
:param freq: string, representing the FSK secondary frequency in Hz
:return: 0xa
"""
self.cmd = "WFK" + freq
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getPSKmode(self):
"""
Read PSK modulation mode
:return: integer, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation.
"""
self.cmd = "RTP"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.readline())
return self.response
def setPSKmode(self, mode):
"""
Set PSK modulation mode of CH1 waveform
:param mode: string, one of:
0 = Normal output without trigger
1 = Modulation mode of external signal input
2 = Manual modulation
:return: x0a
"""
self.cmd = "WTP" + mode
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
# Frequency counter measurement commands #
def setCounterCouplingMode(self, mode):
"""
Set frequency counter coupling mode
:param mode: string, one of:
0 = DC coupling
1 = AC coupling
:return: x0a
"""
self.cmd = "WCC" + mode
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def getCounterFreq(self):
"""
Read frequency counter frequency
:return: string, representing the frequency in Hz
"""
self.cmd = "RCF"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getCounterCnt(self):
"""
Read frequency counter count value.
:return: string, representing the count value.
"""
self.cmd = "RCC"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def resetCounterCnt(self):
"""
Reset frequency counter count value.
:return: x0a
"""
self.cmd = "WCZ0"
self.fy6800.write(self.cmd)
return hex(ord(self.fy6800.read(1)))
def pauseCounter(self, status):
"""
Pause frequency counter measurement.
:param: status: string, one of:
0 = pause
1 = unpause
:return: string, one of:
current counter count if status = 0
0x0a = unpaused if status = 1.
"""
self.cmd = "WCP" + status
self.fy6800.write(self.cmd)
if status == "0":
response = self.fy6800.readline()
return response.strip(self.LF)
else:
self.fy6800.flushinput()
return hex(ord(self.fy6800.read(1)))
def getCounterCntPeriod(self):
"""
Read frequency counter counting period.
:return: string, representing counting period in ns
"""
self.cmd = "RCT"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getCounterPosPulseWidth(self):
"""
Read frequency counter Positive Pulse Width
:return: string, representing width of positive pulse in ns.
"""
self.cmd = "RC+"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getCounterNegPulseWidth(self):
"""
Read frequency counter Negative Pulse Width
:return: string, representing width of negative pulse in ns.
"""
self.cmd = "RC-"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getCounterDutyCycle(self):
"""
Read frequency counter Duty Cycle.
:return: string, representing duty cycle in percent
"""
self.cmd = "RCD"
self.fy6800.write(self.cmd)
self.response = self.fy6800.readline()
return self.response.decode().strip(self.LF)
def getCounterGateTime(self):
"""
Read frequency counter gate time.
:return: integer, one of:
0 = 1Sec
1 = 10sec
2 = 100sec
"""
self.cmd = "RCG"
self.fy6800.write(self.cmd)
self.response = int(self.fy6800.read(1))
return self.response
def setCounterGateTime(self, time):
self.cmd = "WCG" + time
self.fy6800.write(self.cmd)