99import numpy as np
1010from picosdk .ps6000a import ps6000a as ps
1111from picosdk .PicoDeviceEnums import picoEnum as enums
12+ from picosdk .PicoDeviceStructs import picoStruct as structs
1213import matplotlib .pyplot as plt
1314from picosdk .functions import adc2mV , assert_pico_ok
15+ from picosdk .constants import PICO_STATUS
1416
1517# Create chandle and status ready for use
1618chandle = ctypes .c_int16 ()
3638for x in range (1 , 7 , 1 ):
3739 channel = x
3840 status ["setChannel" ,x ] = ps .ps6000aSetChannelOff (chandle ,channel )
39- assert_pico_ok (status ["setChannel" ,x ])
41+ assert_pico_ok (status ["setChannel" ,x ])
42+
43+
44+ # Set number of samples to be collected
45+ noOfPreTriggerSamples = 100000
46+ noOfPostTriggerSamples = 900000
47+ nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples
48+
49+ # Set simple trigger on channel A, 1 V rising with 1 s autotrigger
50+ # handle = chandle
51+ # enable = 1
52+ source = channelA
53+ # threshold = 1000 mV
54+ direction = enums .PICO_THRESHOLD_DIRECTION ["PICO_RISING" ]
55+ # delay = 0 s
56+ # autoTriggerMicroSeconds = 1000000 us
57+ status ["setSimpleTrigger" ] = ps .ps6000aSetSimpleTrigger (chandle , 1 , source , 1000 , direction , 0 , 1000000 )
58+ assert_pico_ok (status ["setSimpleTrigger" ])
59+
60+ # create buffers
61+ maxBuffers = 10
62+
63+ for i in range (0 ,9 ):
64+ bufferA (i ) = (ctypes .c_int16 * nSamples )()
65+
66+
67+ # Set data buffers
68+ # handle = chandle
69+ # channel = channelA
70+ # bufferMax = bufferAMax
71+ # bufferMin = bufferAMin
72+ # nSamples = nSamples
73+ dataType = enums .PICO_DATA_TYPE ["PICO_INT16_T" ]
74+ waveform = 0
75+ downSampleMode = enums .PICO_RATIO_MODE ["PICO_RATIO_MODE_RAW" ]
76+ clear = enums .PICO_ACTION ["PICO_CLEAR_ALL" ]
77+ add = enums .PICO_ACTION ["PICO_ADD" ]
78+ action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"]
79+ status ["setDataBuffers" ] = ps .ps6000aSetDataBuffer (chandle , channelA , ctypes .byref (bufferA (0 )), nSamples , dataType , waveform , downSampleMode , action )
80+ assert_pico_ok (status ["setDataBuffers" ])
81+
82+ # Run streaming
83+ sampleInterval = 1
84+ sampleIntervalTimeUnits = enums .PICO_TIME_UNITS ["PICO_US" ]
85+ autoStop = 0
86+ downSampleRatio = 1
87+
88+ status ["runStreaming" ] = ps .ps6000aRunStreaming (chandle , ctypes .byref (sampleInterval ), sampleIntervalTimeUnits , noOfPreTriggerSamples , noOfPostTriggerSamples , autoStop , downSampleRatio , downSampleMode )
89+ assert_pico_ok (status ["runStreaming" ])
90+
91+ streamData = structs .PICO_STREAMING_DATA_INFO [channelA , downSampleRatio , dataType , 0 , 0 , 0 , 0 ]
92+
93+ streamTrigger = structs .PICO_STREAMING_DATA_TRIGGER_INFO [0 ,0 ,0 ]
94+
95+ count = 1
96+
97+ picoOk = PICO_STATUS ["PICO_OK" ]
98+
99+ while count <= maxBuffers :
100+
101+ status ["getStreamingLatestValues" ] = ps .ps6000aGetStreaminglatestValues (chandle , ctypes .byref (streamData ), 1 , ctypes .byref (streamTrigger )
102+
103+ if status ["getStreamingLatestValues" ] == picoOk :
104+ else
105+ count = count + 1
106+ if count <= maxBuffers :
107+ status ["setDataBuffer" ] = ps .ps6000aSetDataBuffer (chandle , channelA , ctypes .byref (bufferA (count - 1 )), nSamples , dataType , waveform , downSampleMode , action )
108+ print (count )
109+
110+ print ("streaming finished" )
111+
112+ # get max ADC value
113+ # handle = chandle
114+ minADC = ctypes .c_int16 ()
115+ maxADC = ctypes .c_int16 ()
116+ status ["getAdcLimits" ] = ps .ps6000aGetAdcLimits (chandle , resolution , ctypes .byref (minADC ), ctypes .byref (maxADC ))
117+ assert_pico_ok (status ["getAdcLimits" ])
118+
119+ # convert ADC counts data to mV
120+ bufferAmV = adc2mV (bufferA , channelRange , maxADC )
121+
122+ # Close the scope
123+ status ["closeunit" ] = ps .ps6000aCloseUnit (chandle )
124+ assert_pico_ok (status ["closeunit" ])
125+
126+ print (status )
0 commit comments