Reading one sample at a time in Compatible streaming mode

Post your C and C++ discussions here

Reading one sample at a time in Compatible streaming mode

Postby atulkumar » Mon Feb 20, 2012 1:22 am

Hi!

I am using a 2204 device and I want to read one sample at a time (every 10ms) in the Compatible streaming mode. So I use ps2000_run_streaming(handle, 10, 1, 0). Now inside a while loop, I read value using ps2000_get_values(handle, &value, NULL, NULL, NULL, &overflow, 1) here value and overflow are defined as short. There is a sleep of 10ms inside the loop (usleep of 10000 us).

The problem I face is as follows. Unless I put a sleep of at least around 300ms after the ps2000_run_streaming and before the start of the loop (i.e., before the invocation of first ps2000_get_values), the return value of ps2000_get_values is zero (i.e., the function does not read any value). With the sleep of 300ms before the loop, it works for few iterations (10 to18 times) and then starts giving return value of zero for next many iterations.

The documentation says that short ps2000_ready is only applicable in the block mode so I assume I dont have to wait for the device/driver to be ready after starting the streaming and before reading a value or between two invocations of ps2000_get_values if there is a sleep of the time equal to the sampling rate.

Is this a driver bug or a limitation of the driver code or device?

Thanks,
Atul
atulkumar
Newbie
 
Posts: 0
Joined: Fri Dec 23, 2011 3:13 am

Re: Reading one sample at a time in Compatible streaming mod

Postby Martyn » Tue Feb 21, 2012 9:03 am

Please can you post your code so that we can take a look at exactly what you are doing.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 1711
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Reading one sample at a time in Compatible streaming mod

Postby atulkumar » Tue Feb 28, 2012 8:45 am

I have a framework for running programs that runs a code segment repeatedly at a desired frequency. The framework allows to have an initialization code segment (the code that runs only once in the beginning) and then the code segment that is executed repeatedly.

The code looks as follows:

/* Initialization part of the code */
// Appropriate data definitions
handle = ps2000_open_unit ();
// Check whether the device opened successfully or not, print device info if opened

ret = ps2000_set_channel(handle, 0, true, true, PS2000_2V);
// check for the return value
ret = ps2000_set_channel(handle, 1, false, true, PS2000_2V);
// check for the return value
ps2000_set_trigger(handle, PS2000_NONE, 0, 0, 0, 0);

ret = ps2000_run_streaming(handle, 10, 1, 0);
// check for the return value
/* end of the initialization code */

/* beginning of the code segment that is executed repeatedly at a frequency of 10ms */

no_of_values = ps2000_get_values(handle, &value, NULL, NULL, NULL, &overflow, 1)
// check for no_of_values, if zero means nothing was read if 1 means one value was read
// do something with the value read

/* end of the code segment that is executed repeatedly */


The problem is as follows. If I dont put a sleep of at least 300ms at the end of the initialization code segment, the repeating code segment reads zero number of values for several iterations. Even after inserting a sleep of 300ms at the end of the initialization code, there are many 'zero values read' during many iterations. And there is no fixed pattern for these missing values.

Thanks,
Atul
atulkumar
Newbie
 
Posts: 0
Joined: Fri Dec 23, 2011 3:13 am

Re: Reading one sample at a time in Compatible streaming mod

Postby Martyn » Tue Feb 28, 2012 11:42 am

Is there any reason why you can't collect a number of samples at a time ?

Collecting a single data value in a loop from the driver at the same rate of 10ms as the data is being collected from the device is likely to fail due to inaccuracies in timings.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 1711
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Reading one sample at a time in Compatible streaming mod

Postby atulkumar » Wed Mar 07, 2012 5:40 am

Its just an experimental setup trying to sample an analog signal where the user program reads the voltage value at the desired time. The best option for this purpose would be to have an API function that just reads a sample value from an input channel when invoked without starting any sampling/streaming-mode beforehand. I can do this with MC USB-1208FS.

Since you mentioned that having the sampling rate and the rate at which the program loops to read the data almost equal may cause a timing problem, can I do it as follows. I set a sampling rate 'n' times faster than the rate at which my program loops. Then when I read, I get the average of the 'n' samples collected since the last 'read' call. I want to do this in the compatible streaming mode as I dont want the 'n' to be very large.
atulkumar
Newbie
 
Posts: 0
Joined: Fri Dec 23, 2011 3:13 am

Re: Reading one sample at a time in Compatible streaming mod

Postby Martyn » Wed Mar 07, 2012 9:47 am

As this is a scope the driver is setup to collect many samples of data and not just individual readings. You can't aggregate data using Compatible Streaming mode however you can with Fast Streaming, so this may provide a better method to achieve your desired results
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 1711
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Reading one sample at a time in Compatible streaming mod

Postby atulkumar » Wed Mar 14, 2012 10:41 am

OK. Lets assume that I use the Fast Streaming mode and aggregate data. Is there is a driver imposed limit on how fast my program can call 'ps2000_get_streaming_values'? Can I call it every mili second?
atulkumar
Newbie
 
Posts: 0
Joined: Fri Dec 23, 2011 3:13 am

Re: Reading one sample at a time in Compatible streaming mod

Postby Martyn » Thu Mar 15, 2012 8:46 am

ps2000_get_streaming_values is called after the streaming has stopped, you would need to be using ps2000_get_streaming_last_values and the callback function my_get_overview_buffers steps 5 to 8 as shown below

This is the general procedure for reading and displaying data in fast streaming mode:
1. Open the oscilloscope using ps2000_open_unit().
2. Select channel ranges and AC/DC switches using ps2000_set_channel().
3. Set the trigger using ps2000_set_trigger().
4. Start the oscilloscope running using ps2000_run_streaming_ns().

5. Get a block of data from the oscilloscope using ps2000_get_streaming_last_values().
6. Display or process the data.
7. If required, check for overview buffer overruns by calling ps2000_overview_buffer_status().
8. Repeat steps 5 to 7 as necessary or until auto_stop is TRUE.


9. Stop fast streaming using ps2000_stop().
10. Retrieve any part of the data at any time scale by calling ps2000_get_streaming_values().
11. If you require raw data, retrieve it by calling ps2000_get_streaming_values_no_aggregation().
12. Repeat steps 10 to 11 as necessary.
13. Close the oscilloscope by calling ps2000_close_unit().
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 1711
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests