LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure vs. stack sequence

hi there.
i have a question about event structure vs the stacked sequences i currently have.
i want to simplfy my code as much as possible and i am at the point where i dont have any other options. so i thought about changing the current structure to event structure.
but one thing i am not sure about is when my sequence call out for a boolean to be TRUE or FALSE. how come my STACKED SEQUENCE does not change value if the timeout called out for  a boolean to be true?

p.s-
i'll attach part of my code. hopefully u can give me pointer on making it better?
sorry about the local varialbes. still working hard on changing them.
 
Best regards,
Krispiekream
0 Kudos
Message 1 of 10
(4,506 Views)
You are going to need to give a few more details.  You have so many stacked sequences and and booleans, which ones are you talking about?  Where does the event structure come into play?
Message 2 of 10
(4,486 Views)

Hi,

I think you should check some of the design patterns through the Getting started window. For example Producer/Consumer (events) and the Standard State Machine would be good to start with. Another thing is that you could divide your VI more into subVIs. By implementing better design pattern and using subVIs helps you to avoid local variables and also makes your life easier 🙂

- Matti

Message 3 of 10
(4,461 Views)

Good comments from Matti & Ravens Fan.

I saw the code last night and figured that there's a lot of work needed, so you should attack this piecemeal.  Maybe start by getting rid of Locals by wiring directly.  And get rid of all stacked sequences.  After those two are cleaned up, the code should already be much better.  You'll also be able to remove the Flat sequence structure.

R

Message 4 of 10
(4,451 Views)
Looking into the code, i dare to say: Your "origin" lies within textual (procedural) programming languages. And it looks to me that you haven't taken the time to learn which differences are there between LabVIEW and procedural languages....
So here a small list:
- Do not use any kind of variables if avoidable because they are evil (read this link)
- Do not use any sequencestructures besides some very rare, special cases
- Please inform yourself about the common architectures/frameworks within LabVIEW for a better (more readable) codedesign
- Try to incorporate as many style guides as possible (and useful)
- The position of several terminals in the blockdiagram (BD) indicate that your fullversionofmycode.vi is way too large. The BD should fit on a single monitorresolution.
- Stop using variables (erm, said that before...)

hope this helps,
Norbert


Message Edited by Norbert B on 07-30-2008 07:28 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 5 of 10
(4,437 Views)
In addition to the comments posted above I will add a suggestion on how to approach the usage of an event structure when reworking a program.

First, note that in a reworking task like this that the Value Changed event will be the only one you will use. Things like Mouse Down and Drag were not used or emulated in the original and will not be needed until you try to do fancy things with the user interface in a later version of the program.

Go through the front panel and make a list of all controls which require the program to actually do something when they are changed. Most of the booleans will be on the list but such things as Input String and Comment will probably not be on it. After you have the list, add a second column describing the task to be performed when the control changes.

You will probably want to create an event case for the Value Changed event for each control on the list. Since you do not want any time-consuming code inside an event case, you may need to implement a two-loop architecture with the event structure in one and most of the the operating code in another. See Matti's post above. Use queues to transfer commands from the event loop to the other loop. The tasks on the list of controls are actually performed in the second loop. This is where a state machine becomes very useful.

Lynn
Message 6 of 10
(4,429 Views)
Without really being able to look at functioning code it's difficult to be too specific.  If you can group your controls and indicators properly as suggested by Lynn, then you can bundle their values together and pass them through a shift register in your state machine in order to eliminate the variables.


Message Edited by lmtis on 07-30-2008 08:50 AM
Jim

LV 2020
Message 7 of 10
(4,404 Views)
thank you everyone for giving me great advices.
i am still thinking about approaching this problem.
i am thinking about replacing what i have with an event structure.
but i do have a question...
lets say that i have an event structure. inside the structure, there is a flat sequence.
the sequence call for ADV to be true.
does that automattically changed my ADV BUTTON to NEW VALUE or is it ONLY NEW VALUE if i manually click on it?


so, this is an off topic, but have this diagram.
normally when i unbundle and bundle clusters, do i do it INSIDE OR OUTSIDE OF THE CASES?


Message Edited by krispiekream on 07-31-2008 03:18 PM



Message Edited by krispiekream on 07-31-2008 03:18 PM
Best regards,
Krispiekream
0 Kudos
Message 8 of 10
(4,353 Views)
The event structure responds to user events. When a user pushes a button or changes a numeric or enum control, then a Value Changed event for that button or control occurs. The specific events you want to capture must be explicitly defined by creating an event case for each one. The event structure does not execute until an event occurs unless a timeout event is defined. (Note: There are exceptions to all the things I just said, but they are not relevant to what you are trying to do now).

An event case should not contain any code which takes very long to execute because it will block the response to other events. Similarly it can get complicated if one event case depends on data from controls which are in another case.

I usually have the event structure in a while loop which does very little else than respond to user activity on the front panel. It sends "Commands" via a queue to a econd loop where all the processing takes place.

I am not sure I completely understand you question about a sequence inside an event case, but I think it is a bad idea. Sequence structures are almost always better replaced by dataflow or a state machine or both. New Value has the value to which the control has changed when the event was triggered. For Value Changed events it will be the same as the value of the control. If you are looking at something like a Mouse Enter event, I am not sure what you get. Remember, the event case only executes when the event for which it is defined occurs. You will only get inside the ADV Value Change event case if the ADV button is pressed or a Value (Signaling) property node executes.

Obviously the TempCharMode unbundle must be outside. The others can be either place. It may depend on whether the signals are used in both case or only one. Using Unbundle by Name is very helpful for documenting code, so deciding where to put it may make a difference in the readability of the code. If large amounts of data are present in the cluster it may make some difference to the ability of LV to work in place to conserve memory allocations.

Lynn
Message 9 of 10
(4,339 Views)
great!i think you made things very  very clear now.

Best regards,
Krispiekream
0 Kudos
Message 10 of 10
(4,333 Views)