Detecting a scope before calling ps2000_open_unit

Post general discussions on using our drivers to write your own software here
Post Reply
User avatar
KennyM
Active User
Active User
Posts: 19
Joined: Mon Sep 15, 2008 5:51 pm

Detecting a scope before calling ps2000_open_unit

Post by KennyM »

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.

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Post by Robin »

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

User avatar
KennyM
Active User
Active User
Posts: 19
Joined: Mon Sep 15, 2008 5:51 pm

Post by KennyM »

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

Post by KennyM »

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.

Robin
Advanced User
Advanced User
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Post by Robin »

Glad you got it working. Thanks for sharing.

Post Reply