05-22-2009 05:43 PM
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?
Solved! Go to Solution.
05-22-2009 05:50 PM
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.
05-22-2009 07:47 PM
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.
05-22-2009 08:23 PM - edited 05-22-2009 08:28 PM
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 🙂
05-22-2009 08:29 PM
05-22-2009 09:14 PM
05-23-2009 04:44 PM
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!
05-26-2009 11:33 AM
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.
05-26-2009 11:43 AM
05-26-2009 11:49 AM