1313import matplotlib .pyplot as plt
1414from picosdk .functions import adc2mV , assert_pico_ok
1515from picosdk .constants import PICO_STATUS
16+ import time
1617
1718# Create chandle and status ready for use
1819chandle = ctypes .c_int16 ()
3536assert_pico_ok (status ["setChannelA" ])
3637
3738# set channel B-H off
38- for x in range (1 , 7 , 1 ):
39+ for x in range (1 , 7 , 1 ):
3940 channel = x
40- status ["setChannel" ,x ] = ps .ps6000aSetChannelOff (chandle ,channel )
41- assert_pico_ok (status ["setChannel" ,x ])
41+ status ["setChannel" , x ] = ps .ps6000aSetChannelOff (chandle , channel )
42+ assert_pico_ok (status ["setChannel" , x ])
4243
4344
4445# Set number of samples to be collected
6061# create buffers
6162maxBuffers = 10
6263
63- for i in range ( 0 , 9 ):
64- bufferA ( i ) = (ctypes .c_int16 * nSamples )()
64+
65+ bufferA = (( ctypes .c_int16 * nSamples ) * 10 )()
6566
6667print (bufferA )
6768# Set data buffers
7576downSampleMode = enums .PICO_RATIO_MODE ["PICO_RATIO_MODE_RAW" ]
7677clear = enums .PICO_ACTION ["PICO_CLEAR_ALL" ]
7778add = 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 )
79+ action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"]
80+ status ["setDataBuffers" ] = ps .ps6000aSetDataBuffer (chandle , channelA , ctypes .byref (bufferA [0 ]), nSamples , dataType ,
81+ waveform , downSampleMode , action )
8082assert_pico_ok (status ["setDataBuffers" ])
8183
8284# Run streaming
83- sampleInterval = 1
85+ sampleInterval = ctypes . c_double ( 1 )
8486sampleIntervalTimeUnits = enums .PICO_TIME_UNITS ["PICO_US" ]
8587autoStop = 0
8688downSampleRatio = 1
8789
88- status ["runStreaming" ] = ps .ps6000aRunStreaming (chandle , ctypes .byref (sampleInterval ), sampleIntervalTimeUnits , noOfPreTriggerSamples , noOfPostTriggerSamples , autoStop , downSampleRatio , downSampleMode )
90+ status ["runStreaming" ] = ps .ps6000aRunStreaming (chandle , ctypes .byref (sampleInterval ), sampleIntervalTimeUnits ,
91+ noOfPreTriggerSamples , noOfPostTriggerSamples , autoStop ,
92+ downSampleRatio , downSampleMode )
8993assert_pico_ok (status ["runStreaming" ])
9094
91- streamData = structs .PICO_STREAMING_DATA_INFO [ channelA , downSampleRatio , dataType , 0 , 0 , 0 , 0 ]
95+ streamData = structs .PICO_STREAMING_DATA_INFO ( channelA , downSampleRatio , dataType , 0 , 0 , 0 , 0 )
9296
93- streamTrigger = structs .PICO_STREAMING_DATA_TRIGGER_INFO [ 0 , 0 , 0 ]
97+ streamTrigger = structs .PICO_STREAMING_DATA_TRIGGER_INFO ( 0 , 0 , 0 )
9498
9599count = 1
96100
100104
101105while count <= maxBuffers :
102106
103- status ["getStreamingLatestValues" ] = ps .ps6000aGetStreaminglatestValues (chandle , ctypes .byref (streamData ), 1 , ctypes .byref (streamTrigger )
107+ status ["getStreamingLatestValues" ] = ps .ps6000aGetStreamingLatestValues (chandle , ctypes .byref (streamData ), 1 ,
108+ ctypes .byref (streamTrigger ))
104109
105- if status ["getStreamingLatestValues" ] == picoOk
106- else
110+ if status ["getStreamingLatestValues" ] == picoOk :
111+ # do nothing
112+ time .sleep (0.01 )
113+ else :
107114 count = count + 1
108- if count <= maxBuffers
109- status ["setDataBuffers" ] = ps .ps6000aSetDataBuffer (chandle , channelA , ctypes .byref (bufferA (count - 1 )), nSamples , dataType , waveform , downSampleMode , actionB )
110- assert_pico_ok (status ["setDataBuffers" ])
115+ if count <= maxBuffers :
116+ status ["setDataBuffer" ] = ps .ps6000aSetDataBuffer (chandle , channelA , ctypes .byref (bufferA [count - 1 ]),
117+ nSamples , dataType , waveform , downSampleMode , actionB )
118+ assert_pico_ok (status ["setDataBuffer" ])
111119 print (count )
112120
113121print ("streaming finished" )
120128assert_pico_ok (status ["getAdcLimits" ])
121129
122130# convert ADC counts data to mV
123- bufferAmV = adc2mV (bufferA , channelRange , maxADC )
131+ bufferAmV = ((ctypes .c_int16 * nSamples )* 10 )()
132+ for j in range (0 , 9 ):
133+ bufferAmV [j ] = adc2mV (bufferA [j ], channelRange , maxADC )
124134
125135# Close the scope
126136status ["closeunit" ] = ps .ps6000aCloseUnit (chandle )
127137assert_pico_ok (status ["closeunit" ])
128138
129- print (status )
139+ print (status )
0 commit comments