LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW: Concerns with Local Variables and Program Readability

Solved!
Go to solution

aputman wrote:

JKI is the exact same construct that you have used in your VI except that it is string based and contains a cluster of data elements that you define, much like a class, that are always available in any state.


 

The data cluster sounds immensely helpful, but looking at at the JKI state machine is much more complicated. It is pre-set with 12 cases that I now need to go learn and understand before I can even start writing my code into it. So in a sense, yes, it is a state machine. But it is my no means exactly the same. As if learning labview weren't intimidating enough, now we have complicated templates to really mess with people's heads.

 

It looks like a better long term solution though. Let me go figure that out and I will get back to everyone. THANK YOU!

 

 EDIT:

 

So I have downloaded JKI and started learning how it works. Now that I am trying to implement this I am looking at it very closely and noticing a problem. Since the event structure is inside the idle case, doesn't the program have to be in the idle case for the event to process? 

 

This is one of the reasons I started using two event structures. I need to be able to pause at any point during my program, not just when it is sitting in the idle state.  It seems bad to send the program to the idle state after every step to check for the pause condition.

 

Is this what I need to do?

0 Kudos
Message 11 of 18
(1,014 Views)

Maybe the state just needs to be renamed.  "Idle" implies that nothing is happening.  Perhaps you should think of it as a "Check Events" or "Check User Interface" or something like that.  And the state machine will cycle through that on a regular basis.

 

Another thing you can do in the event you need to go to a "pause" state, but  don't now which of many different states to go back to when the "resume" occurs is to store the previous state in another shift register.  So you can either keep returning to the pause state, or feed previous state that was stored in a shift register back into your state machine when you unpause.

Message 12 of 18
(993 Views)

I have built a large test application.  When a test is underway, I throw an Idle step into the mix every 300ms to check for the Escape keypress to stop the test. 

 

The event structure can be moved into it's own while loop but you don't need two event structures.  I like having the event structure in the idle state because I still have access to the data cluster.

 

Capture.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 13 of 18
(984 Views)

Alright. Thank you all. If sending the program to idle frequently is not an issue then that should work. 

 

Learning LabVIEW on my own at the same time as I am supposed to be producing working programs has been an interesting process, and I have no doubt it will continue to be. Without this forum I would be dead in the water. No doubt every response has helped me to see the things I have still to learn and work on. I am going to call this solved, but it was not a single effort. 

 

For others who may have similar issues however, the JKI state machine is probably the most widespread and applicable. Thank you all. I really do appreciate all of the help. 

 

Nukem

Message 14 of 18
(975 Views)

Quite some cleanup, i think you'll understand and agree it's a better design. 🙂

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Download All
0 Kudos
Message 15 of 18
(961 Views)

Here is some code using JKI.  Labview 2012.

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 16 of 18
(933 Views)

I haven't read all parts of the discussion, but I will add this:

 

* Following a style guide is a good idea, but everyone still have their own artistic touches to their code.

* I use in-place 1 element sequence structures a lot for the same reason you have listed, its easier to keep that code together and not affected by the clean-up tool.  Especially if I have comments I want to keep with the code.  Almost always, those sequence structures turn into SubVIs.  I think some folks are a little over zeolous about not using them Smiley Tongue.


* Local Variables can be unpredictable at times, but I like to use them for a lot of reasons.  Thats another issue I think some folks are over zeolous about.  You just need to be mindful of why you are using a Local Variable as oppose to a notifier or a queue.  Generally speaking, notifiers and queues are a much better and less error-prone route but that doesn't mean you should avoid using Local Variables all together.

0 Kudos
Message 17 of 18
(913 Views)

Local variables and sequences are like wine, good in moderation.

 

It's very easy to overuse both, especially if you're coming from a text-based language, so the starting point is: Avoid them until you can handle them, kind of like wine. 😉

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 18 of 18
(906 Views)