LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch USB device plug/unplug events

I'm working on a LABView/C# solution for production test system of a USB device. When LABView code finishes running a numbers of tests on a USB device, the device is unplugged, a new one is plugged in and the LABView repeats the testing. The underlying C# framework has a limitation that requires LABView code to call a function in the C# framework before the new USB device can be communicated with.

 

How can I do this?

 

I tried using the Window message queue library (http://zone.ni.com/devzone/cda/epd/p/id/4394) but it seems to be able to catch the WM_DEVICECHANGE only (twice for each device swap), never DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. I could count the WM_DEVICECHANGE to decide that a swapping has completed, but it is not the best technique.

 

I also got the error (shown in the attached picture) unless I set a breakpoint in the Message Queue library to make LABView stops there before going on.

 

I read something about one need to register for DEV_BROADCAST_DEVICEINTERFACE notification but don't know how to do that in LABView. Or how could it be done in a C# library so LABView can invoke?

 

Please help.

 

Tuyen

 

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

Hi tuyen,

i have some code running in delphi which detects new devices like usb stick. It shows the assigned drive letter which with you can work with.  I'll try to build a labview example for you at weekend.

 

Mike

0 Kudos
Message 2 of 5
(6,571 Views)

Hi Mike,

 

That's great, thank you very much. I'm looking forward to see the code.

 

Regards,

Tuyen

0 Kudos
Message 3 of 5
(6,554 Views)

Hi Tuyen,

 

Hope this helps you.

 

 

Message 4 of 5
(6,543 Views)

Hi tuyen,

i had some time to write the example. It works with windows messages. Attached you'll find it. The Main vi is the "DeviceChangeEvent_Example.vi".

 

Hope it helps.

Mike

Message 5 of 5
(6,493 Views)