LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

USB hot-plugin - how to detect

My application uses VISA to talk to several USB RAW devices (all proprietary). My applications needs to get an event when the device has been un-plugged or a new device is plugged in so it can then query the device type. How can I do that? Below is settable attribute list for device (the other devices are the same). Thanks in advance,

Chuck


VI_ATTR_USER_DATA = 0x00000000
VI_ATTR_MAX_QUEUE_LENGTH = 50
VI_ATTR_TMO_VALUE = 2000
VI_ATTR_TERMCHAR = 0x0A
VI_ATTR_TERMCHAR_EN = VI_FALSE
VI_ATTR_IO_PROT = 1
VI_ATTR_SUPPRESS_END_EN = VI_FALSE
VI_ATTR_USB_MAX_INTR_SIZE = 1
VI_ATTR_USB_BULK_OUT_PIPE = 2
VI_ATTR_USB_BULK_IN_PIPE = 130
VI_ATTR_USB_INTR_IN_PIPE = -1
VI_ATTR_USB_ALT_SETTING = 0
VI_ATTR_USB_INTR_IN_STATUS = -1
0 Kudos
Message 1 of 6
(4,234 Views)
Hi Chuck,

I'm sorry to say there is not a VISA function that can recognize this event. What you can do is write your own driver to recognize when the devices are plugged in or unplugged using the VISA Driver Development Wizard. You can find this by going to Start>>All Programs>>National Instruments>>VISA>>VISA Driver Development Wizard. I'm sorry that it's not easier, but this is the best way to go.

Thanks!

JenK
0 Kudos
Message 2 of 6
(4,220 Views)
I re-ran the VISA Driver Development Wizard per your suggestion because I didn't recall it creating anything programmable. Sure enough, it created a .inf file that has info about my raw device but I didn't see anything in it that would allow me to detect connections. Did I miss something? Is there a .DLL or other piece of software that created as a side-effect?

Chuck
0 Kudos
Message 3 of 6
(4,219 Views)
Hi Chuck,

This tutorial, Using NI-VISA 3.0 to Control Your USB Device, explains how to use the driver development wizard for a USB device. It should answer your questions. Thanks!

JenK
0 Kudos
Message 4 of 6
(4,184 Views)
Let me give some background because I am obviously not communicating well.

I have several types of proprietary USB cameras. I have been talking to them successfully via USB for over a year. I already have a very good INF file. USB communication is not a problem. I have read every USB tutorial or other documentation that I have found published by NI.

My specific issue is hot-plugin. USB supports hot-plugin. When I plug in my USB camera, my Windows XP OS recognizes the fact and informs me by playing a nice little ascending arpeggio on the sound card. XP's hardware profile is updated and it recognizes the manufacturer and model number of my camera. When I unplug the camera, XP detects the event and plays a descending arpeggio. Clearly XP supports hot-plugin/plugout and my camera is properly informing XP of its manufacturer and model number.

When I hot plugin a camera, my software can manually start a VISA session and talk to the camera --- no problem. The problem is, the user has to *INFORM* the software to start the session. What I need is a VISA event that informs the software of a hot plugin so the software can autonomously start the session without operator intervention. Likewise, I need a VISA event that informs the software of a hot plugout so the software can autonomously cease communicating with the camera. Otherwise, software assumes the camera is still there and times out on the next USB activity.

I have seen nothing in NI's documentation that describes how VISA can detect a USB plug-in or plug-out. Please tell me there is a little-known document somewhere that describes how to do this. Right now, the only option I have is to periodically poll the USB bus to see if any new cameras have been attached. I hate polling.

I carefully read your response about the VISA Driver Development Wizard. Correct me if I am wrong but as far as I can tell, all it does is create an .inf file for XP. I even re-ran it and created a new .inf file to see if I was missing something. Are you suggesting that I write my own XP driver? Replace VISA? Is there a template for a VISA USB driver that I could modify? Please explain.

Chuck

Message Edited by Chuck_in_dallas on 05-16-2005 11:45 AM

Message Edited by Chuck_in_dallas on 05-16-2005 11:46 AM

0 Kudos
Message 5 of 6
(4,179 Views)
Hi Chuck,

According to this KB, when you create an .inf file for a specific USB device and plug the device in, Windows reads the device information and uses the vendor and model number to search through the .inf files. When a matching .inf file is located Windows binds the driver listed as the owner to the device. This sounds like what you might be looking for, please correct me if I am wrong.

JenK
0 Kudos
Message 6 of 6
(4,147 Views)