PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Checking if USB device is plugged in

 
 
beaker
Guest
Posts: n/a
 
      10th Nov 2006

Hi,

I'm looking for a way of checking whether a specific USB device (a
webcam) is plugged in. I have the Vendor and Product ID numbers for the
device.

I found an article (http://www.vsj.co.uk/articles/display.asp?id=600)
with code sample that does the trick for human input devices (mouse,
keyboard, ...) but am struggling for my webcam.

Any help appreciated, thanks.

Gary
 
Reply With Quote
 
 
 
 
andrew queisser
Guest
Posts: n/a
 
      10th Nov 2006
"beaker" <(E-Mail Removed)> wrote in message
news:OxQQ%(E-Mail Removed)...
>
> Hi,
>
> I'm looking for a way of checking whether a specific USB device (a webcam)
> is plugged in. I have the Vendor and Product ID numbers for the device.
>
> I found an article (http://www.vsj.co.uk/articles/display.asp?id=600) with
> code sample that does the trick for human input devices (mouse, keyboard,
> ...) but am struggling for my webcam.
>
> Any help appreciated, thanks.
>
> Gary


Gary,

It's easy outside of .NET if you handle the WM_DEVICECHANGE message. Below
is a snippet of a MFC program that does that. It shouldn't be hard to map
this to .NET, here's a discussion of just that, I haven't tried it myself:

http://www.codecomments.com/archive2...-4-185490.html

My MFC (edited) code snippet:

BOOL CConfigWinDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
{
DEV_BROADCAST_DEVICEINTERFACE *devInterface;
DEV_BROADCAST_HDR *brHeader = (DEV_BROADCAST_HDR *)dwData;

switch (nEventType)
{
case (DBT_DEVICEARRIVAL):
if (brHeader && brHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
devInterface = (DEV_BROADCAST_DEVICEINTERFACE *)brHeader;
if (strstr(strupr(devInterface->dbcc_name), "VID_0403&PID_6006"))
{
// my device plugged in
// do something cool
}
else
{
// some other device plugged in
}
}
else
{
// unknown device plugged in
}
}
break;

// other cases
}
[snip]


 
Reply With Quote
 
beaker
Guest
Posts: n/a
 
      13th Nov 2006
andrew queisser wrote:
> "beaker" <(E-Mail Removed)> wrote in message
> news:OxQQ%(E-Mail Removed)...
>
>>Hi,
>>
>>I'm looking for a way of checking whether a specific USB device (a webcam)
>>is plugged in. I have the Vendor and Product ID numbers for the device.
>>
>>I found an article (http://www.vsj.co.uk/articles/display.asp?id=600) with
>>code sample that does the trick for human input devices (mouse, keyboard,
>>...) but am struggling for my webcam.
>>
>>Any help appreciated, thanks.
>>
>>Gary

>
>
> Gary,
>
> It's easy outside of .NET if you handle the WM_DEVICECHANGE message. Below
> is a snippet of a MFC program that does that. It shouldn't be hard to map
> this to .NET, here's a discussion of just that, I haven't tried it myself:
>
> http://www.codecomments.com/archive2...-4-185490.html
>
> My MFC (edited) code snippet:
>
> BOOL CConfigWinDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
> {
> DEV_BROADCAST_DEVICEINTERFACE *devInterface;
> DEV_BROADCAST_HDR *brHeader = (DEV_BROADCAST_HDR *)dwData;
>
> switch (nEventType)
> {
> case (DBT_DEVICEARRIVAL):
> if (brHeader && brHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
> {
> devInterface = (DEV_BROADCAST_DEVICEINTERFACE *)brHeader;
> if (strstr(strupr(devInterface->dbcc_name), "VID_0403&PID_6006"))
> {
> // my device plugged in
> // do something cool
> }
> else
> {
> // some other device plugged in
> }
> }
> else
> {
> // unknown device plugged in
> }
> }
> break;
>
> // other cases
> }
> [snip]
>
>



Thanks, the article you gave the link to does half of what I need, and I
can now detect when the device is plugged in - but I still need to know
if the device is present when my app starts (and so misses the
appropriate event for that method.)

Any ideas?

Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Reboot Needed After USB device plugged in Shenan Stanley Windows XP Hardware 0 14th Jun 2008 04:56 PM
'usb device not recognized' when no device plugged in ningirsu Windows XP Hardware 0 7th Oct 2005 04:50 PM
Event/Notification when a USB device plugged in Charles Law Microsoft VB .NET 4 15th Apr 2004 12:45 PM
HI_SPEED USB device plugged into non-hi-speed usb hub Linda Windows XP Hardware 1 27th Dec 2003 05:45 AM
how XP can identify device when plugged to a USB hub edmund Windows XP Hardware 3 9th Oct 2003 07:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:50 AM.