Test and Measurement Forum

Detecting a scope before calling ps2000_open_unit

Post general discussions on using our drivers to write your own software here

Detecting a scope before calling ps2000_open_unit

Postby KennyM » Mon Oct 05, 2009 9:43 am

In my new product I'd like to be able to detect if there is a Pico Scope attached before calling ps2000_open_unit().

The reason is that I wish the make the UI as slick and user friendly as possible, so I don't want to do user-nagging such as "Please attach your scope and hit 'connect'", and I can't just keep polling open_unit because it repeatedly displays the PicoScope spash screen.

So, therefore I'd like to detect if a scope is present before I call open_unit() - is there a good way to do this?
-Kenny M.
User avatar
KennyM
Active User
Active User
 
Posts: 19
Joined: Mon Sep 15, 2008 5:51 pm

Postby Robin » Mon Oct 05, 2009 12:11 pm

Hi Kenny

This cannot be done using our driver, but it is possible using the Windows API or .net.

I don't know exactly how it's done, but my understanding is that Windows broadcasts a message whenever a USB device is connected. You would then need to read the device descriptor to determine whether it is the device you are looking for.

Robin
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Postby KennyM » Mon Oct 05, 2009 12:50 pm

Robin,
Thanks again - that sounds like exactly the type of thing I'm looking for.
I'll check MSDN and google....

BTW, I'm using VC 9.0. (Visual Studio 2008) but not .Net
-Kenny M.
User avatar
KennyM
Active User
Active User
 
Posts: 19
Joined: Mon Sep 15, 2008 5:51 pm

Postby KennyM » Mon Oct 05, 2009 4:14 pm

For the benefit of the list lurkers...
This turned out to be quite straightforward.

The Windows API call you need is : RegisterDeviceNotification(...)
With this you register for device notifications, and then you add a message handler to your program which gets called when a WM_DEVICECHANGE arrives.

In your message handler, you check the wParam of the message for DBT_DEVICEREMOVECOMPLETE or DBT_DEVICEARRIVAL, if you have one of these then the lParam points to a struct containing more information.

You then check the device name member of the structure pointed to by the lParam to see if it contain the picotech vendor ID (which is 0x0ce9).

So now you know whether a PicoScope has been attached or removed and you can take the appropriate action.

So, as the meerkat says, "simples".
-Kenny M.
User avatar
KennyM
Active User
Active User
 
Posts: 19
Joined: Mon Sep 15, 2008 5:51 pm

Postby Robin » Tue Oct 06, 2009 8:08 am

Glad you got it working. Thanks for sharing.
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 1 guest