-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpython3.patch
9519 lines (9463 loc) · 376 KB
/
python3.patch
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
Index: labtoolsuite-0.1/Labtools/achan.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/achan.py
+++ labtoolsuite-0.1/Labtools/achan.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import numpy as np
gains=[1,2,4,5,8,10,16,32]
calfacs={}
@@ -6,7 +8,7 @@ try: #Try and load data from a calibra
for A in calibs.calibs:
calfacs[A] = [np.poly1d(B) for B in calibs.calibs[A]]
except: #Give up and use default calibration instead
- print 'Loading default calibration values'
+ print ('Loading default calibration values')
for n in range(4):
calfacs['CH'+str(n+1)]=[np.poly1d([ 0,-33/1023./gains[a],16.5/gains[a]]) for a in range(8)] #calibrations for all gains , inv channel
for n in ['CH5','CH6','CH7','CH8','CH9']:
Index: labtoolsuite-0.1/Labtools/calibrate_bipolars.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/calibrate_bipolars.py
+++ labtoolsuite-0.1/Labtools/calibrate_bipolars.py
@@ -4,6 +4,8 @@ Connect all inputs to PVS1x2 before star
Author:Jithin
'''
+from __future__ import print_function
+
import numpy as np
import serial,time,string,sys
import struct
@@ -68,7 +70,7 @@ for val in channel_names:
addEntry(val,fits[val],True)
ft=np.poly1d(fits['CH1'][0])
-print 'testing',ft(0),ft(1023)
+print ('testing',ft(0),ft(1023))
f.write('}\n')
@@ -79,14 +81,14 @@ CH2str = struct.pack('3f',*fits['CH2'])
CH3str = struct.pack('3f',*fits['CH3'])
CH4str = struct.pack('3f',*fits['CH4'])
-print CH1str
-print CH2str
-print CH3str
-print CH4str
-
-print struct.unpack('3f',CH1str)
-print struct.unpack('3f',CH2str)
-print struct.unpack('3f',CH3str)
-print struct.unpack('3f',CH4str)
+print (CH1str)
+print (CH2str)
+print (CH3str)
+print (CH4str)
+
+print (struct.unpack('3f',CH1str))
+print (struct.unpack('3f',CH2str))
+print (struct.unpack('3f',CH3str))
+print (struct.unpack('3f',CH4str))
'''
Index: labtoolsuite-0.1/Labtools/commands_proto.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/commands_proto.py
+++ labtoolsuite-0.1/Labtools/commands_proto.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import math,sys,time
ACKNOWLEDGE = 254
@@ -233,7 +235,7 @@ def getfreq(pr2,m,p):
def get_wave_parameters(freq):
T=1.0/freq
m=1;p=0
- #print 'initial guess',closest,a
+ #print ('initial guess',closest,a)
while 1:
pr2=PR2(T,m,p)
a=[int(round(pr2)),m,p]
@@ -247,10 +249,10 @@ def get_wave_parameters(freq):
break
if a[0]<40 or a[0]>255:
- print 'failed. not in range'
+ print ('failed. not in range')
success=False
else:
- print 'final parameters', closest,a
+ print ('final parameters', closest,a)
success=True
return success,closest,a
Index: labtoolsuite-0.1/Labtools/custom_widgets.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/custom_widgets.py
+++ labtoolsuite-0.1/Labtools/custom_widgets.py
@@ -2,6 +2,8 @@
These widgets will be used by the Experiment framework
"""
+from __future__ import print_function
+
import sip,os
os.environ['QT_API'] = 'pyqt'
@@ -20,7 +22,7 @@ from widgets.clickingOptions import Ui_F
class CustomWidgets:
parent=None
def __init__(self):
- print "widgets imported"
+ print ("widgets imported")
self.I=interface.Interface()
Index: labtoolsuite-0.1/Labtools/experiment.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/experiment.py
+++ labtoolsuite-0.1/Labtools/experiment.py
@@ -1,4 +1,6 @@
# Set the QT API to PyQt4
+from __future__ import print_function
+
import os
os.environ['QT_API'] = 'pyqt'
import sip
@@ -34,16 +36,16 @@ import sys
class QIPythonWidget(RichIPythonWidget):
def __init__(self,customBanner=None,*args,**kwargs):
- print 'importing'
+ print ('importing')
from IPython.qt.inprocess import QtInProcessKernelManager
- print 'import #2'
+ print ('import #2')
from IPython.lib import guisupport
if customBanner!=None: self.banner=customBanner
- print 'initializing'
+ print ('initializing')
super(QIPythonWidget, self).__init__(*args,**kwargs)
- print 'kernel manager creating'
+ print ('kernel manager creating')
self.kernel_manager = kernel_manager = QtInProcessKernelManager()
- print 'kernel manager starting'
+ print ('kernel manager starting')
kernel_manager.start_kernel()
kernel_manager.kernel.gui = 'qt4'
self.kernel_client = kernel_client = self._kernel_manager.client()
@@ -163,11 +165,11 @@ class ConvenienceClass():
ph = ((phase)*180/(np.pi))
if(frequency<0):
- #print 'negative frq'
+ #print ('negative frq')
return 0,0,0,0,pcov
if(amplitude<0):
- #print 'AMP<0'
+ #print ('AMP<0')
ph-=180
if(ph<-90):ph+=360
@@ -347,7 +349,7 @@ class Experiment(QMainWindow,template_ex
self.ipyConsole.pushVariables({"I":self.I})
self.ipyConsole.printText("Access hardware using the Instance 'I'. e.g. I.get_average_voltage(0)")
except:
- print 'Device Not Connected.'
+ print ('Device Not Connected.')
def addConsole(self,**args):
dock = QDockWidget()
Index: labtoolsuite-0.1/Labtools/interface.py
===================================================================
--- labtoolsuite-0.1.orig/Labtools/interface.py
+++ labtoolsuite-0.1/Labtools/interface.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import os
os.environ['QT_API'] = 'pyqt'
import sip
@@ -26,2314 +28,2316 @@ class Singleton(type):
return cls._instances[cls]
class Interface(object):
- """
- **Communications library.**
+ """
+ **Communications library.**
+
+ This class contains methods that can be used to interact with the hardware.
- This class contains methods that can be used to interact with the hardware.
+ Initialization does the following
- Initialization does the following
-
- * connects to tty device
- * loads calibration values.
-
- +----------+-----------------------------------------------------------------+
- |Arguments |Description |
- +==========+=================================================================+
- |timeout | serial port read timeout. default = 1s |
- +----------+-----------------------------------------------------------------+
-
- >>> I = Interface(2.0)
- >>> print I
- <interface.Interface instance at 0xb6c0cac>
-
-
- Once you have instantiated this class, its various methods will allow access to all the features built
- into the device.
-
-
- .. raw:: html
-
- <iframe width="100%" height="315" src="videos/lissajous.ogv" frameborder="0" allowfullscreen></iframe>
-
-
-
-
- """
- __metaclass__ = Singleton
-
- def __init__(self,timeout=1.0,**kwargs):
- self.BAUD = 1000000
- self.timebase = 40
- self.MAX_SAMPLES = 3200
- self.samples=self.MAX_SAMPLES
- self.triggerLevel=550
- self.triggerChannel = 0
- self.error_count=0
- self.channels_in_buffer=0
- self.digital_channels_in_buffer=0
-
- #-------------get rid of these=-------
- self.CH1 = 3
- self.CH2 = 0
- self.CH3 = 1
- self.CH4 = 2
- self.CH5 = 4
- self.IN1 = 5
- self.IN2 = 6
- self.SEN = 7
- self.PCS = 8
- self.ID1 = 0
- self.ID2 = 1
- self.ID3 = 2
- self.ID4 = 3
- self.OD1=0
- self.OD2=1
- self.LOW=0
- self.HIGH=1
- self.LMETER = 4
- #-------------get rid of the above=-------
-
- self.digital_channel_names=['ID1','ID2','ID3','ID4','LMETER','CH4']
- self.dchans=[digital_channel(a) for a in range(4)]
- #This array of four instances of digital_channel is used to store data retrieved from the
- #logic analyzer section of the device. It also contains methods to generate plottable data
- #from the original timestamp arrays.
-
- self.streaming=False
- self.achans=[analog_channel(a) for a in ['CH1','CH2','CH3','CH4']]
- self.pga_chip_select_map = {'CH1':1,'CH2':2,'CH3':3,'CH4':4,'CH5':5,'CH6':5,'CH7':5,'CH8':5,'CH9':5,'5V':5,'PCS':5,'9V':5}
- self.analog_gains={'CH1':0,'CH2':0,'CH3':0,'CH4':0}
- self.sensor_list = ['CH5','CH6','CH7','CH8','CH9','5V','PCS','9V']
- self.sensor_gain=0
- self.analog_channel_names=['CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8','CH9','5V','PCS','9V','IN1','SEN','TEMP']
- self.gain_values=[1,2,4,5,8,10,16,32]
- self.sensor_multiplex_channel=0
- self.sensor_multiplex_gain=0
- self.buff=np.zeros(4000)
-
- #--------------------------Initialize communication handler, and subclasses-----------------
- self.H = packet_handler.Handler(**kwargs)
-
- self.I2C = I2C_class.I2C(self.H)
- """
- Sub-Instance I2C of the Interface library contains methods to access devices
- connected to the I2C port.
-
- example::
- >>> I.I2C.start(self.ADDRESS,0) #writing mode
- >>> I.I2C.send(0x01)
- >>> I.I2C.stop()
-
- .. seealso:: :py:meth:`~I2C_class.I2C` for complete documentation
- """
-
- self.SPI = SPI_class.SPI(self.H)
- """
- Sub-Instance SPI of the Interface library contains methods to access devices
- connected to the SPI port.
-
- example::
- >>> I=Interface()
- >>> I.SPI.start('CS1')
- >>> I.SPI.send16(0xAAFF)
- >>> print I.SPI.send16(0xFFFF)
- some number
-
- .. seealso:: :py:meth:`~SPI_class.SPI` for complete documentation
- """
- self.NRF = NRF24L01_class.NRF24L01(self.H)
-
- self.DDS_MAX_FREQ = 0xFFFFFFFL-1 #24 bit resolution
- self.DDS_CLOCK = 1e6 #1 MHz clock
- self.map_reference_clock(7,'wavegen')
- print self.DDS_CLOCK
-
- for a in ['CH1','CH2','CH3','CH4','CH5']: self.set_gain(a,0)
- time.sleep(0.01)
-
-
-
- def __del__(self):
- print 'closing port'
- #try:self.fd.close()
- #except: pass
- #-------------------------------------------------------------------------------------------------------------------#
-
- #|================================================ANALOG SECTION====================================================|
- #|This section has commands related to analog measurement and control. These include the oscilloscope routines, |
- #|voltmeters, ammeters, and Programmable voltage sources. |
- #-------------------------------------------------------------------------------------------------------------------#
-
-
- def capture1(self,ch,ns,tg):
- """
- Blocking call that fetches an oscilloscope trace from the specified input channel
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- ch Channel to select as input. ['CH1'..'CH9','5V','PCS','9V','IN1','SEN']
- ns Number of samples to fetch. Maximum 3200
- tg Timegap between samples in microseconds
- ============== ============================================================================================
-
- .. figure:: ../images/capture1.png
- :width: 400px
- :align: center
- :alt: alternate text
- :figclass: align-center
-
- A sine wave captured and plotted.
-
- Example
-
- >>> from pylab import *
- >>> I=interface.Interface()
- >>> x,y = I.capture1('CH1',3200,1)
- >>> plot(x,y)
- >>> show()
-
-
- :return: Arrays X(timestamps),Y(Corresponding Voltage values)
-
- """
- self.capture_traces(1,ns,tg,ch)
- time.sleep(1e-6*self.samples*self.timebase+.01)
- while not self.osciloscope_progress()[0]:
- pass
- return self.fetch_trace(1)
-
- def capture2(self,ns,tg):
- """
- Blocking call that fetches oscilloscope traces from CH1,CH2
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- ns Number of samples to fetch. Maximum 1600
- tg Timegap between samples in microseconds
- ============== ============================================================================================
-
- .. figure:: ../images/capture2.png
- :width: 400px
- :align: center
- :alt: alternate text
- :figclass: align-center
-
- Two sine waves captured and plotted.
-
- Example
-
- >>> from pylab import *
- >>> I=interface.Interface()
- >>> x,y1,y2 = I.capture2(1600,1.25)
- >>> plot(x,y1)
- >>> plot(x,y2)
- >>> show()
-
- :return: Arrays X(timestamps),Y1(Voltage at CH1),Y2(Voltage at CH2)
-
- """
- self.capture_traces(2,ns,tg)
- time.sleep(1e-6*self.samples*self.timebase+.01)
- while not self.osciloscope_progress()[0]:
- pass
- x,y=self.fetch_trace(1)
- x,y2=self.fetch_trace(2)
- return x,y,y2
-
- def capture4(self,ns,tg):
- """
- Blocking call that fetches oscilloscope traces from CH1,CH2,CH3,CH4
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- ns Number of samples to fetch. Maximum 800
- tg Timegap between samples in microseconds. Minimum 1.75uS
- ============== ============================================================================================
-
- .. figure:: ../images/capture4.png
- :width: 400px
- :align: center
- :alt: alternate text
- :figclass: align-center
-
- Four traces captured and plotted.
-
- Example
-
- >>> from pylab import *
- >>> I=interface.Interface()
- >>> x,y1,y2,y3,y4 = I.capture4(800,1.75)
- >>> plot(x,y1)
- >>> plot(x,y2)
- >>> plot(x,y3)
- >>> plot(x,y4)
- >>> show()
-
- :return: Arrays X(timestamps),Y1(Voltage at CH1),Y2(Voltage at CH2),Y3(Voltage at CH3),Y4(Voltage at CH4)
-
- """
- self.capture_traces(4,ns,tg)
- time.sleep(1e-6*self.samples*self.timebase+.01)
- while not self.osciloscope_progress()[0]:
- pass
- x,y=self.fetch_trace(1)
- x,y2=self.fetch_trace(2)
- x,y3=self.fetch_trace(3)
- x,y4=self.fetch_trace(4)
- return x,y,y2,y3,y4
-
- def capture_traces(self,num,samples,tg,channel_one_input='CH1',CH123SA=0,**kwargs):
- """
- Instruct the ADC to start sampling. use fetch_trace to retrieve the data
-
- =================== ============================================================================================
- **Arguments**
- =================== ============================================================================================
- num Channels to acquire. 1/2/4
- samples Total points to store per channel. Maximum 3200 total.
- tg Timegap between two successive samples (in uSec)
- channel_one_input map channel 1 to 'CH1' ... 'CH9'
- \*\*kwargs
-
- * trigger Whether or not to trigger the oscilloscope based on the voltage level set by :func:`configure_trigger`
- =================== ============================================================================================
-
- .. figure:: ../images/transient.png
- :width: 600px
- :align: center
- :alt: alternate text
- :figclass: align-center
-
- Transient response of an Inductor and Capacitor in series
-
- .. _adc_example:
-
- The following example demonstrates how to use this function to record active events.
-
- * Connect a capacitor and an Inductor in series.
- * Connect CH1 to the spare leg of the inductor. Also Connect OD1 to this point
- * Connect CH2 to the junction between the capacitor and the inductor
- * connect the spare leg of the capacitor to GND( ground )
- * set OD1 initially high using set_state(OD1=1)
-
- >>> I.set_state(OD1=1) #Turn on OD1
- >>> time.sleep(0.5) #Arbitrary delay to wait for stabilization
-
- >>> I.capture_traces(2,800,2,trigger=False) #Start acquiring data (2 channels,800 samples, 2microsecond intervals)
- >>> I.set_state(OD1=0) #Turn off OD1. This must occur immediately after the previous line was executed.
- >>> time.sleep(800*2*1e-6) #Minimum interval to wait for completion of data acquisition. samples*timegap*(convert to Seconds)
- >>> x,CH1=I.fetch_trace(1)
- >>> x,CH2=I.fetch_trace(2)
- >>> plot(x,CH1-CH2) #Voltage across the inductor
- >>> plot(x,CH2) ##Voltage across the capacitor
- >>> show()
-
- The following events take place when the above snippet runs
-
- #. The oscilloscope starts storing voltages present at CH1 and CH2 every 2 microseconds
- #. The output OD1 was enabled, and this causes the voltages across the L and C to fluctuate
- #. The data from CH1 and CH2 was read into x,CH1,CH2
- #. Both traces were plotted in order to visualize the Transient response of series LC
-
- :return: nothing
-
- .. seealso::
-
- :func:`fetch_trace` , :func:`osciloscope_progress` , :func:`capture1` , :func:`capture2` , :func:`capture4`
-
- """
- triggerornot=0x80 if kwargs.get('trigger',True) else 0
- self.timebase=tg
- self.H.__sendByte__(ADC)
- if channel_one_input in self.analog_gains:
- self.achans[0].gain = self.analog_gains[channel_one_input]
- elif channel_one_input in self.sensor_list:
- self.achans[0].gain = self.sensor_gain
- else:
- self.achans[0].gain = 0
- self.achans[1].gain = self.analog_gains['CH2']
- self.achans[2].gain = self.analog_gains['CH3']
- self.achans[3].gain = self.analog_gains['CH4']
- CHOSA = self.__calcCHOSA__(channel_one_input)
- if(num==1):
- if(self.timebase<1):self.timebase=1.0
- if(samples>self.MAX_SAMPLES):samples=self.MAX_SAMPLES
-
- self.achans[0].set_params(channel=channel_one_input,length=samples,timebase=self.timebase)
-
- self.H.__sendByte__(CAPTURE_ONE) #read 1 channel
- self.H.__sendByte__(CHOSA|triggerornot) #channelk number
-
- elif(num==2):
- if(self.timebase<1.25):self.timebase=1.25
- if(samples>self.MAX_SAMPLES/2):samples=self.MAX_SAMPLES/2
-
- self.achans[0].set_params(channel=channel_one_input,length=samples,timebase=self.timebase)
- self.achans[1].set_params(channel='CH2',length=samples,timebase=self.timebase)
-
- self.H.__sendByte__(CAPTURE_TWO) #ccapture 2 channels
- self.H.__sendByte__(CHOSA|triggerornot) #channel 0 number
-
-
- elif(num==3 or num==4):
- if(self.timebase<1.75):self.timebase=1.75
- if(samples>self.MAX_SAMPLES/4):samples=self.MAX_SAMPLES/4
- self.achans[0].set_params(channel=channel_one_input,length=samples,timebase=self.timebase)
- for a in range(1,4):
- self.achans[a].set_params(channel=['NONE','CH2','CH3','CH4'][a],length=samples,timebase=self.timebase)
-
- self.H.__sendByte__(CAPTURE_FOUR) #read 4 channels
- self.H.__sendByte__(CHOSA|(CH123SA<<4)|triggerornot) #channel number
-
- self.samples=samples
- self.H.__sendInt__(samples) #number of samples to read
- self.H.__sendInt__(int(self.timebase*8)) #Timegap between samples. 8MHz timer clock
- self.H.__get_ack__()
- self.channels_in_buffer=num
-
- def fetch_trace(self,channel_number):
- """
- fetches a channel(1-4) captured by :func:`capture_traces` called prior to this, and returns xaxis,yaxis
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel_number Any of the maximum of four channels that the oscilloscope captured. 1/2/3/4
- ============== ============================================================================================
-
- :return: time array,voltage array
-
- .. seealso::
-
- :func:`capture_traces` , :func:`osciloscope_progress`
-
- """
- self.__fetch_channel__(channel_number)
- return self.achans[channel_number-1].get_xaxis(),self.achans[channel_number-1].get_yaxis()
-
- def oscilloscope_progress(self):
- """
- returns the number of samples acquired by the capture routines, and the conversion_done status
-
- :return: conversion done,samples acquired
-
- >>> I.start_capture(1,3200,2)
- >>> print I.osciloscope_progress()
- (0,46)
- >>> time.sleep(3200*2e-6)
- >>> print I.osciloscope_progress()
- (1,3200)
-
- .. seealso::
-
- :func:`fetch_trace` , :func:`capture_traces`
-
- """
- conversion_done=0
- samples=0
- try:
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_CAPTURE_STATUS)
- conversion_done = self.H.__getByte__()
- samples = self.H.__getInt__()
- self.H.__get_ack__()
- except:
- print 'disconnected!!'
- #sys.exit(1)
- return conversion_done,samples
-
- def __fetch_channel__(self,channel_number):
- """
- Fetches a section of data from any channel and stores it in the relevant instance of achan()
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel_number channel number (1,2,3,4)
- ============== ============================================================================================
-
- :return: True if successful
- """
- samples = self.achans[channel_number-1].length
- if(channel_number>self.channels_in_buffer):
- print 'Channel unavailable'
- return False
- data=''
- splitting=20
- for i in range(int(samples/splitting)):
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_CAPTURE_CHANNEL)
- self.H.__sendByte__(channel_number-1) #starts with A0 on PIC
- self.H.__sendInt__(splitting)
- self.H.__sendInt__(i*splitting)
- data+= self.H.fd.read(splitting*2) #reading int by int sometimes causes a communication error. this works better.
- self.H.__get_ack__()
-
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_CAPTURE_CHANNEL)
- self.H.__sendByte__(channel_number-1) #starts with A0 on PIC
- self.H.__sendInt__(samples%splitting)
- self.H.__sendInt__(samples-samples%splitting)
- data += self.H.fd.read(2*(samples%splitting)) #reading int by int sometimes causes a communication error. this works better.
- self.H.__get_ack__()
-
- for a in range(samples): self.buff[a] = ord(data[a*2])|(ord(data[a*2+1])<<8)
- self.achans[channel_number-1].yaxis = self.achans[channel_number-1].fix_value(self.buff[:samples])
- return True
-
-
-
- def __fetch_channel_oneshot__(self,channel_number):
- """
- Fetches all data from given channel and stores it in the relevant instance of achan()
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel_number channel number (1,2,3,4)
- ============== ============================================================================================
-
- """
- offset=0
- samples = self.achans[channel_number-1].length
- if(channel_number>self.channels_in_buffer):
- print 'Channel unavailable'
- return False
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_CAPTURE_CHANNEL)
- self.H.__sendByte__(channel_number-1) #starts with A0 on PIC
- self.H.__sendInt__(samples)
- self.H.__sendInt__(offset)
- data = self.H.fd.read(samples*2) #reading int by int sometimes causes a communication error. this works better.
- self.H.__get_ack__()
- for a in range(samples): self.buff[a] = ord(data[a*2])|(ord(data[a*2+1])<<8)
- self.achans[channel_number-1].yaxis = self.achans[channel_number-1].fix_value(self.buff[:samples])
- return True
-
-
-
- def configure_trigger(self,chan,level):
- """
- configure trigger parameters for 10-bit capture commands
- The capture routines will wait till a rising edge of the input signal crosses the specified level.
- The trigger will timeout within 8mS, and capture routines will start regardless.
-
- These settings will not be used if the trigger option in the capture routines are set to False
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- chan channel . 0,1,2 or 3 corresponding to the channels being recorded by the capture routines
- level The voltage level that should trigger the capture sequence(in Volts)
- ============== ============================================================================================
-
- **Example**
-
- >>> I.configure_trigger(0,1.1)
- >>> I.capture_traces(4,800,2)
- >>> I.fetch_trace(1) #Unless a timeout occured, the first point of this channel will be close to 1.1Volts
- >>> I.fetch_trace(2) #This channel was acquired simultaneously with channel 1, so it's triggered along with the first
-
- .. seealso::
-
- :func:`capture_traces` , adc_example_
-
- """
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(CONFIGURE_TRIGGER)
- self.H.__sendByte__(1<<chan) #Trigger channel
- level = 511-31*level*self.gain_values[self.achans[chan].gain]
- if level>1023:level=1023
- elif level<0:level=0
- self.H.__sendInt__(int(level)) #Trigger
- self.H.__get_ack__()
-
-
-
- def set_gain(self,channel,gain):
- """
- set the gain of the selected PGA
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel 'CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8','CH9','5V','PCS','9V'
- gain (0-7) -> (1x,2x,4x,5x,8x,10x,16x,32x)
- ============== ============================================================================================
-
- .. note::
- The gain value applied to a channel will result in better resolution for small amplitude signals.
-
- However, values read using functions like :func:`get_average_voltage` or :func:`capture_traces`
- will not be 2x, or 4x times the input signal. These are calibrated to return accurate values of the original input signal.
-
- >>> I.set_gain('CH1',7) #gain set to 32x on CH1
-
- """
- if channel in self.pga_chip_select_map:
- chan = self.pga_chip_select_map[channel]
- else:
- print 'No amplifier exists on this channel :',channel
- return
-
- if channel in self.analog_gains:
- self.analog_gains[channel] = gain
- elif channel in self.sensor_list:
- self.sensor_gain = gain
- else:
- print "No such channel ",channel,"\n try 'CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8','CH9','5V','PCS','9V' "
- return
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(SET_PGA_GAIN)
- self.H.__sendByte__(chan) #send the channel
- self.H.__sendByte__(gain) #send the gain
- self.H.__get_ack__()
- return self.gain_values[gain]
-
- def write_dac(self,channel,n):
- """
- writes a value(12 bit) to the DAC.
-
- +----------+-----------------------------------------------------------------+
- |Arguments |Description |
- +==========+=================================================================+
- |channel | channel number. |
- + + +
- | | * 0 -> PVS1 (-5 to 5V) |
- + + +
- | | * 1 -> PVS2 (0-3V) |
- +----------+-----------------------------------------------------------------+
- |n | value to set (0-4095) |
- +----------+-----------------------------------------------------------------+
-
- :return: nothing
-
- .. warning:: n should be between 0 and 4095 for both channels. The output voltage will be scaled accordingly.
-
- >>> I.write_dac(0,4095) # pvs1 set to 5Volts
- >>> I.write_dac(0,4095) # pvs1 set to -5Volts
-
- .. seealso::
-
- :func:`set_pvs1` and :func:`set_pvs2`
-
-
- """
- self.H.__sendByte__(DAC) #DAC write coming through.(MCP4922)
- self.H.__sendByte__(SET_PVS1)
- val=(channel<<15)|(1<<14)|(1<<13)|(1<<12)|n #channel-15,buf-14,g-13,on/off-12,value 0-11
- self.H.__sendInt__(val)
- self.H.__get_ack__()
-
- def __selectSensorChannel__(self,channel):
- """
- set the channel of PGA 5
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel channel number. 0-7
- ============== ============================================================================================
-
- """
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(SELECT_PGA_CHANNEL)
- self.H.__sendByte__(channel) #send the channel
- self.H.__get_ack__()
-
-
- def __calcCHOSA__(self,name):
- bipolars=['CH2','CH3','CH4','CH1']
- unipolars=['CH5','CH6','CH7','CH8','CH9','5V','PCS','9V']
- others=['IN1','CHIP SELECT. IGNORE','SEN','TEMP']
- name=name.upper()
- if name in bipolars:
- return bipolars.index(name)
- elif name in unipolars:
- if self.sensor_multiplex_channel != unipolars.index(name):
- self.sensor_multiplex_channel = unipolars.index(name)
- self.__selectSensorChannel__(self.sensor_multiplex_channel)
- return 4
- elif name in others:
- return others.index(name)+5
- else:
- print 'not a valid channel name. selecting CH1'
- return 3
-
-
- def get_average_voltage(self,channel_name,sleep=0):
- """
- Return the voltage on the selected channel
-
- +------------+-----------------------------------------------------------------------------------------+
- |Arguments |Description |
- +============+=========================================================================================+
- |channel_name| 'CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8','CH9','5V','PCS','9V','IN1','SEN','TEMP'|
- +------------+-----------------------------------------------------------------------------------------+
- |sleep | read voltage in CPU sleep mode. not particularly useful. |
- +------------+-----------------------------------------------------------------------------------------+
-
- Example:
-
- >>> print I.get_average_voltage('CH4')
- 0.002
-
- """
- chosa = self.__calcCHOSA__(channel_name)
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_VOLTAGE_SUMMED)
- if(sleep):self.H.__sendByte__(chosa|0x80)#sleep mode conversion. buggy
- else:self.H.__sendByte__(chosa)
- self.H.__getInt__() #2 Zeroes sent by UART. sleep or no sleep :p
- V_sum = self.H.__getInt__()
- #V = [self.H.__getInt__() for a in range(16)]
- #print V
- self.H.__get_ack__()
- V=1023*V_sum/16./4095
- if channel_name in self.analog_gains:
- gain = self.analog_gains[channel_name]
- elif channel_name in self.sensor_list:
- gain = self.sensor_gain
- else:
- gain = 0
- V=calfacs[channel_name][gain](V)
- return V #sum(V)/16.0 #
-
-
-
- def __get_raw_average_voltage__(self,channel_name,sleep=0):
- """
- Return the average of 16 raw 10-bit ADC values of the voltage on the selected channel
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel_name 'CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8','CH9','5V','PCS','9V','IN1','SEN','TEMP'
- sleep read voltage in CPU sleep mode. not particularly useful.
- ============== ============================================================================================
-
- """
- chosa = self.__calcCHOSA__(channel_name)
- self.H.__sendByte__(ADC)
- self.H.__sendByte__(GET_VOLTAGE_SUMMED)
- if(sleep):self.H.__sendByte__(chosa|0x80)#sleep mode conversion. buggy
- else:self.H.__sendByte__(chosa)
- self.H.__getInt__() #2 Zeroes sent by UART. sleep or no sleep :p
- V_sum = self.H.__getInt__()
- self.H.__get_ack__()
- V=1023*V_sum/16./4095
- return V #sum(V)/16.0 #
-
-
-
-
-
- #-------------------------------------------------------------------------------------------------------------------#
-
- #|===============================================DIGITAL SECTION====================================================|
- #|This section has commands related to digital measurement and control. These include the Logic Analyzer, frequency |
- #|measurement calls, timing routines, digital outputs etc |
- #-------------------------------------------------------------------------------------------------------------------#
- def __calcDChan__(self,name):
- """
- accepts a string represention of a digital input ( 'ID1','ID2','ID3','ID4','LMETER','CH4' ) and returns a corresponding number
- """
-
- if name in self.digital_channel_names:
- return self.digital_channel_names.index(name)
- else:
- print ' invalid channel',name,' , selecting ID1 instead '
- return 0
-
- def get_high_freq(self,pin):
- """
- retrieves the frequency of the signal connected to ID1. >10MHz
- also good for lower frequencies, but avoid using it since
- the ADC cannot be used simultaneously. It shares a TIMER with the ADC.
-
- The input frequency is fed to a 32 bit counter for a period of 100mS.
- The value of the counter at the end of 100mS is used to calculate the frequency.
-
- .. seealso:: :func:`get_freq`
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- pin The input pin to measure frequency from. 'ID1' , 'ID2', 'ID3', 'ID4', 'LMETER','CH4'
-
- ============== ============================================================================================
-
- :return: frequency
- """
- self.H.__sendByte__(COMMON)
- self.H.__sendByte__(GET_HIGH_FREQUENCY)
- self.H.__sendByte__(self.__calcDChan__(pin))
- scale=self.H.__getByte__()
- val = self.H.__getLong__()
- self.H.__get_ack__()
- return scale*(val+1)/1.0e-1 #100mS sampling
-
- def get_freq(self,channel='ID1',timeout=0.1):
- """
- Frequency measurement on IDx.
- Measures time taken for 16 rising edges of input signal.
- returns the frequency in Hertz
-
- ============== ============================================================================================
- **Arguments**
- ============== ============================================================================================
- channel The input to measure frequency from. 'ID1' , 'ID2', 'ID3', 'ID4', 'LMETER','CH4'
- timeout This is a blocking call which will wait for one full wavelength before returning the
- calculated frequency.
- Use the timeout option if you're unsure of the input signal.
- returns 0 if timed out
- ============== ============================================================================================
-
- :return float: frequency
-
-
- .. _timing_example:
-
- * connect SQR1 to ID1
-
- >>> I.set_sqr1(2000,500,1) # TODO: edit this function
- >>> print I.get_freq('ID1')
- 4000.0
- >>> print I.r2r_time('ID1') #time between successive rising edges
- 0.00025
- >>> print I.f2f_time('ID1') #time between successive falling edges
- 0.00025
- >>> print I.pulse_time('ID1') #may detect a low pulse, or a high pulse. Whichever comes first
- 6.25e-05
- >>> I.duty_cycle('ID1') #returns wavelength, high time
- (0.00025,6.25e-05)
-
- """
- self.H.__sendByte__(COMMON)
- self.H.__sendByte__(GET_FREQUENCY)
- timeout_msb = int((timeout*64e6))>>16
- self.H.__sendInt__(timeout_msb)
- self.H.__sendByte__(self.__calcDChan__(channel))
- tmt = self.H.__getInt__()
- x=[self.H.__getLong__() for a in range(2)]
- self.H.__get_ack__()
- if(tmt >= timeout_msb):return 0
- freq = lambda t: 16*64e6/t if(t) else 0
- y=x[1]-x[0]
- return freq(y)
-
- def r2r_time(self,channel='ID1',timeout=0.1):
- """
- Returns the time interval between two rising edges
- of input signal on ID1
-
- ============== ============================================================================================
- **Arguments**