LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly exit with Systray event

Hi Labview experts,
 
<DESCRIPTION OF MY PROGRAM>
 
In my simple program, when I press the "start" button, the program begins a serial Modbus communication with a connected device (temperature
controller), reading always the same address (it contains a temperature value). This reading is inside a loop and it stops when I press "stop" button or
when a timeout (in seconds) expires ("timeout" is a control on the front panel and I consider it only if it's different from 0).
The data are collected in a shift register that is updated every cicle
When the reading ends, the shift register is an array with all data read, and I do the following three task:
update some statistics (mean, etc...), write the data in a text file (after array to spreadsheet string), update a graph
This ends the "start" value change event (mouse click).
 
<A NEW FEATURE AND THE ISSUE>
 
Recently I added another feature which is the "systray icon", with the following behaviour:
1) when the window is minimized, the systray icon appears and the taskbar icon is hidden
2) systray icon has 3 "menuItem" (Exit, About, and Restore). When I double click or select Restore, systray icon is hidden and taskbasr appears.
3) When I select exit from systray program should properly exit.
1 and 2 works fine (I am using a free package found here in the forum, it consists of an ActiveX Server compiled with LabWindows/CVI, and some top level VIs that interface with it)
 
As regards the third point, I am not sure about the best way to properly close *in case a serial reading was in progress*.
I mean I would like that data would at least be saved until that point, so manage a proper exit.
I was thinking about a sort of notifier/semaphore/rendevous but I think I should change the "structure" of this data acquisition. As of now, I am simply using events and user-events (generated by the systray VI). The program is a event structures inside a while loop.
 
ThAnKs
0 Kudos
Message 1 of 6
(2,823 Views)

If you want to avoid changing the basic structure of your program, you can simply create a "clean up and exit" user event which will do everything you want. Then, fire that event when you want to exit (e.g. tray icon, Panel Close event, the stop button, timeout, etc.).

If you want your program to be more flexible, you can try running the DAQ code in a separate loop and use a synchronization mechanism to pass the data, like you suggested. Then, ending the loop will also close all resources. You should be able to find some examples if you search for "queued state machines" and "producer consumer".


___________________
Try to take over the world!
0 Kudos
Message 2 of 6
(2,807 Views)

If I made a "producer consumer" architecture how can I stop the producer in the middle of his work (for example: "front panel close event" in the consumer event structure)?
And how can I synchronize both the start and the stop of the DAQ loop with notifiers?? Am I obliged to use queues?

I think I'm making confusion about the usage of the notifiers...Smiley Indifferent

0 Kudos
Message 3 of 6
(2,786 Views)

I didn't look at all the details of your setup, but you can try something like this:

  1. DAQ loop (a VI would actually be better with all the relevant code and the loop inside it). This talks to the controller ALL the time and puts the most recent value into a notifier or even a global.
  2. UI loop. This will process all the events.
  3. Logging loop. This will accepts commands from the UI loop, probably using a queue, and you can now send the same command when different events occur. Alternatively, you might be able to implement this code as an action engine and use actions (e.g. start logging, stop logging) instead of the commands. You can then call those actions for different events.

Stopping the loops can be done using a global variable or a notifer.

P.S. I mentioned globals twice - you should note that they are dangerous. You can usually use them in cases like this where you have a single producer, but even then you should be aware of the potential for race conditions and often there are better solutions.


___________________
Try to take over the world!
0 Kudos
Message 4 of 6
(2,771 Views)

I know action engines, untill now I made one to manage a "timer" whereever I want ("get timer" gets the millisecond elapsed from the "start timer" action, by means of time difference).
But I don't want to acquire data *always*. I would like to do the following:
1) Start the DAQ (in my case by means of "ModBus function 3 (read register)") with a button (start).
2) "stop&clean" : this event fires when
 A) I click stop button
 B) Timeout expires (timeout is a control on UI, if not zero, after that time the event is fired)
 C) panel close event occurs, or exit from the "User_event_systrayIcon_Exit" event occurs
     the stop&clean should close communication and resources and save the data collected to a file.

What is the best architecture to use ??

Another problem: In the event structure I have events from the front panel controls. Then I added the "user events" connector, and wired the user event generated by the VI of the systray (see "LabviewTray Icon.vi" in the forum). Now I can see some "user_events" together with the rest (only the user events programmed in that vi). Is it possibile to add OTHER custom user events???? How?

Thanks

0 Kudos
Message 5 of 6
(2,749 Views)

Again, in my opinion the better architecture is to let the DAQ VI (or loop) run all the time and put the most recent value into a notifier. Then, you can decide whether you want to get that data or not.

Stopping the DAQ loop will also run the code which closes the VISA resource.



Slyfer wrote:

Is it possibile to add OTHER custom user events???? How?


The event registration refnum is typed, meaning it holds the exact types of all the events in it (you can see this if you open the context help window and hover over it). This means that you can only configure the basic list of events in one place. The ActiveX object does this in a subVI, so you can go into that subVI and add more events to the list, but this will break the indicator in the VI and you will need to recreate it.

___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(2,733 Views)