03-17-2014 10:24 AM - edited 03-17-2014 10:38 AM
Hi everybody,
I just started to learn labview so please don't judge my messy programming 😉
I want to continously measure some values (humidity, temperature etc.) and once a certain threshold is crossed, i want to activate a device. Measuring and activating stuff works perfectly if used seperately. If i combine it and measure for some time (10 samples to read 100Hz continous mode) I get the Error 200279 "Attempted to read samples that are no longer available".
If I use (100 samples to read 100Hz n samples) It measures for quite some time (manually aborted it after 4 hours) but i recognized that there was a time gap of half an hour between the system timem and the "actual" time shown in the chart.
Ah, and the whole thing is not really time critical. It's enough if it measures one sample per 5 seconds or so!
Is there any quick and dirty solution for that?
Thank your very much in advance,
Hendrik
Solved! Go to Solution.
03-18-2014 04:55 AM
Split you code into 2 Loops - control and prcessor.
Acquire the data in the control loop EnQue it onto a Q in the control loop.
DeQ the Data in the processor Loop and do the anaylsis.
The really critical thing that will immediatley show you a big speed/time improvement is to convert the DAQ express VIs into gererated code (right click), create the task outside the while loop (Control Loop) acquire the data in the loop and close the task at the end of the loop, use Shft registers to pass the wire references throuigh the loop.
avoid the use of globals where possible.
(Open+close DAQ task takes 10x the duration of setting a digital line - I know this is not what you are doing, but this will be a place where you are losing time.)
(Slower crashes don't mean the problem has gone necessarily as you still haven't dealt with the problem!) have a look at some of the examples in the example finder onDAQ acquisition and look for the simple help topics on data flow.
James
03-18-2014 11:21 AM
Dear James,
thank you very much for your help. I changed the program according to your information and tried to build a producer/consumer architecture. Still it won't work as i want it to.
It gives me an error at the dequeue function saying that it has an invalid input. Do you know how to fix it? Also i fear that i will override the queue buffer if i continously write in it but don't clear it.
03-18-2014 11:37 AM
OK you have several problems there especially with having too many queues( Really you only need 1 queue)
The error you are seeing is due to that feedback node stuck haphazardly in the top queue reference. a Ctrl+Space Crtl+R will remove that offence.
Once you get past that you are going to notice that those clear task vi's should not be in the loop at all.
03-20-2014 07:18 AM
Thank you very much! I learned alot in the last few days and i changed the program according to your information.
Still I found to have a time gap in the wafeform charts. I think it's because i load the data faster in the queue and in the shift register than it can process it in the consumer loop.
Is there any possibility to get rid of this? I want to have a synchonized data aquisition and visualization/control loop and i want to automatically erase data that is older than 12h so i don't get a buffer overflow. Since i am still at the beginning of learning labview it would be great if i can get a recommandation on which functions/structure to use.
03-20-2014 08:55 AM
@labviewnewbiehendrik wrote:
Thank you very much! I learned alot in the last few days and i changed the program according to your information.
Still I found to have a time gap in the wafeform charts. I think it's because i load the data faster in the queue and in the shift register than it can process it in the consumer loop.
Is there any possibility to get rid of this? I want to have a synchonized data aquisition and visualization/control loop and i want to automatically erase data that is older than 12h so i don't get a buffer overflow. Since i am still at the beginning of learning labview it would be great if i can get a recommandation on which functions/structure to use.
Well that is a lot nicer! A ctrl+u makes the Block diagram almost readable!
So lets chat about the subtle differences between Charts, Graphs and Shift registers OK?
You are using charts not graphs..... Charts are a memory element like "shift registers" but, with a finite length set from the property "Chart History Length." Set the Chart History length appropriately for your charts and get rid of the Shift Registers on the waveform data. (That is what is killing you with way too much memory consumption)
Once you read up on charts and graphs and shift registers we can talk about that whole case structure polling a boolean User Interface control. What does reading that user input have to do with the data coming in? (Not much right?) That Digital Out Case structure needs to be in its own parallel loop (And look into the help file and examples on using an event structure ---)
03-20-2014 11:36 AM
Ok, i got rid of the shift registers and put the build waveform function inside the control loop. Now the charts work as i thought, but i still don't understand why there is a gap between the measurements as seen on the picture? Do you know how to get rid of those?
03-20-2014 12:23 PM
OK Now we are getting somewhere! Congrats you are coming along fine! Now lets wean you off of the blue wires (Dynamic data type is completely unnecessary)
You are passing an array of waveforms on the queue. Just use an index array to get the elements (Hint :index array is resizable so look at the detailed help on how to use it)
Now you can get rid of all those convert from DDT bullets
You also need to remove the append to waveform functions- You are using charts
Go look at C:\Program Files\National Instruments\LabVIEW 2013\examples\Controls and Indicators\Graphs and Charts\Waveform Graphs and Charts\Waveform Graphs and Charts.lvproj Yup, there are shipping examples that cover this case!
Something like this should result:
Hey did you know you can add a DAQmx Scale to each Channel in a DAQmx Task? That would get rid of all those multiply functions too!
Now lets look at this code:
What is the case structure doing? selecting weather to pass a True or a False to the same sub vi depending on the value on the boolean wire? I think you might just be able to wire the AND output directly to the DAQmx Write and avoid the nastyness of having duplicated code in both cases.... (And you did it several times too.)
We still need to chat about the UI Event loop but, that can wait a bit untill you explore the array functions, and charts
03-20-2014 01:25 PM
Great!! I have the feeling i understand more of the code every hour 😄 (I looked at the small case structure i made earlier this week and though: 'what a mess 😉 '
I improved the code and also used the scale function! The only issue i still have is, that the charts in the consumer loop are a way to slow compared to the producer loop. So that means the enqueue and dequeue function "wastes" time? 😉
How can i get rid of this?
03-20-2014 02:41 PM
I doubt the queue is wasting your time. In fact I would put money on it (Queues are really very fast)
A couple of things COULD be slowing down the UI (User Interface)
First I do not know your sample rate (that sub-vi isn't attached) but you are refreshing 6 graphs if tose chart history lengths are large the refresh can take time Although I doubt that is your issue either.
You are not really using the DAQmx Digital out very well (you should configure and commit the task before the loop starts) and you could use a single task to write all 8 lines. That will greatly speed up the control/ display loop since DAQmx won't have to do all the "Autostart" checking under the hood 16 times per loop iteration. since you have only 1 task and it was defined before the loop all the DAQmx "Magic" happens much less often.