LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait for ActiveX Event

In short: what's the best way to halt execution of a VI until a specific ActiveX event occurs?

 

More details: I just got started working with some ActiveX controls provided by the manufacturer of a new piece of equipment.  I ended up redoing one of their basic VIs (which initializes the equipment) because it was poorly done, in lots of ways.  One thing I noticed was that it used a wait to make sure the equipment was ready, rather than actually checking for the equipment to report that it was done.  This meant unnecessary delay (especially when the equipment had already been initialized, in which case it would report immediately.)

 

The wait was in a case structure permanently wired to select that case.  In the other (inactive) case I saw that someone had tried checking for the initialization event, but hadn't gotten it to work.  They used Create ActiveX Event Queue and Wait On ActiveX Event.  I got that case working--they were off by one letter in the name of the event.  However, while doing some searching I found out that these particular VIs hadn't been part of LabVIEW for a number of years, and that the replacement was Register Event Callback.  I figured it would be best to use the newer method, so I implemented that instead.

 

The problem is, when all I want to do is pause until I get the event, using a callback is really clunky.  (At least, my method is.  Then again, I've never used this before, in LabVIEW or elsewhere.)  I ended up creating a user event and passing it to the callback function.  When the event occurred and the callback ran, it would generate a user event.  Meanwhile, back in the parent VI I registered the event and put the rest of the code in an event structure, so that it wouldn't run until the event occurred.  (See the attached screenshot for how I had this set up; this arrangement is at the bottom, while the two old/obsolete VIs are at the top.)

 

Just looking at the screenshot, the bottom one is much more complicated, has to call a subVI, and is much less clean/elegant than the two simple VIs at the top of the screenshot.

 

So, is there a better/simpler way to do this, using callbacks?  If I instead go with the obsolete, much simpler code, how great is the danger that NI will completely remove support for the two VIs I'd be using?

 

Many thanks,

Michael

0 Kudos
Message 1 of 5
(5,019 Views)
Unfortunately, the event structure does not support ActiveX events, so you have to either use your method, or create a dummy control (can be hidden), and pass a reference to this control to your callback VI. In the callback you can set the "Value (signaling)" property, and you can add an event case to handle the value change for that control. The only real thing you gain is not having to create a user event, but at the cost of requiring an additional control. Take your pick.
Message 2 of 5
(5,009 Views)

Hello,

 

I ran into a similar problem with activeX - I need to detect an event from the activeX-controlled equipment, and then the application should do something else... which is why the callback VI option is not so good for me.

The LabView help file says Event structure can be used to dynamically register for ActiveX events, but I did not succeed to do that. The output of RegisterEventCallback does not connect to Event Structure. 

 

I will use the dummy control option you described above, if nothing else will work. But you mentioned user events - how can it be done with user events? I've wasted quite a while on trying to figure out how to work with user events, and I can't say I understand...

Any help will be very welcome... Thanks!

 

Michal  

 

 

0 Kudos
Message 3 of 5
(4,861 Views)

michalm wrote:

Hello,

 

I ran into a similar problem with activeX - I need to detect an event from the activeX-controlled equipment, and then the application should do something else... which is why the callback VI option is not so good for me.


Why not? Are you saying that in your case your application has to sit there and wait for something to occur before it can proceed? If so, this can still be done regardless of whether you use a callback VI or not, so I'm not sure I understand why it's not good for you.

 


The LabView help file says Event structure can be used to dynamically register for ActiveX events, but I did not succeed to do that. The output of RegisterEventCallback does not connect to Event Structure. 


Where did you read this? You cannot configure the event structure to directly handle an ActiveX event.

 


But you mentioned user events - how can it be done with user events? I've wasted quite a while on trying to figure out how to work with user events, and I can't say I understand...

You would use a user event in the same way as you would use a dummy control. User events are not completely intuitive. There's an example that ships with LabVIEW called "Programmatically Fire Events" that has user events. Attached is an example that shows both methods of handling ActiveX events: setting the "Value (signaling)" property on a control, or with user events.

Message 4 of 5
(4,851 Views)

In my case the application does not have to wait - there's a motor controlled with ActiveX, and I want to catch the end of the movement and start data acquisition with another device. So I had to catch the event sent by ActiveX. 

I see now that I had to wire the user event to the User Parameter input, which I didn't do. I will try to do it as shown in your example, but probably with the dummy control, it seems easier... 

 

Thank you for your help!

 

Michal 

0 Kudos
Message 5 of 5
(4,836 Views)