Jump to content

Passing a reference via case structure cases


bna08

Recommended Posts

I have multiple cases to be executed in a case structure as a result of user events in my application in a producer/consumer pattern. 

In one of the cases a new reference is created that I will only need once more in another case of the given case structure. All other cases have no need for that reference. However, if those other cases are invoked (e.g. Grab Frame, Stop Acquisition), a wire has to be dragged through the case from input shift register via case structure tunnels to output shift register so that it does not become invalid (Use Default If Unwired) and can be used once the case that actually needs the reference is invoked. This results in unnecessary wires (and often more of them) in other cases of the structure that pollute the diagram and have to be there just to carry the reference for any other case. Is there a way I could reduce this "pollution" and avoid dragging the wire through each case where it is not used at all? 

Here is an example: 

INIT VI generates a reference that I will need when calling the OPEN CAMERA VI so I pass it to next iterations via Shift Register: 

image.png.fc076f538c4a8608044783a6081cc1e3.png 

OPEN camera VI that requires the reference from INIT case: 

image.png.19521715492b90acbf2676f71a3ec40f.png

 

Other cases, such as Open Camera or Grab Frame have no need for this reference, yet it has to be dragged through these cases as well in order to pass the reference if I want to keep the reference value for future use:

 

image.png.4cb10cfb32db3b19024eb7f962685cab.png

I could select Use Default If Unwired in these cases and not use the wire at all, however, that will set the reference value to null and I won't be able to use it anymore. 

Is there a way to solve this without dragging the wires in all cases of the structure? 

 

 

Edited by bna08
Link to comment

imho linked tunnel and explicit wires through all cases is always the sane thing to do to avoid mistakes. Yes, to save wires you could certainly write your ref into a hidden indicator or into a global variable out of Init, and read the local/global variable in the open camera case, but I'd consider it bad practice and a recipe for future races and less readable code.

  • Thanks 1
Link to comment
1 hour ago, Neil Pate said:

As your application grows I would expect the need to pass additional state information between the frames of your VI. You could make a "Core Data" type cluster and put whatever you want inside that. Then you just have one wire that gets passed on the shift register.

Sounds like a good idea, thanks!

Link to comment
5 hours ago, bna08 said:

I could select Use Default If Unwired in these cases and not use the wire at all, however, that will set the reference value to null and I won't be able to use it anymore. 

Right click on the tunnel and select "Linked Input Tunnel>Create and Wire Unused cases"

  • Like 2
Link to comment
3 hours ago, ShaunR said:

Right click on the tunnel and select "Linked Input Tunnel>Create and Wire Unused cases"

I use it everywhere. This is one of the things many LabVIEW programmers I've met have never encountered.

They ask me "what the f&ck is that little thing?" and after I explain it to them it shows up in all their code 🙂

Unwired Cases.png

Link to comment
On 12/15/2022 at 11:16 AM, Phillip Brooks said:

I use it everywhere. This is one of the things many LabVIEW programmers I've met have never encountered.

I resemble that remark.

Best holiday gift so far this year. Thank you!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.