Jump to content

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


Recommended Posts

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!image.png.a42902121b7a6054058ea75c5f54030a.png

WMI_USBStorage_Event_withDeviceIDandTimeOut.vi

Link to comment

Welcome to Lava!

There is no way to intercept WaitForNextEvent, other than generating the event it is waiting for or the timeout occurring. It is, however, possible to handle the event directly in LabVIEW. Are you familiar with .NET Event Callbacks?

Use the Register Event Callback function to execute a callback VI to generate a user event for an Event Structure. The event structure can then take care of the timeout as well as other events that may end execution prematurely. Here is an example. For simplicity reasons I didn't include error handling and the callback VI, but you should be able to work the rest out from here.

1544210445_EventWIthDevice.png.60a809936141ce94eebe144d55b54a10.png

Disclaimer: I haven't tested this, but I'm certain it will do what you want.

Edited by LogMAN
  • Like 2
Link to comment

Thanks for taking a stab at this, LogMAN!

Unfortunately, that did not work. Looks like there is something special about 'WaitForNextEvent' that recognizes system level WMI events that LabVIEW is not able to see. I'm no WMI expert, but I looked at this in terms of dataflow by highlighting execution on the block diagram. It appears that the data just flows through 'Reg Event Callback' node without waiting for the event as soon as the program is run.

I'm going to assume that there is a rather low probability of you having a Toshiba USB stick :)

I modified the code to where it detects the launch of Notepad. This way, you could test it on your system if interested.

Again, thank you for your help.

 

 

WMI_NotepadLaunchEvent_withTimeOut.vi

Edited by Mode_Locked
Link to comment
8 hours ago, Mode_Locked said:

Thanks for taking a stab at this, LogMAN!

Unfortunately, that did not work. Looks like there is something special about 'WaitForNextEvent' that recognizes system level WMI events that LabVIEW is not able to see. I'm no WMI expert, but I looked at this in terms of dataflow by highlighting execution on the block diagram. It appears that the data just flows through 'Reg Event Callback' node without waiting for the event as soon as the program is run.

I'm going to assume that there is a rather low probability of you having a Toshiba USB stick :)

I modified the code to where it detects the launch of Notepad. This way, you could test it on your system if interested.

Again, thank you for your help.

 

 

WMI_NotepadLaunchEvent_withTimeOut.vi 13.21 kB · 1 download

Reg Event Callback is not the thing that waits, it is (as the name implies) merely the registration. It should return immediately. Did you create the callback VI?

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
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.