Checking Device Manager

Dec 18, 2012
5 Posts

0  |  0  

Re: Checking Device Manager

I do a lot over USB.  I send files to the Unit Under Test.  Sometimes these files change the way Windows "sees" the UUT.  I have to wait for the new device name to show in Device Manager.  I can watch Device Manager and get a feel for how long it may take for this to happen but sometimes it varies.  If windows is slow then I can not perform my next operation in the test and the UUT will falsely fail.

Is there a way to check if the UUT is properly recognized by the operating system?  This way my test can just sit and loop and check the Device Manager and proceed only after the UUT and the PC are ready.

Thanks,
Steve

Victor B.
Lake Forest, CA

Dec 26, 2012
93 Posts

0  |  0  

Re: Checking Device Manager

Hi Steve,

You should use the System.Management assembly to detect system changes such as a USB insertion and after an event is detected, you can read the plug and play registry to see if your target device is installed.  I have attached an example of this.

One important section of the example that I would like to point out is the AddHandlerUsbInsert() procedure.  When we create a WqlEventQuery() and set the properties to define what type of event we are trying to trigger on.  Specifically, we are looking for a "__InstanceCreationEvent" when a device is plugged in.  If we were looking to trigger when a device is removed, we would use "__InstanceDeletionEvent".  Also, we only want to trigger on USB devices, so we set a Condition that the event has to be a 'Win32_USBControllerdevice' rather than 'Win32_PnPEntity' that would cover all plug and play devices.

obQuery = new WqlEventQuery()
obQuery.EventClassName = "__InstanceCreationEvent"
obQuery.WithinInterval = new TimeSpan(0, 0, 3)
obQuery.Condition = "TargetInstance ISA 'Win32_USBControllerdevice'"

Regards,
Victor Brode


File Attachment:
UsbDetection.zip

Feb 14, 2013
5 Posts

0  |  0  

Re: Checking Device Manager

Victor,
   Thanks for the sample code.  I have a couple questions.  I ran this and it "did not work".  I had a co worker sit down and talk me thru it.  I have a couple questions:

In procedure CheckForUsbInsertEvent  the code looks like this:
try
    return m_obWatcher.WaitForNextEvent()
catch
        print "error 1"
    return Nothing
endtry

When we run it, an error is always returned and we get a long string of "error1".  It seems there is a problem with the return statement.

Thanks,
Steve Feeser

Victor B.
Lake Forest, CA

Feb 15, 2013
93 Posts

0  |  0  

Re: Checking Device Manager

Steve,

CheckForUsbInsertEvent() attempts to detect if a user plugs in a USB device.  If the user does not plug in a USB device with five seconds of calling the CheckForUsbInsertEvent() procedure, the procedure will print 'error 1' and return Nothing.  If the user does plug in a device, it will return the insertion event.

Regards,
Victor Brode



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]