-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pico_3a_2w_R2R_Interface_Level.py
1591 lines (1562 loc) · 55.4 KB
/
Pico_3a_2w_R2R_Interface_Level.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
#
# Hardware specific interface functions
# For Arduino pi pico Three analog + 2 R2R AWG + 6 digital channel scope (6-9-2024)
# Written using Python version 3.10, Windows OS
#
try:
import serial
import serial.tools.list_ports
except:
root.update()
showwarning("WARNING","Serial Library not installed?!")
root.destroy()
exit()
#
# adjust for your specific hardware by changing these values in the alice.init file
CHANNELS = 3 # Number of supported Analog input channels
AWGChannels = 2 # Number of supported Analog output channels
PWMChannels = 1 # Number of supported PWM output channels
DigChannels = 6 # Number of supported Dig channels
LogicChannels = 6 # Number of supported Logic Analyzer channels
EnablePGAGain = 0 #
EnableAWGNoise = 0 #
UseSoftwareTrigger = 1
AllowFlashFirmware = 1
Tdiv.set(10)
AWG_Amp_Mode.set(0)
AWGPeakToPeak = 3.26
DevID = "Pico R2R 3"
SerComPort = 'Auto' # or enter explicit come port 'COM22'
TimeSpan = 0.01
ADC_Cal = 3.26
AWGRes = 255 # For 8 bits, 4095 for 12 bits, 1023 for 10 bits
InterpRate = 4
EnableInterpFilter.set(1)
MaxSampleRate = SAMPLErate = 333333*InterpRate
ATmin = 3 # set minimum DAC update rate to 8 uSec
MaxAWGSampleRate = 1.0 / (ATmin / 1000000) # set to 1 / 8 uSec
AWGSampleRate = MaxAWGSampleRate
LSBsizeA = LSBsizeB = LSBsizeC = LSBsize = ADC_Cal/4096.0
PhaseOffset = 12.5
HardwareBuffer = 2048# Max hardware waveform buffer size
MinSamples = 2000 # capture sample buffer size
AWGBuffLen = 2048
Cycles = 1
SMPfft = MinSamples*InterpRate # Set FFT size based on fixed acquisition record length
#
VBuffA = numpy.ones(MinSamples*InterpRate)
VBuffB = numpy.ones(MinSamples*InterpRate)
VBuffC = numpy.ones(MinSamples*InterpRate)
VBuffD = numpy.ones(MinSamples*InterpRate)
VBuffG = numpy.ones(MinSamples*InterpRate)
MBuff = numpy.ones(MinSamples*InterpRate)
MBuffX = numpy.ones(MinSamples*InterpRate)
MBuffY = numpy.ones(MinSamples*InterpRate)
VmemoryA = numpy.ones(MinSamples*InterpRate) # The memory for averaging
VmemoryB = numpy.ones(MinSamples*InterpRate) # The memory for averaging
VmemoryC = numpy.ones(MinSamples*InterpRate)
VmemoryD = numpy.ones(MinSamples*InterpRate)
#
IACMString = "+1.65"
IA_Mode.set(1)
#
## hardware specific Fucntion to close and exit ALICE
def Bcloseexit():
global RUNstatus, Closed, ser
RUNstatus.set(0)
Closed = 1
#
try:
ser.write(b'Gx\n') # Turn off AWG
ser.write(b'sx\n') # turn off PWM
# try to write last config file, Don't crash if running in Write protected space
BSaveConfig("alice-last-config.cfg")
# May need to be changed for specific hardware port
ser.close()
# exit
except:
donothing()
root.destroy()
exit()
#
# Set Scope Sample Rate based on Horz Time Scale
#
def DummySetSampleRate():
global TimeSpan, MaxSampleRate, SHOWsamples, InterpRate, Tdiv
global TrigSource, TriggerEdge, TriggerInt, SAMPLErate, TimeDiv, ser
TimeDiv = UnitConvert(TMsb.get())
#
def SetSampleRate():
global TimeSpan, SHOWsamples, InterpRate, Tdiv
global MaxSampleRate, SAMPLErate, TimeDiv, ser
try:
TimeDiv = UnitConvert(TMsb.get())
except:
pass
#print("TimeDiv = ", TimeDiv)
if TimeDiv < 0.000099:
ser.write(b't3\n') # 90.909 KSPS
elif TimeDiv > 0.000099 and TimeDiv < 0.000199:
ser.write(b't4\n') # 90.909 KSPS
elif TimeDiv > 0.000199 and TimeDiv < 0.0005:
ser.write(b't5\n') # 90.909KSPS
elif TimeDiv >= 0.0005 and TimeDiv < 0.001:
ser.write(b't6\n') # 90.909 KSPS
elif TimeDiv >= 0.001 and TimeDiv < 0.002:
ser.write(b't8\n') # 62.5 KSPS
elif TimeDiv >= 0.002 and TimeDiv < 0.005:
ser.write(b't16\n') # 31.250 KSPS
elif TimeDiv >= 0.005 and TimeDiv < 0.01:
ser.write(b't32\n') # 15.625 KSPS
elif TimeDiv >= 0.01 and TimeDiv < 0.02:
ser.write(b't100\n') # 10 KSPS
elif TimeDiv >= 0.02 and TimeDiv < 0.05:
ser.write(b't200\n') # 5 KSPS
elif TimeDiv >= 0.05 and TimeDiv < 0.10:
ser.write(b't500\n') # 2 KSPS
elif TimeDiv >= 0.1 and TimeDiv < 0.20:
ser.write(b't1000\n') # 1 KSPS
else:
ser.write(b't2000\n') # 500 SPS
#
time.sleep(0.005)
#
#
def only_numerics(seq):
seq_type= type(seq)
return seq_type().join(filter(seq_type.isdigit, seq))
#
# Main function to request and receive a set of ADC samples
#
def Get_Data():
global ShowC1_V, ShowC2_V, ShowC3_V, ShowC4_V
global TgInput, VBuffA, VBuffB, VBuffC, VBuffD, VBuffG
global D0_is_on, D1_is_on, D2_is_on, D3_is_on
global D4_is_on, D5_is_on, D6_is_on, D7_is_on, COLORtrace8
global DBuff0, DBuff1, DBuff2, DBuff3, DBuff4, DBuff5, DBuff6, DBuff7
global D0line, D1line, D2line, D3line, D4line, D5line, D6line, D7line
global TRIGGERentry, TRIGGERsample, SaveDig, CHANNELS, TRACESread
# Get data from Pi Pico + MCP
#
SaveDig = False
if D0_is_on or D1_is_on or D2_is_on or D3_is_on or D4_is_on or D5_is_on or D6_is_on:
SaveDig = True
Get_Dig()
COLORtrace8 = "#800000" # 80% red
else:
SaveDig = False
#
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC3_V.get() == 0:
TRACESread = 2 # A and B
Get_Data_Two()
elif ShowC1_V.get() > 0 and ShowC2_V.get() == 0 and ShowC3_V.get() > 0:
TRACESread = 2 # A and C
Get_Data_Two()
elif ShowC1_V.get() == 0 and ShowC2_V.get() > 0 and ShowC3_V.get() > 0:
TRACESread = 2 # B and C
Get_Data_Two()
elif ShowC1_V.get() > 0 and ShowC2_V.get() == 0 and ShowC3_V.get() == 0:
TRACESread = 1 # A
Get_Data_One()
elif ShowC1_V.get() == 0 and ShowC2_V.get() > 0 and ShowC3_V.get() == 0:
TRACESread = 1 # B
Get_Data_One()
elif ShowC1_V.get() == 0 and ShowC2_V.get() == 0 and ShowC3_V.get() > 0:
TRACESread = 1 # C
Get_Data_One()
elif ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC3_V.get() > 0:
TRACESread = 3 # A and B and C
Get_Data_Three()
elif SaveDig:
pass
else:
return
# do external Gain / Offset calculations before software triggering
if ShowC1_V.get() > 0:
VBuffA = numpy.array(VBuffA)
VBuffA = (VBuffA - InOffA) * InGainA
if ShowC2_V.get() > 0 and CHANNELS >= 2:
VBuffB = numpy.array(VBuffB)
VBuffB = (VBuffB - InOffB) * InGainB
if ShowC3_V.get() > 0 and CHANNELS >= 3:
VBuffC = numpy.array(VBuffC)
VBuffC = (VBuffC - InOffC) * InGainC
#
def Get_Buffer():
global Wait, ser, MaxSampleRate, InterpRate, SAMPLErate
global ABuff, iterCount, SampleTime, MinSamples, TRACESread
time.sleep(Wait)
ratestring = str(ser.readline())
# print("Raw string ", ratestring)
if "stReal=" in ratestring: #
DTime = ratestring.replace("b'stReal=","")
DTime = DTime.replace("\\\\","")
DTime = DTime.replace("r","")
DTime = DTime.replace("n","")
DTime = DTime.replace("\\","")
DTime = DTime.replace("'","")
# print(DTime, UnitConvert(DTime)/MinSamples)
SampleTime = (UnitConvert(DTime)/MinSamples) * 1.0e-6 # convert to uSec
# set actual samplerate from returned time per sample
MaxSampleRate = SAMPLErate = int((1.0/SampleTime)*InterpRate)
# print("Sample Time: ", SampleTime)
# print("Sample Rate = ", SAMPLErate )
#
#StartTime = time.time()
VBuffRaw = []
ABuff = []
time.sleep(Wait*TRACESread)
### Wait to buffer enough samples to satisfy the entire frame
# print("iterCount = ", iterCount)
Count = 0
Chunk = TRACESread * MinSamples
## 1 chan 324, 108, 36
## 2 chan 640, 320, 160
## 3,4 chan 500, 250
ByTwo = 500
ByFour = 250
ByEight = 160
if TRACESread == 2:
ByTwo = 640
ByFour = 320
ByEight = 160
if TRACESread > 1:
Chunk = Chunk + MinSamples
waiting0 = ser.in_waiting
#print("Serial Length:", waiting0)
while waiting0 >= 1:
# print("Number Bytes waiting = ", waiting0)
# read in chunks divisible by 3
# Read an integer as two bytes, big-endian
time.sleep(0.015)
waiting0 = ser.in_waiting
if waiting0 > Chunk:
VBuffRaw = ser.read(Chunk)
Count = Count + Chunk
elif waiting0 > MinSamples:
VBuffRaw = ser.read(MinSamples)
Count = Count + MinSamples
elif waiting0 > ByTwo:
VBuffRaw = ser.read(ByTwo)
Count = Count + ByTwo
elif waiting0 > ByFour:
VBuffRaw = ser.read(ByFour)
Count = Count + ByFour
elif waiting0 > ByEight:
if TRACESread == 2:
VBuffRaw = ser.read(ByEight)
Count = Count + ByEight
else:
VBuffRaw = ser.read(waiting0)
Count = Count + waiting0
else:
VBuffRaw = ser.read(waiting0)
Count = Count + waiting0
# if TRACESread == 4:
# print("Count = ", Count)
# print("Length AB: Raw: ", len(ABuff), len(VBuffRaw))
index = 0
while index < len(VBuffRaw):
ABuff.append(VBuffRaw[index])
index = index + 1
# Count = Count + waiting0
waiting0 = ser.in_waiting
#print("Serial Length:", waiting0)
# time.sleep(Wait)
if Count >= iterCount: # Sample Buffer now full
# print("Count = ", Count, "iterCount = ", iterCount)
break
#print("Frames = ", Frams)
#EndTime = time.time()
#Elapsed = EndTime - StartTime
#print("Elapsed Time = ", Elapsed)
# if TRACESread == 4:
# print("received Bytes = ", Count)
# print("Length: ", len(ABuff))
#
def Get_Dig():
global VBuffA, VBuffB, VBuffC, VBuffD
global ShowC1_V, ShowC2_V, ShowC3_V, ShowC4_V
global LSBsizeA, LSBsizeB, LSBsizeC, LSBsizeD
global LoopBack, LBsb, InterpRate
global MaxSampleRate, SAMPLErate, EnableInterpFilter
global ser, SHOWsamples, TRIGGERsample, TgInput, TimeSpan
global TrigSource, TriggerEdge, TriggerInt, Is_Triggered
global vct_btn, vdt_btn, HoldOff, MinSamples, Interp4Filter
global SaveDig, D0_is_on, D1_is_on, D2_is_on, D3_is_on
global D4_is_on, D5_is_on, D6_is_on, D7_is_on
global DBuff0, DBuff1, DBuff2, DBuff3, DBuff4, DBuff5, DBuff6, DBuff7
global D0line, D1line, D2line, D3line, D4line, D5line, D6line, D7line
SetSampleRate()
Wait = 0.02
#
ser.write(b'0') # capture just dig channels
#
time.sleep(Wait)
ratestring = str(ser.readline())
# print("Raw string ", ratestring)
if "stReal=" in ratestring: #
DTime = ratestring.replace("b'stReal=","")
DTime = DTime.replace("\\\\","")
DTime = DTime.replace("r","")
DTime = DTime.replace("n","")
DTime = DTime.replace("\\","")
DTime = DTime.replace("'","")
# print(DTime, UnitConvert(DTime)/MinSamples)
SampleTime = (UnitConvert(DTime)/MinSamples) * 1.0e-6 # convert to uSec
# set actual samplerate from returned time per sample
MaxSampleRate = SAMPLErate = int((1.0/SampleTime)*InterpRate)
# print("Sample Time: ", SampleTime)
# print("Sample Rate = ", SAMPLErate )
#
iterCount = (MinSamples * 2) # 2 bytes for one channel
#
#StartTime = time.time()
VBuffRaw = []
ABuff = []
time.sleep(Wait)
### Wait to buffer enough samples to satisfy the entire frame
# print("iterCount = ", iterCount)
Count = 0
waiting0 = ser.in_waiting
#print("Serial Length:", waiting0)
while waiting0 >= 1:
# print("Number Bytes waiting = ", waiting0)
# read in chunks divisible by 3
# Read an integer as two bytes, big-endian
time.sleep(0.010)
waiting0 = ser.in_waiting
if waiting0 > MinSamples:
VBuffRaw = ser.read(MinSamples)
Count = Count + MinSamples
elif waiting0 > 324:
VBuffRaw = ser.read(324)
Count = Count + 324
elif waiting0 > 108:
VBuffRaw = ser.read(108)
Count = Count + 108
elif waiting0 > 36:
VBuffRaw = ser.read(36)
Count = Count + 36
else:
VBuffRaw = ser.read(waiting0)
Count = Count + waiting0
# print("Count = ", Count)
# print("Length AB: Raw: ", len(ABuff), len(VBuffRaw))
index = 0
while index < len(VBuffRaw):
ABuff.append(VBuffRaw[index])
index = index + 1
# Count = Count + waiting0
waiting0 = ser.in_waiting
#print("Serial Length:", waiting0)
# time.sleep(Wait)
if Count >= iterCount: # Sample Buffer now full
# print("Count = ", Count, "iterCount = ", iterCount)
break
#
#EndTime = time.time()
#Elapsed = EndTime - StartTime
#print("Elapsed Time = ", Elapsed)
# print("received Bytes = ", Count)
# print("Length: ", len(ABuff))
#
waiting0 = ser.in_waiting
if waiting0 > 0:
# print("Serial Length:", waiting0)
dump = ser.read(waiting0)
#Frams = 0
index = 0
VBuffG = []
# Interpolate
while index < len(ABuff): # build array
pointer = 0
while pointer < InterpRate:
VBuffG.append(ABuff[index])
pointer = pointer + 1
index = index + 1
# Extract Digital buffers if needed
VBuffG = numpy.array(VBuffG) * 1
if SaveDig:
VBuffG = VBuffG.astype(int)
if D0_is_on:
DBuff0 = VBuffG & 1
if D1_is_on:
DBuff1 = VBuffG & 2
DBuff1 = DBuff1 / 2
if D2_is_on:
DBuff2 = VBuffG & 4
DBuff2 = DBuff2 / 4
if D3_is_on:
DBuff3 = VBuffG & 8
DBuff3 = DBuff3 / 8
if D4_is_on:
DBuff4 = VBuffG & 16
DBuff4 = DBuff4 / 16
#
else:
SaveDig = False
DBuff0 = []
DBuff1 = []
DBuff2 = []
DBuff3 = []
DBuff4 = []
DBuff5 = []
DBuff6 = []
DBuff7 = []
#
def Get_Data_One():
global VBuffA, VBuffB, VBuffC, VBuffD, VBuff1
global ShowC1_V, ShowC2_V, ShowC3_V, ShowC4_V
global LSBsizeA, LSBsizeB, LSBsizeC, LSBsizeD
global LoopBack, LBsb, TRACESread, Wait, iterCount
global MaxSampleRate, SAMPLErate, EnableInterpFilter
global ser, SHOWsamples, TRIGGERsample, TgInput, TimeSpan
global TrigSource, TriggerEdge, TriggerInt, Is_Triggered
global vct_btn, vdt_btn, HoldOff, MinSamples, Interp4Filter
global SaveDig, D0_is_on, D1_is_on, D2_is_on, D3_is_on
global D4_is_on, D5_is_on, D6_is_on, D7_is_on
global DBuff0, DBuff1, DBuff2, DBuff3, DBuff4, DBuff5, DBuff6, DBuff7
global D0line, D1line, D2line, D3line, D4line, D5line, D6line, D7line
#
SetSampleRate()
Wait = 0.02
if SAMPLErate <= 4000:
Wait = 0.08
#
if ShowC1_V.get() > 0:
ser.write(b'A0\n') # capture on A1
elif ShowC2_V.get() > 0:
ser.write(b'A1\n') # capture on A2
elif ShowC3_V.get() > 0:
ser.write(b'A2\n') # capture on A3
else:
return
ser.write(b'1') # capture one channel
#
iterCount = (MinSamples * 2) # 2 bytes for one channel
#
Get_Buffer()
#
VBuff1=[]
waiting0 = ser.in_waiting
if waiting0 > 0:
# print("Serial Length:", waiting0)
dump = ser.read(waiting0)
#Frams = 0
index = 0
while index < MinSamples: # len(ABuff)-2:
#Frams = Frams + 1
# Get CH 1 data
inputHigh = ABuff[index]
inputLow = ABuff[index+MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff1.append(data)
index = index + 1
#
VBuffG=[]
#
# Interpolate data samples by 4X
#
index = 0
if ShowC1_V.get() > 0:
VBuffA=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
#
elif ShowC2_V.get() > 0:
VBuffB=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffB.append(float(samp) * LSBsizeB)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffB)
if EnableInterpFilter.get() == 1:
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffB = VBuffB[4:SHOWsamples+4]
#
elif ShowC3_V.get() > 0:
VBuffC=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffC.append(float(samp) * LSBsizeC)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffC)
if EnableInterpFilter.get() == 1:
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffC = VBuffC[4:SHOWsamples+4]
#
elif ShowC4_V.get() > 0:
VBuffD=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffD)
if EnableInterpFilter.get() == 1:
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffD = VBuffD[4:SHOWsamples+4]
#
else:
return
#
def Get_Data_Two():
global VBuffA, VBuffB, VBuffC, VBuffD, ABuff
global ShowC1_V, ShowC2_V, ShowC3_V, ShowC4_V
global LSBsizeA, LSBsizeB, LSBsizeC, LSBsizeD
global LoopBack, LBsb, Wait, iterCount
global MaxSampleRate, SAMPLErate, EnableInterpFilter
global ser, SHOWsamples, TRIGGERsample, TgInput, TimeSpan
global TrigSource, TriggerEdge, TriggerInt, Is_Triggered
global vct_btn, vdt_btn, HoldOff, MinSamples, Interp4Filter
global SaveDig, D0_is_on, D1_is_on, D2_is_on, D3_is_on
global D4_is_on, D5_is_on, D6_is_on, D7_is_on
global DBuff0, DBuff1, DBuff2, DBuff3, DBuff4, DBuff5, DBuff6, DBuff7
global D0line, D1line, D2line, D3line, D4line, D5line, D6line, D7line
#
SetSampleRate()
Wait = 0.015
if SAMPLErate <= 4000:
Wait = 0.08
### send command to readout data
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0: # capture on A1 and A2
ser.write(b'A0\n')
ser.write(b'B1\n')
elif ShowC1_V.get() > 0 and ShowC3_V.get() > 0: # capture on A1 and A3
ser.write(b'A0\n')
ser.write(b'B2\n')
elif ShowC1_V.get() > 0 and ShowC4_V.get() > 0: # capture on A1 and A4
ser.write(b'A0\n')
ser.write(b'B3\n')
elif ShowC2_V.get() > 0 and ShowC3_V.get() > 0: # capture on A2 and A3
ser.write(b'A1\n')
ser.write(b'B2\n')
elif ShowC2_V.get() > 0 and ShowC4_V.get() > 0: # capture on A2 and A4
ser.write(b'A1\n')
ser.write(b'B3\n')
elif ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on A3 and A4
ser.write(b'A2\n')
ser.write(b'B3\n')
else:
return
ser.write(b'2') # capture two channels
#
iterCount = (MinSamples * 4) # 4 bytes for two channels
#
Get_Buffer()
#
VBuff1=[]
VBuff2=[]
waiting0 = ser.in_waiting
if waiting0 > 0:
# print("Serial Length:", waiting0)
dump = ser.read(waiting0)
#Frams = 0
index = 0
while index < MinSamples: # len(ABuff)-2:
#Frams = Frams + 1
# Get CH 1 data
inputHigh = ABuff[index]
inputLow = ABuff[index+MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff1.append(data)
index = index + 1
index = index + MinSamples # skip ahead MinSamples
while index < 3 * MinSamples:
# Get CH 2 data
inputHigh = ABuff[index]
inputLow = ABuff[index+MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff2.append(data)
index = index + 1
#
#print("Frames = ", Frams)
#
VBuffG=[]
#
# Interpolate data samples by 4X
#
index = 0
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0: # capture on A and B
VBuffA=[]
VBuffB=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffB.append(float(samp) * LSBsizeB)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffB = VBuffB[4:SHOWsamples+4]
#
elif ShowC1_V.get() > 0 and ShowC3_V.get() > 0: # capture on A and C
VBuffA=[]
VBuffC=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffC.append(float(samp) * LSBsizeC)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffC = VBuffC[4:SHOWsamples+4]
#
elif ShowC2_V.get() > 0 and ShowC3_V.get() > 0: # capture on B and C
VBuffB=[]
VBuffC=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffB.append(float(samp) * LSBsizeB)
samp = VBuff2[index]
VBuffC.append(float(samp) * LSBsizeC)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffB)
if EnableInterpFilter.get() == 1:
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffB = VBuffB[4:SHOWsamples+4]
VBuffC = VBuffC[4:SHOWsamples+4]
#
elif ShowC1_V.get() > 0 and ShowC4_V.get() > 0: # capture on A and D
VBuffA=[]
VBuffD=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
#
elif ShowC2_V.get() > 0 and ShowC4_V.get() > 0: # capture on B and D
VBuffB=[]
VBuffD=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffB.append(float(samp) * LSBsizeB)
samp = VBuff2[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffB)
if EnableInterpFilter.get() == 1:
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffB = VBuffB[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
#
elif ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on C and D
VBuffC=[]
VBuffD=[]
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffC.append(float(samp) * LSBsizeC)
samp = VBuff2[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffC)
if EnableInterpFilter.get() == 1:
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffC = VBuffC[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
#
else:
return
#
def Get_Data_Three():
global VBuffA, VBuffB, VBuffC, VBuffD, ABuff
global ShowC1_V, ShowC2_V, ShowC3_V, ShowC4_V
global LSBsizeA, LSBsizeB, LSBsizeC
global LoopBack, LBsb, Wait, iterCount
global MaxSampleRate, SAMPLErate, EnableInterpFilter
global ser, SHOWsamples, TRIGGERsample, TgInput, TimeSpan
global TrigSource, TriggerEdge, TriggerInt, Is_Triggered
global vct_btn, vdt_btn, HoldOff, MinSamples, Interp4Filter
global SaveDig, D0_is_on, D1_is_on, D2_is_on, D3_is_on
global D4_is_on, D5_is_on, D6_is_on, D7_is_on
global DBuff0, DBuff1, DBuff2, DBuff3, DBuff4, DBuff5, DBuff6, DBuff7
global D0line, D1line, D2line, D3line, D4line, D5line, D6line, D7line
#
SetSampleRate()
Wait = 0.015
if SAMPLErate <= 4000:
Wait = 0.08
#
# send command to readout data
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC3_V.get() > 0: # capture on A1 A2 and A3
ser.write(b'A0\n')
ser.write(b'B1\n')
ser.write(b'C2\n')
elif ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC4_V.get() > 0: # capture on A1 A2 and A4
ser.write(b'A0\n')
ser.write(b'B1\n')
ser.write(b'C3\n')
elif ShowC2_V.get() > 0 and ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on A2 A3 and A4
ser.write(b'A1\n')
ser.write(b'B2\n')
ser.write(b'C3\n')
elif ShowC1_V.get() > 0 and ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on A1 A3 and A4
ser.write(b'A0\n')
ser.write(b'B2\n')
ser.write(b'C3\n')
else:
#print("none of the cases found?")
return
time.sleep(0.015)
ser.write(b'3') # capture three channels
#
iterCount = (MinSamples * 6) # 6 bytes for three channels
#
Get_Buffer()
#
VBuff1=[]
VBuff2=[]
VBuff3=[]
#
waiting0 = ser.in_waiting
if waiting0 > 0:
# print("Serial Length:", waiting0)
dump = ser.read(waiting0)
#Frams = 0
index = 0
while index < MinSamples: # len(ABuff)-2:
#Frams = Frams + 1
# Get CH 1 data
inputHigh = ABuff[index]
inputLow = ABuff[index+MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff1.append(data)
index = index + 1
index = index + MinSamples # skip ahead MinSamples
while index < 3 * MinSamples:
# Get CH 2 data
inputHigh = ABuff[index]
inputLow = ABuff[index+MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff2.append(data)
index = index + 1
index = index + MinSamples # skip ahead MinSamples
while index < 5 * MinSamples:
# Get CH 3 data
inputHigh = ABuff[index]
inputLow = ABuff[index+ MinSamples]
data = ((inputHigh*256)+inputLow)
VBuff3.append(data)
index = index + 1
#
#print("Frames = ", Frams)
#
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC3_V.get() > 0: # capture on A B and C
VBuffA=[]
VBuffB=[]
VBuffC=[]
#
# Interpolate data samples by 4X
#
index = 0
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffB.append(float(samp) * LSBsizeB)
samp = VBuff3[index]
VBuffC.append(float(samp) * LSBsizeC)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffB = VBuffB[4:SHOWsamples+4]
VBuffC = VBuffC[4:SHOWsamples+4]
if ShowC1_V.get() > 0 and ShowC2_V.get() > 0 and ShowC4_V.get() > 0: # capture on A B and D
VBuffA=[]
VBuffB=[]
VBuffD=[]
#
# Interpolate data samples by 4X
#
index = 0
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffB.append(float(samp) * LSBsizeB)
samp = VBuff3[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffB = VBuffB[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
if ShowC2_V.get() > 0 and ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on B C and D
VBuffB=[]
VBuffC=[]
VBuffD=[]
#
# Interpolate data samples by 4X
#
index = 0
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffB.append(float(samp) * LSBsizeB)
samp = VBuff2[index]
VBuffC.append(float(samp) * LSBsizeC)
samp = VBuff3[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffB)
if EnableInterpFilter.get() == 1:
VBuffB = numpy.pad(VBuffB, (4, 0), "edge")
VBuffB = numpy.convolve(VBuffB, Interp4Filter )
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffB = VBuffB[4:SHOWsamples+4]
VBuffC = VBuffC[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
if ShowC1_V.get() > 0 and ShowC3_V.get() > 0 and ShowC4_V.get() > 0: # capture on A B and D
VBuffA=[]
VBuffC=[]
VBuffD=[]
#
# Interpolate data samples by 4X
#
index = 0
while index < len(VBuff1): # build array
pointer = 0
while pointer < 4:
samp = VBuff1[index]
VBuffA.append(float(samp) * LSBsizeA)
samp = VBuff2[index]
VBuffC.append(float(samp) * LSBsizeC)
samp = VBuff3[index]
VBuffD.append(float(samp) * LSBsizeD)
pointer = pointer + 1
index = index + 1
SHOWsamples = len(VBuffA)
if EnableInterpFilter.get() == 1:
VBuffA = numpy.pad(VBuffA, (4, 0), "edge")
VBuffA = numpy.convolve(VBuffA, Interp4Filter )
VBuffC = numpy.pad(VBuffC, (4, 0), "edge")
VBuffC = numpy.convolve(VBuffC, Interp4Filter )
VBuffD = numpy.pad(VBuffD, (4, 0), "edge")
VBuffD = numpy.convolve(VBuffD, Interp4Filter )
VBuffA = VBuffA[4:SHOWsamples+4]
VBuffC = VBuffC[4:SHOWsamples+4]
VBuffD = VBuffD[4:SHOWsamples+4]
#
# Hardware Help
#
def PrintID():
global ser
ser.write(b'I\n') # request board ID
time.sleep(0.05)
#print("sent I, wating for response")
if ser.in_waiting > 0:
IDstring = str(ser.readline())
ID = IDstring.replace("b'","")
ID = ID.replace("\\\\","")
ID = ID.replace("r","")
ID = ID.replace("n","")
ID = ID.replace("\\","")
ID = ID.replace("'","")
print("ID string ", ID)
#
def SetBufferLength(NewLength):
global ser, MinSamples, MaxSamples, InterpRate, HardwareBuffer
global SMPfft
if NewLength > HardwareBuffer:
NewLength = HardwareBuffer
MinSamples = NewLength
MaxSamples = MinSamples * InterpRate
SMPfft = MaxSamples
CALCFFTwindowshape(SMPfft)
## send Scope Buffer Length
SendStr = 'b' + str(MinSamples) + '\n'
# print(SendStr)
SendByt = SendStr.encode('utf-8')
ser.write(SendByt)
# ser.write(b'b1024\n')
time.sleep(0.005)
#print("set Scope Samples: ", MinSamples)
#
# Hardware Help
#
## try to connect to Arduino Pi Pico board
#
def ConnectDevice():
global SerComPort, DevID, MaxSamples, SAMPLErate, MinSamples, AWGSampleRate
global bcon, FWRevOne, HWRevOne, MaxSampleRate, ser, SHOWsamples
global CH1Probe, CH2Probe, CH1VRange, CH2VRange, TimeDiv
global CHAsb, CHBsb, TMsb, LSBsizeA, LSBsizeB, ADC_Cal, LSBsize
global d0btn, d1btn, d2btn, d3btn, d4btn, d5btn, d6btn, d7btn
# print("SerComPort: ", SerComPort)
if DevID == "No Device" or DevID == "Pico R2R 3":
#
if SerComPort == 'Auto':
ports = serial.tools.list_ports.comports()
for port in ports: # ports:
# print("Port List", port)
# looking for this ID: USB\VID_2E8A&PID_000A