LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a refnum along a stacked sequence...

I think it is not productive to let us guess how your code looks like, so you get partial advice based on limited and possibly incorrect information. I am sure we could be much more helpful if we could see the entire code architecture. I guarantee you that there are much better ways from what it sounds like you are doing.

 

You could encapsulate the file writing into an action engine that keeps track of the file reference and also add internal modes for opening and closing, but I agree that a top-level state machine is the answer. It should be more than just a functional replacement for a stacked sequence so you can reorder live and even skip out early if needed.

 

 

0 Kudos
Message 11 of 20
(1,497 Views)

@aputman wrote:

@RTSLVU wrote:


Necessary? Stacked or flat sequences are NEVER necessary.

 


I would agree that stacked sequences are NEVER necessary but a case could be made for flat sequences.


Sure you could argue that, but the cases where it is true are few and far between.

 

I have found that if I stop and think about it, there is usually always a better way than a sequence structure. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 12 of 20
(1,496 Views)

I can't share the code directly without going through a great deal of trouble due to the security measures in place on the control computer.

 

I will do my best to explain the situation: The legacy code was organized as a While loop which encloses a stacked sequence structure, and in each sequence there are state machines. What this means is that the state values all have to be passed into the while loop with shift registers, and then to their respective case in the stacked sequence, and then to their state machine. 

 

My problem was created when I wanted to pass a refnum along all of the sequences so that I could write to a log text file whenever certain states were triggered. Unfortunately, despite the stacked sequence structure being perfect for the previous application, the one thing it can't do is pass along something like a refnum from sequence to sequence, even though the sequences are always sequential (of course), so this couldn't lead to any conflicts. I really don't understand why LabView doesn't allow this.

 

If I replace the stacked sequence with a case structure enclosed in a For loop (to make a sort of artificial stacked sequence) then all of my tunnels for the states break - I would have to wire all of them all the way through the sequences (and there are a lot, so that's seriously impractical.) 

 

All I want is to be able to use and update my refnum throughout the stacked sequence so that I can keep writing to my text file. Maybe I could just store the refnum as a local variable and then read it, write to my text file, and write the new refnum to that variable? I am not sure how to create a local variable for a refnum. 

0 Kudos
Message 13 of 20
(1,492 Views)

I really think you need a full refactoring of your code. However, if you only need now a "quick patch", just use a Functional Global Variable, as it was already proposed to you!

http://www.labviewing.com/fgv-in-labview/

https://www.youtube.com/watch?v=I_sjwAfVXrM

Message 14 of 20
(1,488 Views)

@VPI001 wrote:

Maybe I could just store the refnum as a local variable and then read it, write to my text file, and write the new refnum to that variable? I am not sure how to create a local variable for a refnum. 


I am sorry you inherited such a mess. How many different files are actually being written? I would go with my suggestion to encapsulating the file IO into an action engine that keeps track of the reference internally.

0 Kudos
Message 15 of 20
(1,486 Views)

@VPI001 wrote:

 

 

When I try the For loop>Case Structure solution, all of my tunnels break - LabView wants me to wire each and every one of them in every case of the case structure, which is extremely unwieldly. Is there a way to circumvent this behavior? To clarify: the tunnel returns an 'unwired' error unless it is wired through on every case, which seems opposite to the way a tunnel should work.


you can r-click the connector and chose link it to the other side. Then all cases will be wired. If you have many wires you can bundle them up with ... Bundle.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 20
(1,483 Views)

@VPI001 wrote:

I can't share the code directly without going through a great deal of trouble due to the security measures in place on the control computer.

 

I will do my best to explain the situation: The legacy code was organized as a While loop which encloses a stacked sequence structure, and in each sequence there are state machines. What this means is that the state values all have to be passed into the while loop with shift registers, and then to their respective case in the stacked sequence, and then to their state machine. 


I'd make 1 subvi of the sequence, then, in that sub-vi, change the sequence to a flat sequence and make each step 1 sub-vi which'll have error threads to control execution.

The quick fix, as mentioned, if a AE/FGV or a global variable.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 17 of 20
(1,480 Views)

@altenbach

 

Thank you, sadly there's no way this code is getting compeltely rewritten just to add a log functionality - the loss in instrument time and man-hours wouldn't be worth the benefit. 

 

It does look like a FGV would help - but why is a global variable necessary? It feels like I should be able to store the output refnum and then reference it the next time I need it, even from within a loop.

 

In fact, since I know for a fact that race conditions cannot occur can't I just use a regular old global?

0 Kudos
Message 18 of 20
(1,479 Views)

If you open the ref before the stacked sequence you can pass it into the stacked seq. and just use the same tunnel in all of the frames.

 

Normally the value of the reference does not change but rather the data structure at which that reference points.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 19 of 20
(1,468 Views)

If you insist on keeping the structure you have now, the sequence local will work as long as you are not updating the file reference value on subsequent frames.  Each frame following the initial assignment has access to the sequence local value.

0 Kudos
Message 20 of 20
(1,466 Views)