LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Only 50% to successfully stop the sub VI loop using main VI control

Solved!
Go to solution

Hi everyone,

 

I am a beginner of Labview and I am trying to write a programme to build an array and export it to txt.

 

It was successful when I run the sub VI directly. However, when I added a main VI and use global variable to control the stop button of while loop in sub VI, the programme does not run properly. It can successfully run one time but when I try another run with the same procedure there is a wrong "True" value passing through the global variable, forcing my while loop in sub VI stopped. It is alternating between these two condition and I cannot figure out why this happen.

 

Can anyone explain this? I have attached my VIs below.

 

Cheng

Download All
0 Kudos
Message 1 of 8
(1,044 Views)

You have not attached anything.

0 Kudos
Message 2 of 8
(1,035 Views)

Sorry for that, I have uploaded now. Thanks for reminding me!

0 Kudos
Message 3 of 8
(1,025 Views)

Kindly share the vi after down converting to LabVIEW 2018 version.


CLD Using LabVIEW since 2013
0 Kudos
Message 4 of 8
(1,013 Views)
Solution
Accepted by topic author cl251

Hi cl,

 

please take the LabVIEW beginners tutorials as offered in the Training resources in the header of this LabVIEW board…

 

Your VIs show a big race condition: two processes access the very same resource - and the winner is unknown (aka more or less randomly choosen)!

  • The main VI reads a latching button within microseconds in a polling (aka CPU-hogging) loop and writes its value into that global.
  • The subVI checks this global only once per second: how big are the chances it will read a TRUE value when this global is overwritten within microseconds?

Solutions:

  • You don't need a subVI for this simple task: place all code within the loop of your MainVI.
  • Leanr about proper programming patterns: the basic ones are explained in the tutorials mentioned before…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(976 Views)

Thank you for your explanation, GerdW! Sure, I will follow your suggestion to watch the tutorial!

0 Kudos
Message 6 of 8
(968 Views)

A few more general comments:

 

  • It is typically a bad idea to save outside the main loop, because all data is lost if it fails for some reason and you want to re-try saving once more. Use a state machine instead.
  • Your header array should probably have one word per field so the column delimiters (tab by default) are properly inserted.
  • "Insert into array" is not the correct way to prepend a 2D array. Use "built array" in concatenate mode.
  • "Number to decimal string" will drop all fractional parts and only keep integers. Use "Number to fractional string" for DBL.
  • Just initialize the shift register with an empty array constant. No need to built and display it.
  • There are probably easier ways to get the elapsed time than with the elapsed time express VI.
  • Use a reasonable time format for the time indicator.
  • If arrays can grow larger than the container, show the scrollbar(s).
  • "Global 5.vi" is a very (very!) poor name for a file. My downloads folder already had one from a previous forum post, so chrome renamed yours to "Global 5 (1).vi" , breaking your VI because the old global 5.vi had a different datatype.
  • Similarly, SubVI1.vi is also a very poor naming choice. Give it a unique name that hints at the functionality
  • etc.
0 Kudos
Message 7 of 8
(942 Views)

Hi altenbach, Thank you so much for your useful comments! There are many things you pointed out that I should be very careful about when I am making LabVIEW programs in the future.

 

I have some further questions and would be appreciated if you can help me.

 

1. Could you post an example that I can refer to as you pointed out the proper way of saving data with state machine?

 

2. Using express VI for elapsed time seems to be quite easy for me, is there any disadvantage using it?

 

 

 

 

 

 

0 Kudos
Message 8 of 8
(929 Views)