Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Streaming and capturing time stamp


  • Please log in to reply
9 replies to this topic

#1 DanT

DanT
  • Members
  • 8 posts

Posted 12 June 2013 - 09:52 AM

I am trying to setup a U6 to capture one channel of analog data streaming at 50KHz and also return the timestamp of the data. I have used the LJStreamUD application as an experiment and it will capture the data I need at 50KHz, although it is a little noisier than I had hoped for. I have something that does streaming, but I am having problems with getting the error message unable to stop streaming, and sometimes it doesn't seem to even start. I have also had problems getting the timer to get the time stamp of the sample. Any advice on the configuration of the buffers and settings is appreciated. I am doing the application in C#.

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 11:56 AM

If you stream a grounded channel or channel 15, you should see noise levels similar to what is documented:

http://labjack.com/s...users-guide/3.2


Does the unmodified stream example work fine for you?


I don't quite understand what you mean by timestamp. The relative time (elapsed time from the start of the stream) is known from scan number and scanrate.

#3 DanT

DanT
  • Members
  • 8 posts

Posted 12 June 2013 - 12:21 PM

I am capturing a very active signal and the data returned appears to have noise that does not show up when I capture the same signal with a scope. This is an issue that I will look at further, but that isn't my primary concern at the moment. The biggest issue I am having is that of reliably capturing the data at 50Khz sample rate. I have played around with my code and I am getting occasional errors from the LabJack, primarily the error is unable to stop the streaming message. I am currently running at 5KHz rate and when I try to go faster, I have even more errors and reaching the point that it doesn't stream at all. If I can get past this problem, then I will tackle the next issues. Thanks,

#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 12:46 PM

Does the unmodified stream example work fine? If so you can see what changes cause problems and post a code snippet or attach the modified code so we can check it out.

#5 DanT

DanT
  • Members
  • 8 posts

Posted 12 June 2013 - 01:07 PM

The declarations for the variables used to set up the streaming are as follows: private int delayms = 3000; private LJUD.IO ioType=0; private LJUD.CHANNEL channel=0; private double dblValue=0, dblCommBacklog=0, dblUDBacklog; private double scanRate = 50000; private double numScans = 20000; //2x the expected # of scans (2*scanRate*delayms/1000) private double numScansRequested; private double[] adblData = new double[25000]; //Max buffer size (#channels*numScansRequested) The rest of the code is based on the example code U6_StreamWindowed with the exception that I am only capturing data on channel 0. If the sample rate is slower, it seems to work ok, but when I go to 50000, I start having it run for a little bit and then getting an error message unable to stop streaming. I have tried increasing the size of adblData, but at some point it still fails. I am also not sure I understand the relationship of the numScans to the operation and its impact on the code. It seems that if it gets too large, something else breaks.

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 01:39 PM

We will try your values. In the meantime, Section 4.3.7 of the U6 User's Guide has details about streaming with the UD driver:

http://labjack.com/s...ers-guide/4.3.7

#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 03:43 PM

Your values will lead to "Buffer overrun while streaming." error. Basically you are not reading data fast enough from the driver and it's stream buffer is overflowing. My guess on the stream stop error is that the driver is busy handling the stream error. You'll want to change these settings to keep streaming stable:

private double numScans = 300000; //2x the expected # of scans (2*scanRate*delayms/1000) = 2 * 50000 * 3000/1000
private double numScansRequested;
private double[] adblData = new double[300000]; //Max buffer size (#channels*numScansRequested
Note that the example sets a five second buffer for 2 channels by default. "numScans" is the number of scans you are reading every "delayms". At a 50000 scan rate for 1 channel (50000 samples/second) in 3 seconds you will have 150000 samples to read. Your old settings were only reading 20000 samples every 3 seconds. The settings I suggest will try to read 300000 samples but will probably only get around 150000 samples. You ask for more than needed and it will help ensure the driver's stream buffer is being cleared and prevent an overflow.

#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 June 2013 - 03:57 PM

I will also point out to keep an eye on exceptions in the MakeReadings function as it will indicate errors from the UD driver. STREAM_BACKLOG_COMM indicates how much data is buffered on the U6 device and STREAM_BACKLOG_UD will indicate how much data is buffered in the UD driver. If either of these are constantly increasing each MakeReadings call that is an indication that you are not reading stream data fast enough from the UD driver and an eventually UD stream buffer overflow will probably occur.

#9 DanT

DanT
  • Members
  • 8 posts

Posted 13 June 2013 - 07:39 AM

I am still struggling to get the streaming to work reliably. I can get things running up to around 5K sample rate, but beyond that, I get different errors, from the unable to stop streaming, to communications failure, etc. The documentation doesn't really help me much either. To stream faster, does the LJ_chSTREAM_READS_PER_SECOND need to be increased from the default of 25? I tried changing it to 100, but then I couldn't get the streaming to work at all. What are good choices for the delay, buffer size, etc for running the streaming at faster rates, such as 10K, 20K, and 50K?

#10 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 13 June 2013 - 08:35 AM

Sounds like perhaps you are using wait mode NONE? I suggest you use SLEEP instead. I find it simpler, and it is what most people want for most applications. The pseudocode in Section 4.3.7 uses wait mode SLEEP:

http://labjack.com/s...ers-guide/4.3.7

does the LJ_chSTREAM_READS_PER_SECOND need to be increased from the default of 25?

No, LJ_chSTREAM_READS_PER_SECOND and LJ_chSTREAM_SAMPLES_PER_PACKET are advanced config parameters typically used for lower-speed low-latency streaming. For example, if someone wants to stream at 1k, but they want 1 scan or sample transferred at a time in the background, rather than the more efficient large packets. The default values are good for streaming at 50k.

What are good choices for the delay, buffer size, etc for running the streaming at faster rates, such as 10K, 20K, and 50K?

Delay: Switch to SLEEP mode, so you will not use any delay at all. The read function will wait until the desired amount of data is ready.

UD Buffer Size: 10 seconds is typical if you are reading data once per second. That gives you some buffer in case the computer is temporarily busy and not reading data fast enough, but not too much buffer to where you are falling behind and don't notice. You could just make the buffer huge if you don't want to think about it. If you just fix it at 1000000, that equates to 20 seconds at the max sample rate of 50k, so you know the buffer is always 20s or more.


The pseudocode in Section 4.3.7 shows a typical SLEEP wait mode stream. You typically read data once or twice a second, so if scanrate is 50k then numScans might be set to 25k before each read call. After each read call I suggest you display STREAM_BACKLOG_UD so you can make sure it is staying near 0 and not growing.


If you still have trouble, I suggest you attach a file or zipped project for us to check out.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users