LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to illiminate some local variables

I started this conversation in another thread but this is not the same topic, so here's the new question. I was told that I was using too many local variable but I don't know how to get rid of them. Here's the updated code with some other fixes. This code works great butif I'm doing something wrong I'd like to fix it.

 

Capture.PNG

0 Kudos
Message 1 of 43
(3,056 Views)

For some things it is OK to use local variables, like if you only care about the most recent value in a control and it is ok to miss some of the values in between. But, other times when the expected value and the actual value are different you have a race condition. And when the expected value and actual value are only sometimes different you have a race condition that is hard to track down.

 

It is also a little awkward to have an event structure side-by-side those case structures which are triggered by booleans. The event structure is very good at detecting a boolean value change, so you should put those inside the event structure, and then you not have to make the event structure timeout every 100ms. Also, make some SubVIs that perform a well-defined function, like taking your instrument measurement. Then your code can fit on one screen and you won't have to use the stacked sequence structure.

0 Kudos
Message 2 of 43
(3,036 Views)

I would restructure this as a Queued Message Handler:

Two parallel loops:

One with an event handler, generating messages,

the other processing the messages.

Store data in shift registers.

Inside your event structure, there is a sequence frame; it's doing nothing, get rid of it.

The 2 local variables for "Sheet Name to load" & "Excel Setup File" are unnecessary because you have the control terminals right there; use them.

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 43
(3,024 Views)

(continued from here)

 

OK so you added a toplevel while loop. Good!

(You don't need to wire indices of "index array" if you want to get the elements in order)

 

Now for the cleanup:

  • If all cases execute in a reasonable time, create event cases for "load, Run, and Undo and put approriate code in each event case (get rid of all the code on the bottom.
  • create a shift register for your "current" array.
  • If you close the visa after the loop, you should open it before the loop (I assume the devices do not change)
  • Instead of building an array of scalar strings, just create a string array diagram constant.
  • Is the user supposed to be able to manually change the array values read from the file? If not they should be indicators.
  • You can use "built array" to append two 1D arrays (concatenate mode).
  • ...

 

0 Kudos
Message 4 of 43
(3,020 Views)

@altenbach wrote:

(continued from here)

 

OK so you added a toplevel while loop. Good!

(You don't need to wire indices of "index array" if you want to get the elements in order)


 


Yes.  I have no idea why the OP decided to put all those in when my example to him eliminated almost all of them!

Untitled

0 Kudos
Message 5 of 43
(3,001 Views)

Good morning guys. I'm reading your posts and trying to implement your suggestions. Thank you very much for helping me BTW.

 

I got rid of the unused flat sequence and added the undo into the event structure. Turning portions of this into sub vi's is next unless you see something else. In the stacked structure I want to change the 1[0..2] portion into a subvi. The issue is with that local variable. How can I accomplish this? I have all day to work on this so I'd appreciate it if you could try to walk me through this a step at a time until it looks and work on a professional level. Let's go!

0 Kudos
Message 6 of 43
(2,970 Views)

If you are basing it on a local variable of the current diagram, when you create the subVI, the value from the local variable (or terminal, or wire from somewhere else in the code) will pass into the subVI via the connector panel.

 

If the local variable is included in the selection window when you highlight the code and pick Edit >> Create subVI, you'll see it turns it into a reference of that boolean control, and places an explicit value property node inside the subVI.

 

Instead, if you move the local variable to a position so it is not included in the region you select, basically the boundary of the selection region crosses over the wire coming from the local variable, you'll see it creates a control in the subVI that is put on the connector panel and the local variable in your main VI will attach to that connector in the new subVI.

 

0 Kudos
Message 7 of 43
(2,965 Views)

Thanks. That's what I did. Here's where I'm at after making some sub vi's.Capture.PNG

 

 

 

0 Kudos
Message 8 of 43
(2,948 Views)

If you must use the RGT to retrieve values from an XLS file, set the datatype on the Excel Get Data to be an array of doubles.  No post-import conversion would be required on your part.

 

Why convert the number of supplies to a string in order to do a select?  Instead do something a little bit smarter that doesn't require a select statement at all.

create_array.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 9 of 43
(2,940 Views)

@RHutchings wrote:

Thanks. That's what I did. Here's where I'm at after making some sub vi's.Capture.PNG

 

 

 


I don't see where yo made any subVI's.

Where do you want to make subVI's?

0 Kudos
Message 10 of 43
(2,932 Views)