Hi there,
This video would be useful for anyone using PicoScope within Python.
The code can be found the at following :-
https://github.com/colinoflynn/pico-python
Enjoy and Have a great day.
Kindest regards,
Stuart
PicoScope FFT via Python
Re: PicoScope FFT via Python
Hi Stuart,
Thanks for posting this it has been the source of inspiration for some work that I am doing but have an issue that is proving difficult to overcome and I think I'm probably just missing something simple. I'm using Python with a 3205a picoscope, I've written a class for it similar to what you have done but specifically for the 3205a and not using the generic base class.
I have a buffer set up of length 1250000 with a timebase of 2(8ns) and I'm running block mode (without aggregation) based on the programmers guide with channel A enabled and B disabled. It all works but only half the buffer is filled I've attached and figure with the plots for 2 cycles of runBlock(). Any Ideas why only half the buffer is being filled?
P.S. the capture is a high pass filtered mains signal through a diff probe
Best Regards
Martin
Thanks for posting this it has been the source of inspiration for some work that I am doing but have an issue that is proving difficult to overcome and I think I'm probably just missing something simple. I'm using Python with a 3205a picoscope, I've written a class for it similar to what you have done but specifically for the 3205a and not using the generic base class.
I have a buffer set up of length 1250000 with a timebase of 2(8ns) and I'm running block mode (without aggregation) based on the programmers guide with channel A enabled and B disabled. It all works but only half the buffer is filled I've attached and figure with the plots for 2 cycles of runBlock(). Any Ideas why only half the buffer is being filled?
P.S. the capture is a high pass filtered mains signal through a diff probe
Best Regards
Martin
-
- Advanced User
- Posts: 2856
- Joined: Tue May 31, 2011 3:43 pm
- Location: St. Neots, Cambridgeshire
Re: PicoScope FFT via Python
Hi Martin,
Are you using Average or Decimate downsampling?
What are the parameters that you are setting when calling the following functions:
Are you using Average or Decimate downsampling?
What are the parameters that you are setting when calling the following functions:
- ps3000aSetDataBuffer
- ps3000aRunBlock
- ps3000aGetValues
Hitesh
Software Dev. Engineer
Software Dev. Engineer
Re: PicoScope FFT via Python
Hi Hitesh,
As far as I know I'm not using any downsampling, if I am it's not intentional. Here are the functions in my python class that calls the DLL using ctypes:
def setDataBuffer(self, channel, buffer):
""" the buffer should be a numpy array """
buffer_p = buffer.ctypes.data_as(POINTER(c_short))
bufferLth = len(buffer)
status = self.pico.ps3000aSetDataBuffer(self.handle,c_short(self.CHANNEL[channel]),
buffer_p,c_long(bufferLth),
c_ushort(0),c_short(0))
if status!=0:
raise IOError('There was a problem setting the data buffer')
def runBlock(self, preTriggerSamples,postTriggerSamples,timebase):
timeIndisposedMS = POINTER(c_long)()
parameter = c_void_p()
status = self.pico.ps3000aRunBlock(self.handle,
c_long(preTriggerSamples),c_long(postTriggerSamples),
c_ulong(timebase),c_short(0),
timeIndisposedMS,c_ushort(0),
c_void_p(),parameter)
if status!=0:
raise IOError('There was a problem running block mode')
def getValues(self, noOfSamples):
noOfSamples = c_long(noOfSamples)
overflow = c_short()
status = self.pico.ps3000aGetValues(self.handle,c_ulong(0),byref(noOfSamples),
c_ulong(0),c_short(0),c_ushort(0),
byref(overflow))
if status!=0:
raise IOError('There was a problem getting the values: status:',status)
return (noOfSamples.value,overflow.value)
setDataBuffer is passed 'A' which subsequently selects 0 from a python dictionary and an empty numpy array:
buffer = np.empty(nSamples,dtype=np.long) where nSamples is set to 1250000 # I've also tried much smaller values
RunBlock is passed 0, nSamples and and the timebase set to 3 # I've also tried much larger values
GetValues is passed nSamples
Thanks in advance.
Martin
As far as I know I'm not using any downsampling, if I am it's not intentional. Here are the functions in my python class that calls the DLL using ctypes:
def setDataBuffer(self, channel, buffer):
""" the buffer should be a numpy array """
buffer_p = buffer.ctypes.data_as(POINTER(c_short))
bufferLth = len(buffer)
status = self.pico.ps3000aSetDataBuffer(self.handle,c_short(self.CHANNEL[channel]),
buffer_p,c_long(bufferLth),
c_ushort(0),c_short(0))
if status!=0:
raise IOError('There was a problem setting the data buffer')
def runBlock(self, preTriggerSamples,postTriggerSamples,timebase):
timeIndisposedMS = POINTER(c_long)()
parameter = c_void_p()
status = self.pico.ps3000aRunBlock(self.handle,
c_long(preTriggerSamples),c_long(postTriggerSamples),
c_ulong(timebase),c_short(0),
timeIndisposedMS,c_ushort(0),
c_void_p(),parameter)
if status!=0:
raise IOError('There was a problem running block mode')
def getValues(self, noOfSamples):
noOfSamples = c_long(noOfSamples)
overflow = c_short()
status = self.pico.ps3000aGetValues(self.handle,c_ulong(0),byref(noOfSamples),
c_ulong(0),c_short(0),c_ushort(0),
byref(overflow))
if status!=0:
raise IOError('There was a problem getting the values: status:',status)
return (noOfSamples.value,overflow.value)
setDataBuffer is passed 'A' which subsequently selects 0 from a python dictionary and an empty numpy array:
buffer = np.empty(nSamples,dtype=np.long) where nSamples is set to 1250000 # I've also tried much smaller values
RunBlock is passed 0, nSamples and and the timebase set to 3 # I've also tried much larger values
GetValues is passed nSamples
Thanks in advance.
Martin
-
- Advanced User
- Posts: 2856
- Joined: Tue May 31, 2011 3:43 pm
- Location: St. Neots, Cambridgeshire
Re: PicoScope FFT via Python
Hi Martin,
A couple of things to check:
1. Please ensure that you are using the latest version of the ps3000a.dll (available from the SDK or PicoScope 6 installation directory).
2. Ensure that you are using the correct data types - enumerations such as in the call to ps3000aSetDataBuffer should be unsigned 32-bit integers (ulong). Also, in the call to ps3000aGetValues, noOfSamples should be an unsigned 32-bit integer (ulong).
Is noOfSamples equal to the sum of the pre and post trigger samples?
In the line
The array should consists of a set of 'short' (signed 16-bit integers).
Edit:
Please also check the value being passed for the sampleCount parameters in the call to ps3000aGetValues.
This should be on entry the number of samples required.
Hope this helps.
Regards,
A couple of things to check:
1. Please ensure that you are using the latest version of the ps3000a.dll (available from the SDK or PicoScope 6 installation directory).
2. Ensure that you are using the correct data types - enumerations such as in the call to ps3000aSetDataBuffer should be unsigned 32-bit integers (ulong). Also, in the call to ps3000aGetValues, noOfSamples should be an unsigned 32-bit integer (ulong).
Is noOfSamples equal to the sum of the pre and post trigger samples?
In the line
Code: Select all
buffer = np.empty(nSamples,dtype=np.long)
Edit:
Please also check the value being passed for the sampleCount parameters in the call to ps3000aGetValues.
This should be on entry the number of samples required.
Hope this helps.
Regards,
Last edited by Hitesh on Thu Oct 16, 2014 12:30 pm, edited 1 time in total.
Reason: Additional information to check.
Reason: Additional information to check.
Hitesh
Software Dev. Engineer
Software Dev. Engineer