From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wrong data after sub vi executes

Hello,

 

I am working on a control vi that (in part) monitors the status of some solenoids and checks that they have actuated (or not) appropriately.  As part of this, I have created a subVI that reads in if the solenoid is supposed to be active, takes a sample reading, and outputs whether or not the sensors are reading that the solenoid is in the proper position.  In the main VI, I then write to a boolean control via a local variable.  I know, your immediate thought is "another race condition issue"... that might be the case, but please read on.  If it is, I'd love to understand why.

 

The subVI works flawlessly when executed on its own.  It also works correctly when debugging either using highlight execution or with breakpoints and single-stepping through everything.  Using the probe feature and running normally, I know I'm getting the right input to the subVI, but for some reason the subVI then provides me with the wrong output when I probe the other side.  I don't believe it to be a race condition with the local variable, because writing a local variable shouldn't affect the output of my subVI, right?

 

I've attached some snippets of my code... if those aren't enough to get started I can post the entire thing.  However, be warned: this is my first ever LabVIEW project and I'll freely admit that I'm in over my head and I'm still trying to learn good ways of keeping my code clean.

 

Thanks in advance for the help!

Download All
0 Kudos
Message 1 of 9
(2,862 Views)

Please describe what you mean by "wrong data."  Give us an example of what was expected and what you got.

 

Is it always false even if it's supposed to be true?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 9
(2,844 Views)

Bill,

 

Thanks for the reply.  Yes, that's exactly what I'm seeing.  My input to my subVI (Solenoid Active?) is true as it should be.  Therefore, I expect that "Extend" is high and "Retract" is low (focusing on Upper Platen Left, because that's where I saw the problem first).  This ought to give me a True output when the upper platen is extended.  However, when executed normally, my line always shows false (even though the upper platen is clearly extended).

 

Is it possible that I don't give the sensor enough time to settle, that LabVIEW executes that quicker than the solenoid can physically actuate / the sensor can sense?  The solenoid is actuated in the Toggle Relay subVI shown in Main, and then I run directly into checking that the sensors show proper actuation.  Again, since I know the function is working and that during highlight execution and singgle-stepping through the code I get my desired True output, I don't really see what else it could be.  Think I'm on the right track?

0 Kudos
Message 3 of 9
(2,793 Views)

@kyle8 wrote:

Bill,

 

Thanks for the reply.  Yes, that's exactly what I'm seeing.  My input to my subVI (Solenoid Active?) is true as it should be.  Therefore, I expect that "Extend" is high and "Retract" is low (focusing on Upper Platen Left, because that's where I saw the problem first).  This ought to give me a True output when the upper platen is extended.  However, when executed normally, my line always shows false (even though the upper platen is clearly extended).

 

Is it possible that I don't give the sensor enough time to settle, that LabVIEW executes that quicker than the solenoid can physically actuate / the sensor can sense?  The solenoid is actuated in the Toggle Relay subVI shown in Main, and then I run directly into checking that the sensors show proper actuation.  Again, since I know the function is working and that during highlight execution and singgle-stepping through the code I get my desired True output, I don't really see what else it could be.  Think I'm on the right track?


I think you are definitely on the right track.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(2,786 Views)

Well that did it!  Now comes the follow-up question: what's the best way to insert a time delay between the two subVIs?  Right now I'm using a 0.5s Time Delay Express VI, but I seem to recall hearing mixed reviews about Express VIs in general.  This seems to work just fine, just not sure it's the optimal solution.

0 Kudos
Message 5 of 9
(2,751 Views)

@kyle8 wrote:

Well that did it!  Now comes the follow-up question: what's the best way to insert a time delay between the two subVIs?  Right now I'm using a 0.5s Time Delay Express VI, but I seem to recall hearing mixed reviews about Express VIs in general.  This seems to work just fine, just not sure it's the optimal solution.


That's probably the easiest solution.  "Use 'em, don't abuse 'em" is my slogan for express VIs.  You could also roll your own by placing the Wait (ms) inside a subVI with a standard error in/out to enforce dataflow - as long as you remember to make it reentrant!  I think everyone has a homemade version of this in the their toolbox.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 6 of 9
(2,735 Views)

An easy solution that i'd probably do is add a small Wait function inside the Set relay-function, thus it'll take some extra time to finish.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 9
(2,716 Views)

I seem to recall hearing mixed reviews about Express VIs in general.


 

That would be the very rare exception to the rule.  Time Delay Express.vi is actually useful and has very limited overhead.

 

When you "pop-the hood" and actually look inside the express vis (right-click>> Open Front Panel...say yes at the prompt) You find this simple implementation:

Capture.PNG

 

That is a "Good" Express vi! the "Expressness" is only there to script the configuration of the time pop-up and is helpful in populating the help for the instance.  No run-time penalty!


"Should be" isn't "Is" -Jay
Message 8 of 9
(2,713 Views)

Thanks all for the input!  For simplicity now I'll keep it the way I've got it set up (especially now that I've seen what it's actually doing under the hood), but will likely end up making my own in the future to customize it for my purposes.

Message 9 of 9
(2,709 Views)