LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

report generation write to file at interval

Your first loop (on the far left) only runs once.  That will be the only time you read the DAQ.  You should move the contents of your middle loop into your first loop (enqueue of data when so much time has passed).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 21 of 27
(985 Views)

No, you did not set up your code similar to my example.  Look at my two loops -- they share an input, but not an output.  Thus there is no data dependency between them -- they run in parallel, at the same time, at whatever rate they can.

 

Look at how the Queue is arranged.  It is first created, then the Queue (wire) is branched, one branch going to the Event Structure which only does an Enqueue (puts data onto the Queue), the other branch going to the Consumer loop, which only does the Dequeue (taking data off the Queue).  Finally, one branch of the Queue (at the exit of the Event loop) does the Release/Destroy.

 

In your case, the Producer (middle) loop and the Consumer (third) loop are wired in serial -- the output from the Producer goes to the input of the Consumer.  This means that the Consumer cannot run until the Producer is finished.  The other problem is that you never create the Queue.

 

Try again.  Notice that your real Producer loop is the first loop -- this is where the data are being produced.  If you are going to use Producer/Consumer, you should create the Queue before entering Loop 1, the Enqueue (of each single data point) should be inside this loop (getting rid of the middle loop), and the Consumer should get the other branch of the Queue.  If you put your two loops above and below each other, you are less likely to make the mistake of wiring them in serial.

 

Style is important!  Something as simple as how you place loops on the block diagram (horizontally or vertically) can have an effect on your code (because it encourages or discourages mistakes).

 

Bob Schor

 

0 Kudos
Message 22 of 27
(965 Views)

Ah I see what you mean.

 

Okay so I think I have them in parallel now and the error is gone but the excel file is not being created and the stop button is not ending the whole operation. I'm wondering if this has something to do with the entire report generation located in the case structure and if I need to move the New Report.vi or Save data to Report.vi outside of the case structure/outside of the while loop? I only want the report created once and for the data to be saved every minute and I'm pretty sure the way it's setup is not allowing for this. Any suggestions?

 

0 Kudos
Message 23 of 27
(956 Views)

@kmarcella wrote:

Ah I see what you mean.

 

Okay so I think I have them in parallel now and the error is gone but the excel file is not being created and the stop button is not ending the whole operation. I'm wondering if this has something to do with the entire report generation located in the case structure and if I need to move the New Report.vi or Save data to Report.vi outside of the case structure/outside of the while loop? I only want the report created once and for the data to be saved every minute and I'm pretty sure the way it's setup is not allowing for this. Any suggestions?

 


The general rule is if you want something (like opening and closing a report) done once, do not put it inside a loop.  If you want something done multiple times (like adding entries to a report), put that in a loop.

 

I'm not 100% certain why the loop does not stop when you push the Stop button. It should stop the top loop, which will cause the Queue to be destroyed.  One minor mistake (which I might have made in my example, too) is that the Timeout case in the lower loop should have a Queue Status wired to the Queue, just to provide an error when the Queue is released.  See if that fixes the Stopping problem.  If all else fails, you can turn on the Watch indicator (the light bulb, 5th icon in the Toolbar on the Block Diagram) once the program is running, go to the Front Panel, push Stop, go back to the Block Diagram and see why the Top (or Bottom) loop fails to exit.

 

Have you taken any LabVIEW classes?  Have you taken advantage of the on-line tutorial material?

 

Bob Schor

0 Kudos
Message 24 of 27
(947 Views)

Right. So I put just the section of the report generation that uses the queue data into the while loop. However, I am still getting errors. Can you determine what I am still doing wrong?

I fixed the Stop button error.

 

I have not taken any classes and have read some on-line tutorial but it was all fairly basic and isn't helping my more specific questions. This is my first time programming, hence all the questions.

 

I really appreciate your help and walking me through all of this!

0 Kudos
Message 25 of 27
(937 Views)

You've fixed the major (and obvious) problems -- now the Fun Begins!  How to find the Obscure Bugs.  You say there are errors -- any clue where the errors arise?

 

Here are some suggestions to help you track down the source of the errors.  First, you want to gather the error lines from the two main loops together using Merge Errors, and run the combined error line through the Simple Error Handler (or you could just use an Error Indicator).  Note that the bottom Error line that you used to stop the Consumer loop you can just "leave alone".

 

It's not necessary to run two error lines into the Consumer Loop.   Drop the bottom error line, move the DeQueue up to the upper error line.  Note that if you have only a single Error Line, and you are wiring it to stop the loop, you might consider putting an Error Indicator on it "just to see" that the error it throws is consistant with the error you expect, namely "Missing Queue" (possibly 1122, or 1).   You still don't have the Get Queue Status on the error line in the TimeOut case (to catch the error and force the Consumer loop to close).

 

Try doing the following -- instead of wiring the Stop control, wire the True constant into the Stop indicator of the Producer loop, and also write True to the Enqueue case statement.  This should generate exactly one entry that should go to the Consumer.  If this works, the basic structure is OK.  If there's an error, you need to see where it occurs.  One way to do this is to turn the "Watch" on and watch the data flow -- you are looking for where the Error line stops saying "OK".

 

Do you know about Probes?  You can right-click a wire on the Block Diagram and choose Probe.  Now, when your code executes and hits the Probe, the value on the wire will be recorded.  So if you want to know where an error occurs, put a Probe on the wire between various functions on the error line and see which one first shows the error.  Now you know which function is causing the problem.

 

Let me know what your find.  What do you think is causing the problem?

 

Bob Schor

0 Kudos
Message 26 of 27
(926 Views)

I placed the Get Queue Status before Dequeue and connected it with the error in/out and queue in/out. Is that correct?

And the error I now recieve is " Refnum became invalid while node waited for it." at the Dequeue element which from my research means that the For Loop in the Consumer Loop is not recieving any data. Is this correct?

When I ran with Watch on, the error never seemed to make it into the Consumer loop and I'm not sure why the data is not entering into that loop...

0 Kudos
Message 27 of 27
(895 Views)