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

Configuring the stream on U6

stream mode u6

  • Please log in to reply
7 replies to this topic

#1 ja090157d

ja090157d
  • Members
  • 5 posts

Posted 11 November 2013 - 03:58 PM

Hello. I'm having difficulties using the stream mode on U6. My situation is: I use 2 analog inputs, and I want to get the data from them at 600 Hz each. Then I need to average 10 samples (from each channel), in order to get 60 Hz of averaged data in the end from each channel. What stream parameters should I use? I tried changing the SimpleStream example to fit my needs, but I couldn't go over 40Hz no matter what I tried.

I'm a complete beginner, sorry if this is a stupid question...



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 November 2013 - 04:16 PM

What language are you using?  What O/S?



#3 ja090157d

ja090157d
  • Members
  • 5 posts

Posted 11 November 2013 - 04:26 PM

I'm using VB.Net on windows 7.



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 November 2013 - 04:49 PM

For background in streaming with the UD driver, see the pseudocode in Section 4.3.7 of the U6 User's Guide:

 

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

 

 

The SimpleStream example for VB.net does 2 channels at 1000 scans/second by default.  The example uses wait mode NONE, and reads stream data in a Timer event that happens every 500ms.  Does this work?

 

Looks to me like all you need to do to scan at 600 scans/second is change scanRate to 600.  Does that work?

 

Next, you want to process that data down to 60 scans/second by averaging each 10 scans.  You could do that using wait mode NONE but it will be a little tricky since you don't know the exact number of scans you will get each time.  It would be easier if you used the SLEEP wait mode.

 

With the SLEEP wait mode, you don't want a delay in the read loop as the read call is blocking.  The other change is that you want to set NUM_SCANS_REQUESTED to the exact number you want ... say 600 to get 600 scans per read which will take about 1 second each time.



#5 ja090157d

ja090157d
  • Members
  • 5 posts

Posted 11 November 2013 - 07:30 PM

Thank you for the quick answer. When I try these changes, it gives me a System.InvalidCastException in this line:
LJUD.eGet(u6.ljhandle, LJUD.IO.GET_STREAM_DATA, LJUD.CHANNEL.ALL_CHANNELS, numScansRequested, adblData)

in both SLEEP and NONE mode. 
Also, I need a sample (which is an average of 10 samples) every 16ms, does that mean I should set READ_INTERVAL to 16?



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 12 November 2013 - 12:36 PM

For your eGet call that gets System.InvalidCastException, make sure numScansRequested is a Double and adbleData is a double array. If that doesn't help the issue, please post your code so we can take a look at it.

 

If you only want to read 10 scans (10 samples for each of the 2 stream channels = 20 samples total) per GET_STREAM_DATA call you will want to set numScansRequested to 10, the READ_INTERVAL to a faster rate than the scan rate, so say 10 ms, and use the SLEEP wait mode. This will help make sure you are reading from the driver's stream buffer at a fast enough rate so it doesn't overflow, and SLEEP mode waits for the exact amount of scans to be available unlike NONE mode. Note to check numScansRequested after your GET_STREAM_DATA calls to see the amount of scans you actually read, and make sure the STREAM_BACKLOG_COMM (U6 hardware's stream buffer) and STREAM_BACKLOG_UD (driver's stream buffer) are not constantly growing as that indicates you are not reading stream data at a fast enough rate.

 

Alternatively if you are reading more scans at a time, every 20 samples (10 scans) in the adblData array is about 16 ms worth of samples for both stream channels.



#7 ja090157d

ja090157d
  • Members
  • 5 posts

Posted 21 November 2013 - 02:59 PM

Thanks, that worked perfectly. Now I am trying to achieve the best resolution possible, is that 16-bit? And what is resolution index (i.e. is it just another term for resolution)? Should I just use this:
LJUD.AddRequest(lngHandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.AIN_RESOLUTION, 16, 0, 0)
to set the resolution of all channels I'm streaming to 16 bits?



#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 21 November 2013 - 04:13 PM

The resolution index is a value from 0-8 that controls the resolution.  We use those values since there are various factors involved (range, etc) that change the resolution you would get.  The higher the resolution index the better the resolution will be.  There is a trade off between how accurate the readings are and the maximum number of samples per second you can collect (since more accurate readings take longer).  Those values can be seen here: http://labjack.com/s...users-guide/3.2

 

On the U6 the range you are using also plays a role, so there are charts for each one.   Basically, you should start with the range you are using and then look at how many samples you are collecting, and choose the highest resolution index that will collect that number of samples.  That will give you the best resolution.  The resolution index (0-8) is what you will pass with the LJUD.CHANNEL.AIN_RESOLUTION





Also tagged with one or more of these keywords: stream mode, u6

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users