11-11-2016 09:41 AM
Hi, I have a main vi that runs through a sequence, containing various pauses and graphics handling. One frame opens another sensor reading.vi (without a visible panel) which generates continuous data to some global variables. Towards the end main.vi closes sensor.vi 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 globalvariable.vi'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!
Confused,
Graham
Solved! Go to Solution.
11-11-2016 09:57 AM
This illustrates the problem. Which is about knowing where and how to read global variables across a sequence.
11-11-2016 10:13 AM
Using a sequence is just wrong on so many levels.
Think DATA FLOW
11-11-2016 10:18 AM
I realise that, but the complexity of the code forced me to use a sequence to keep track of .. the sequence.
11-11-2016 10:21 AM - edited 11-11-2016 10:22 AM
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...
11-11-2016 10:27 AM
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:
http://ni.com/myni/self-paced-training
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.
11-11-2016 05:43 PM
Thank you Blokk, I have been on those courses and the intermediates. This forum is for sharing experience on specific coding problems.
11-11-2016 07:34 PM
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.
Lynn
11-12-2016 12:42 AM
@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?
11-12-2016 04:45 AM
@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! 🙂