Jump to content

Using Dynamic User Events as messaging conduits


Recommended Posts

When Dynamic Events were introduced in LV7 I tried so hard to figure out a place for them in my design architectures. I am attaching an implementation where a user defined dynamic event is used to pass data from a dynamically called VI to a main VI caller. I actually used this implementation in a real project.

Any comments or suggested improvements are welcome. The code is LV7.0.

Download File:post-12-1087954972.llb

Link to comment

Another application where I might have used it (unfortunately the app is written in LV6) is a software where I read out our sensors. They include a microcontroller and communicate over the serial port. The initialisation of the screen (e.g. which channels are shown) is performed, when I show this tab (sw includes serveral "screens"), after a sensor change detected on the port, ...

With dynamic user events I write the code only once, including property changes on controls/indicator, in the event structure and handle different events (mouse click, user event,...) on the same sequence.

It also could be made with sub-vi, but around the sub-vi one has still more or less code. e.g. supplying control refs, write to Indicators,... which is error-prone when the forntpanel changes because you have to wire this code n-times.

Didier

Link to comment
  • 1 year later...

In this attached simple LLB, I employed Aviolaitis strategy in an example for deploying user events between VIs.

To demonstrate:

1) Run VI

2) Click 'Open SubVI' button which open 'test_subvi.vi'

3) In the image on the front panel of test_subvi.vi, move the cursor to any point on the image;

this will cause a user event to fire in main that inverts the waveform.

4) Similarly, if the user clicks the 'Stop' button in the test_main.vi, a user event will fire in the subVI

that closes the test_subvi.vi front panel and stops the subVI

Here is the issue:

If I want to fire a similar event in the main that I did in the subVI, in this case 'Invert' which will

invert the waveform, if the user event has been triggered from the subVI, it will not trigger from

the main VI. And no error is present upon 'Generate User Event', it just does not work.

My first thought was that I needed to reregister the user event in the main VI after triggered

from the subVI. So I tried reregistering the event in the Invert event case in

'test_main.vi' prior to generating the event. Still did not work.

I wanted to know what the explanation for the current behavior might be and how it might be

rectified. I have plenty of workarounds but I wanted to know if there is any way this can be

made to work with some simple steps.

Code is LV 7.1.

Thanks,

Don

Download File:post-115-1132767576.llb

Link to comment

I used the same basic setup as Michael's first example, but made the event and hence the plugins a bit more generic by making the data type a cluster with a command string and an array of variants. The command string then gets fed from the event handler to a state machine and the variants act as arguments to the command. Minor performance penalty, but flexible.

That being said, I tried hard but failed to get that excited over events rather than using queues to do the same things. It was much easier to come up with "how", than a compelling "why".

Link to comment

ps. I want to make one clarification. I stated:

"if the user event has been triggered from the subVI, it will not trigger from

the main VI. And no error is present upon 'Generate User Event', it just does not work."

What I should have said instead of "it just does not work" is that a "timeout event fires rather than the user event."

I see I have a number of downloads but so far no words of wisdom. I'll just assume everyone is stumped for now. I think I will submit this to ni.com to see what they have to say about this.

Sincerely,

Don

Link to comment
"if the user event has been triggered from the subVI, it will not trigger from

the main VI. And no error is present upon 'Generate User Event', it just does not work."

What I should have said instead of "it just does not work" is that a "timeout event fires rather than the user event."

Don,

I had a try at your example and found, that the user event does never fire in the main.vi as long the sub.vi is runnig. Triggering in the sub.vi does not make any difference.

The reason for that behaviour is actually rather simple:

1. There are 2 user events, let me call them "stop" and "invert" for short.

2. There are 2 event structures, one in the main.vi the other in the sub.vi.

3. The "stop" event is to fire in the sub.vi event structure.

4. The "invert" event is to fire in the main.vi event structure - which it refuses to do.

In your example you registered both events with both event structures.

You get the idea ? :rolleyes:

If you separate the events and only register each event to the one event structure it is supposed to fire things will work just as you described them in the first place!

Anke

Link to comment

Thanks for your reply.

The problem becomes how do you make it work when you want to fire the same event both from the subvi and the main using an efficient user event strategy.

If you want to see what we came up with, I was working with someone on ni.com and we came up with a good architecture for this type of problem that uses queuing in combination with a user event to do what I need. A producer-consumer architecture is also employed (but not really necessary to demonstrate the solution for this problem).

Here is the thread and the most recent architecture.

Sincerely,

Don

Download File:post-115-1134420948.llb

Link to comment

In the last example you made quite substantial changes to your first design and I think that way it looses much of its original charme.

I believe that is not necessary at all.

I tried to make your VIs work, just handling the user event separately, as I described in my first post.

Nothing else in the structure had to be changed.

Please have a look at my modifications (I am sorry but I left your comments on the main VIs front panel).

Download File:post-3175-1134505566.llb

Anke

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.