Showing results for 
Search instead for 
Did you mean: 

How to continuously read a global variable across a sequence?

Go to solution

Hi, I have a main vi that runs through a sequence, containing various pauses and graphics handling. One frame opens another sensor (without a visible panel) which generates continuous data to some global variables. Towards the end closes and goes about it's merry way.  


I am trying to continously read these global variables through the rest of mains sequence, but they don't update at all. Why so? They are updating in their own's.


I've tried reading pausing the sequence with a while loop in one frame to sit and read the globals, but there're not there.


All help much appreciated!




0 Kudos
Message 1 of 10

This illustrates the problem. Which is about knowing where and how to read global variables across a sequence.

0 Kudos
Message 2 of 10

Using a sequence is just wrong on so many levels.



Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 3 of 10

I realise that, but the complexity of the code forced me to use a sequence to keep track of .. the sequence.

0 Kudos
Message 4 of 10

Do NOT use sequence structures! It is always a good sign of bad design decision and leads to numerous problems.


Usually if you need to program different steps, the best way to do so is using a State Machine. Another thing is to avoid overusing global and local variables. Beginners end up very often with bad race conditions, and difficulty to understand code. Variables ignore data flow, so you should be careful with them.


If you could further explain why you need to dynamically call another VI from this attached VI, we could propose probably a better solution. LabVIEW's great power comes from the easiness of creating parallel processes inside a single VI, I imagine all the functionality you want could be done using a single VI.


You should look into some common design patterns proved to be useful for handling parallel processes, and you will get more idea about proper intercommunication methods (Queues, etc). One example is the Producer/consumer design. A producer/consumer with a state machine is a very useful thing. Like a Qeued State Machine, where you can execute certain steps in a flexible way...

So explain better what is your goal, and it will be easier to propose a good solution excluding these local/global variables and that Flat sequence structure...

0 Kudos
Message 5 of 10

If you have an active licence, you can access the LabVIEW online training material, you will see that spending a few days with this will help you a lot:


Core 1:

The first step in any NI LabVIEW learning path, LabVIEW Core 1 gives you the chance to explore the LabVIEW environment, dataflow programming, and common LabVIEW development techniques in a hands-on format. In this course you will learn to develop data acquisition, instrument control, data-logging, and measurement analysis applications. At the end of the course, you will be able to create applications using the state machine design pattern to acquire, process, display, and store real-world data.


Core 2:

The LabVIEW Core 2 course is an extension of the LabVIEW Core 1 course and teaches you to use common design patterns to successfully implement and distribute LabVIEW applications for research, engineering, and testing environments.


Message 6 of 10

Thank you Blokk, I have been on those courses and the intermediates. This forum is for sharing experience on specific coding problems.

Message 7 of 10
Accepted by topic author grahamwebb
09-05-2017 08:43 AM

Here is a quick modification to show how a state machine would be set up to handle this situation. Without the subVI I could not test it. It is not intended to be fully functional. Some things like the zero global should probably be eliminated but without the metronome VI, I cannot tell what needs to be done. Possibly a Notifier.


No globals. No locals. No sequence structures. Smaller block diagram. More responsive to user inputs. More easily changed if new requirements are added.



Message 8 of 10

@grahamwebb wrote:

Thank you Blokk, I have been on those courses and the intermediates. This forum is for sharing experience on specific coding problems.

If you attended those courses, you should know that a state machine is the specific  solution for your problem. I hope the NI instructor did not teach you to (mis)use  variables and flat sequence structures? Smiley Surprised

0 Kudos
Message 9 of 10

@grahamwebb wrote:

Thank you Blokk, I have been on those courses and the intermediates. This forum is for sharing experience on specific coding problems.

Your "specific coding problem" isn't specific at all - it is systemic.  It is due to a misunderstanding of how data flow works.


I find that taking the online course equivalents was much better for me because I could go at my own pace.  It could be that since you took the instructor-led courses, the online courses may lead to many "a-ha!" moments and true understanding.  Honestly, I have to say you should take those courses online if possible because you still have not absorbed the very basics of data flow.  The online tutorials listed on the left side of the main LabVIEW forum page may trigger many "a-ha!" moments, too.  If you can't take advantage of the online courses through an active SSP, the tutorials are the next best thing.  Good luck!  Smiley Happy

(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 10 of 10