LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Notifier/while loop question

Solved!
Go to solution

I've got an issue which probably has a simple answer but which has been eluding me for a couple of days.  I've got two loops running in parallel: one which sends commands to an embedded controller over serial and another which reads the return data from the controller.  I want the 'send' loop and the 'read' loop to run at their own rates, but I only want the data read in the 'read' loop to write to an excel file after the 'GO' command is sent until the 'Stop' command is sent. 

 

I've tried using notifiers from the 'send' loop to the 'read' loop to tell the 'read' loop when to output the excel file, but that only slows down the 'read' loop to run whenever it receives the notifier.  I want the 'read' to run all the time, but only to write to the excel file duing the time period between the 'GO' and "Stop" commands.  Does anyone have a better suggestion?

0 Kudos
Message 1 of 11
(3,772 Views)

The simplest thing, although not the most recommended method, might be to use a local variable (I reckon I'll get shouted down for suggesting this!)

 

Place True into a boolean shift register in the write loop whenever you wish for the read loop to export data to file. Make sure that an indicator is connected to this data within the write loop. Then, within the read loop, use a local variable to read from that indicator. When True - write data to file, when False - don't write to file. This might work for you, and could be the simplest implementation.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 11
(3,770 Views)

Well, the only way I can put an indicator on the boolean shift register so that it will actually be useful in the program is on the left hand side, and the indicator only updates after each iteration of the 'while' loop, so that won't help.  Unless I'm misunderstanding you.  Also, I can't wire two boolean statements to the same register without some sort of clumsy code. 

 

This is my latest, varying on the theme you suggested.  When I put a local variable from the 'send' loop iteration counter into the 'read' loop, it updated a full second later, which is too slow. I'll have to see how this works.

0 Kudos
Message 3 of 11
(3,756 Views)
Solution
Accepted by topic author PRCalDude

PRCalDude wrote:

I've tried using notifiers from the 'send' loop to the 'read' loop to tell the 'read' loop when to output the excel file, but that only slows down the 'read' loop to run whenever it receives the notifier. I want the 'read' to run all the time, but only to write to the excel file duing the time period between the 'GO' and "Stop" commands. Does anyone have a better suggestion?


You're on the right track, but the Wait On Notification function in your 'read' loop can be given a timeout value of zero ms and it'll keep ticking along without waiting for a new notification. You can use the 'timed out?' output to decide to use the last value (which you'll store in a Shift Register, the notification output is the default for the data type when the Wait times out) or the latest notification. Like this:

 

 

And, although I'd prefer to never see a Local Variable again, I won't shout Thoric down. He meant well 🙂

Message Edited by jcarmody on 05-22-2009 08:28 PM
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 4 of 11
(3,752 Views)
That is a thing of beauty.  I'll give it a try.  Thanks!
0 Kudos
Message 5 of 11
(3,745 Views)
I think it's working right now.  Is this what you meant?
0 Kudos
Message 6 of 11
(3,733 Views)

Yep. The only thing you might consider is to initialize the Shift Register as False so you don't write data until the top loop sends a notification.

 

I took the liberty to clean up your BD and make a few notes:

 

1) remove Sequence structures, use error cluster to enforce data-flow
2) don't ignore errors, handle them
3) your top loop won't end the way you've wired the Loop Condition. It's
not ideal to use the error to stop a loop but NI does it and it works.
4) it does fit on one screen!

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 11
(3,702 Views)

jcarmody,

 

Do you think you could re-save that file in LV 8.5?  That's the version I'm currently running.  I'll make the changes you suggested.

 

0 Kudos
Message 8 of 11
(3,653 Views)
Also, is it possible to merge error clusters?  I've got one for the notifier and one for the VISA.  I'd like to enforce data flow with the 'write' statements in the top loop, so I wired the error cluster for the notifier into and out of the 2 'send notification' functions.  Now the error cluster from the 'get notifier' does nothing.  I removed the sequence structures though.  
0 Kudos
Message 9 of 11
(3,649 Views)
attached
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 10 of 11
(3,646 Views)