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

Stream Read Duration


  • Please log in to reply
14 replies to this topic

#1 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 03 December 2013 - 11:23 PM

Is there a good way to calculate how long it will take for the stream read to translate the data to an array? I was reading one of the older posts and you said somewhere that it could take roughly ~250ms if you are reading once per second. This seems like a huge amount of time especially when compared to the stream rate of 300 samples/seconds for four channels.

 

This means that essentially upwards of 75 samples (per channel) are being missed in the read duration. Someone in the lab has suggested running multiple machines with a lag respective to eachother to pick up on the missing data but it seems to be a bit impractical financially if I'd need to grab another LabJack, however not entirely impossible. What would you suggest to do to eliminate the down time?



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 04 December 2013 - 08:56 AM

I am not following your discussion of missed samples.  In stream mode, all data is collected at the specified interval using a clock in hardware.  You will get all that data, or you will get an error.  You will not have any skipped or missed scans.

 

Are you asking how long it takes AIStreamRead to execute in your loop?  That is, when you call AIStreamRead, how long does it take to return with your data?  It generally depends on fact that AIStreamRead is waiting for the data to be collected, but assuming the data is already collected and waiting in the U12's buffer, a rule-of-thumb for the time in milliseconds is  20 + 0.4*NumSamples.  So if you are reading 1200 samples you can estimate it will take about 500ms to execute that read and move that many samples from the U12 to software.

 

Note that "simple ai stream example.vi" has a delay frame in the read loop so you can simulate processing time.  In the example set ScanRate=300 scans/second, NumberOfScans=300, and NumberOfChannels=4.  That means your sample rate is 300*4 = 1200 samples/second.  Run the example and you should see that it runs continuously and the time per iteration is about 1000ms.  You should see that ScanBacklog is not growing, which tells you that you are keeping up and the U12's buffer is not growing.

 

Now start increasing "milliseconds to delay before reading".  On my machine if I set it to 700ms, ScanBacklog would start to grown.  We are scanning at 300 scans/second and reading 300 scans/read, so know that each loop iteration will take about 1000ms.  With 700ms of delay in the loop, there is only 300ms left for the read function, but the read function takes longer than 300ms so we are not looping fast enough and the ScanBacklog starts to grow.  If I set the delay back to 600ms the loop is able to catch-up and ScanBacklog drops to 0.



#3 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 04 December 2013 - 06:02 PM

Aaah that makes sense I thought that whilst it was reading it the Labjack wasn't gathering samples. This makes much more sense.



#4 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 04 December 2013 - 08:13 PM

How would I go about converting the output of stream into a Waveform(DBL)?



#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 December 2013 - 08:31 AM

This would be a good question for the LabVIEW forums at ni.com.  So as not to confuse people who can help, phrase the question in a pure LabVIEW context:

 

"I have a 2D array of DBL.  It has 4 columns representing 4 different channels, and 300 rows representing scans collected at 300 scans/second.  How do I convert this 2D array to the waveform datatype?"

 

I am not very experienced with the LabVIEW-specific waveform data type, but will take a crack at this and follow up with another post.



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 December 2013 - 09:12 AM

Here I have split off each of the 4 columns/channels from the 2D array and used the Build Waveform block to make a waveform out of each:

 

u12_stream_buildwaveform.jpg



#7 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 05 December 2013 - 05:03 PM

Thank-you so much. So utilizing the count data would be accessed similarly?



#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 06 December 2013 - 09:11 AM

You mean if in AIStreamStart you set readCount=1?  It is a little different then because you need to combine the 2nd through 4th channels to get the 32-bit count.  From Section 4.8 of the U12 User's Guide:

 

readCount – If >0, the current count (CNT) is returned instead of the 2nd, 3rd, and 4th analog input channels. 2nd channel is bits 0-11. 3rd channel is bits 12-23. 4th channel is bits 24-31. This feature was added to the LabJack U12 starting with firmware version 1.03, and this input has no effect with earlier firmware versions.

 

 

See attached example.

Attached Files



#9 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 09 December 2013 - 08:07 PM

Have been getting a weird error that only happens on one computer not the other. Error 27 is maximum number of streams though both are using the same number of streams. Will stick up the code soon.



#10 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 09 December 2013 - 08:37 PM

Here is the VI which is only working on some computers and not others.

Attached Files



#11 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 10 December 2013 - 08:31 AM

We do not have LabVIEW 8.5.  For us to look at your VI, you will have to revert it to 7.1 or just post a screenshot.

 

Errorcode 27 comes from the driver, not actually from the hardware.  The maximum number of streams the driver supports is 1.  That is, the U12 driver can only stream from 1 U12 at a time.  If you call AIStreamStart but it detects that a stream is already going you will get this error.  Perhaps there are situations where your code might not be stopping the previous stream?  If that is the case, you might want to call AIStreamClear before each call to AIStreamStart.

 

Here is an easy way to cause this problem:

 

    - Run "simple ai stream example.vi".  You will see the LED blinking on the U12 indicating that it is streaming.

    - Use the stop-sign in the LabVIEW menu bar (rather than the "Stop" button on the front panel) to abort execution of the VI.  Note that the VI stops, but the LED is still blinking on the U12 so the U12 is still streaming.

    - Run the VI again and you will get the error "Maximum number of streams".



#12 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 10 December 2013 - 02:51 PM

This seems to be a possible cause of the error. Will definitely implement this into the code to see if it fixes it. Thank-you again.



#13 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 10 December 2013 - 06:10 PM

I think what was happening was someone else in the lab was quitting the program whilst it was gathering data directly instead of using the stop button in the code, and as such didn't have time to execute the code.

This fixed the error I was getting but replaced it with Error Code 33. Which was naturally fixed after removing the added clear. I'm not entirely sure of how to design the error 'code'. I'm thinking of comparing my Error Code with the preset for 7 and if the error code is 7 then it will clear and restart.



#14 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 11 December 2013 - 12:13 PM

If I want a new stream to always start, even if one is already going, I will always run AIStreamClear right before AIStreamStart, but I'll route the error cluster around the clear so if the clear throws an error it is ignored.



#15 Samuel Goodall

Samuel Goodall
  • Members
  • 17 posts

Posted 11 December 2013 - 04:28 PM

Hadn't considered that as an approach. Not sure why.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users