LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to set priorities in an event structure?

I am currently tasked with improving on some LV code used by my company. To keep it short, the program is pretty poorly written. My first task is to add a simple STOP button, so as to finish execution of the program and exit. This would normally seem trivial. However, the programmer who authored this opted to use countless, endless While Loops (with a False boolead hardwired to the Stop control), and numerous Queues, and notifiers, along with embedded sequence structures.

 

Fortunately, he also used an event structure as his main, so I would like to utilize this. When first learning about Event Structures, I though I remember being able to set priorities for events. For example, I want to add an event that executes in the case the user presses the STOP control I added, BUT I want this to interrupt the execution of theother events and execute right away?

Can this be done? If not, other suggestions would be helpful.

 

Thanks for the help.

~Andy

0 Kudos
Message 1 of 8
(3,294 Views)

Andy,

 

I think that the event structure has an internal queue which stores events in the order in which they occur.

 

One key to making the event structure respond quickly is to only put code in the event cases which executes rapidly.  One good thing is to simply enqueue a command.  The commands are dequeued and implemented in a parallel loop.

 

Obviously you need to go into every one of those endless loops and change the termination logic. A Stop Action Engine (AE) might be a good way to begin with the restructuring.  The Stop command can be written to the Stop AE in the event case and read in each of the other loops.

 

The sequence structures are more difficult to clean up. Learn about state machines.  They will be your friend for this problem.

 

Lynn 

0 Kudos
Message 2 of 8
(3,289 Views)

Thanks for the pointers Lynn - that was my understanding of Event Structures as well.

Can you point me in the direction for more information on theStop Action Engine that you mention...I think I would like to look at this...

 

Good point also with theState Machines, I agree with you on this one...

 

~Andy

0 Kudos
Message 3 of 8
(3,278 Views)

To add to Lynn's posting,

 

for the command queue, you would use the enqueue at opposite for the stop command to run before any pending commands or you can flush the queue before enqueueing the stop command.

 

But your post reads like you will need to do a major refactoring (which is not to seldom seen in the forum).

 

Felix

0 Kudos
Message 4 of 8
(3,275 Views)

Hi Andy,

 

look at this place about some advanced architecture:

expressionflow blog post

 

For the action engine search the forum for Ben's 'Community nugget on action engines'.

 

Felix

0 Kudos
Message 5 of 8
(3,267 Views)

Andy,

 

Felix has already pointed you toward the best information about Action Engines.

 

I ordinarily use the queue for the Stop command as well as all other commands.  The queue is meant to be read in only one place.  This works well for the typical producer/consumer state machine architecture.  The Action Engine can be read or written in as many places as needed.  I think this will be an easier step in the process of converting the existing program with full of inconvenient constructions.  (I do not use the term "architecture" for that program because it sounds as though it was built, but not planned.)

 

You mentioned the endless loops in that program.  That implies that the Abort button (re octagon on toolbar) is used to stop the program.  Deployed programs should not use the abort button.  It is there to let the programmer escape from program which will not stop during testing.  The Stop command in your program should take the program to a state where files are closed, hardware outputs are turned off or set to a safe value, references are closed, and things generally cleaned up before the program quits.

 

Lynn 

0 Kudos
Message 6 of 8
(3,259 Views)

Lynn,

 

Exactly!! We are on the same page, I am relieved to hear that. This code was poorly written, but it looks as if it was due to time constraints, rather than just bad programming.

 

I will have to do some more research with the Action Engines and State Machines.

 

Thanks again.

0 Kudos
Message 7 of 8
(3,256 Views)

If you need to go for some kind of software safty (hardware safty goes first!) Get the appliication exit as well and the panel close event and send the kill command to all 'client processes'.

 

Felix

0 Kudos
Message 8 of 8
(3,243 Views)