LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I de-register a Windows WMI Event watcher before timeout in LV

Solved!
Go to solution

Mode_Locker_1-1599358798116.png

My code watches for an event where my Toshiba USB stick is unplugged. If the event does not occur within 30 secs, the code times out. However, in the case that there is no disconnection of the USB stick (no event generated), I can't end the program before the timeout period of 30 sec. Is there a way to end the program before the timeout period? Any help is appreciated. Thanks in advance!

0 Kudos
Message 1 of 6
(1,886 Views)

I don't think you can...

 

The way to do this (in C#) is to use the Start method, and then use an EventArrivedEventHandler to catch the events asynchronously.

 

This seems to be one of those situations where it makes perfect sense in C#, but no sense at all in LabVIEW.

 

I'd try to figure it out in C#, and then use the .NET C# compiler to make a wrapper assembly for LabVIEW  This avoid the need for Visual Studio.

0 Kudos
Message 2 of 6
(1,799 Views)

See this example:

https://docs.microsoft.com/en-us/dotnet/api/system.management.eventarrivedeventhandler?view=dotnet-p...

 

The EventArrivedEventWatcher is a delegate, and there's no way to use them in LabVIEW:

 

 

 WqlEventQuery query =
            new WqlEventQuery("__TimerEvent",
            "TimerId=\"Timer1\"");

        // Initialize an event watcher and
        // subscribe to timer events
        ManagementEventWatcher watcher =
            new ManagementEventWatcher(query);

        // Set up a listener for events
        watcher.EventArrived +=
            new EventArrivedEventHandler(
            this.HandleEvent);

 

watcher.EventArrived is simply not there, and the EventArrivedEventHandler constructor has two (required) parameters in LabVIEW, the object and a pointer.

 

0 Kudos
Message 3 of 6
(1,797 Views)

@Mode_Locker wrote:

Appreciate the help, wiebe@CARYA!

 

Solution in LabVIEW here:

https://lavag.org/topic/21746-how-do-i-de-register-a-windows-wmi-event-watcher-before-timeout-in-lv/...


I tried the event callback, but didn't get any events. In hindsight, I probably used the normal register for events by mistake.

 

Next time, please let us know if (and where) you cross post questions... Not doing so is frowned upon.

0 Kudos
Message 5 of 6
(1,744 Views)

Also, is there any documentation of these queries? They are related to the Classes, but even then the queries seem to be mostly guesswork.

0 Kudos
Message 6 of 6
(1,742 Views)