LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch an event when USB device is plug-ed / unplug-ed?

I want to register for an event that is generated when user unplugs / plugs USB device into PC. I saw solutions in other languages like Delphi and C++ but cannot find a way in Labview...

I don't want to check for devices in a loop, I want to have event generated automatically when this happens.

 

AndrazS_0-1675191515756.png

 

0 Kudos
Message 1 of 7
(1,686 Views)

I suspect you will need to use a .NET event that calls a callback VI and have that VI send a user event to your events case.

 

I would start with this Stackoverflow thread:

https://stackoverflow.com/questions/26975946/detecting-usb-device-insertion-and-removal-in-c-sharp

And try to implement roughly what that person did in, but in LabVIEW using .NET nodes.  

 

This is likely the .NET class to use:

https://learn.microsoft.com/en-us/dotnet/api/system.management.managementeventwatcher?view=netframew...

 

0 Kudos
Message 2 of 7
(1,673 Views)

Any other hint or maybe even VI that does this?

0 Kudos
Message 3 of 7
(1,666 Views)

USB Event Wql Event.png

 

You'd have to fiddle a bit with the 'e' object to get useful info, but it's a start...

Download All
Message 4 of 7
(1,607 Views)

What about continuously checking visa find resource results for changes?

0 Kudos
Message 5 of 7
(1,598 Views)

Thank you, but could you please save this two VIs in 2019 version? Thanks very much

0 Kudos
Message 6 of 7
(1,540 Views)

Thanks  wiebe@CARYA for the soultion, i was trying something similar but your solution works fine.

 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 7
(1,489 Views)