Getting a list of available devices

Post your .Net discussions here
Post Reply
Simon
Newbie
Posts: 0
Joined: Fri Jun 01, 2012 10:26 am

Getting a list of available devices

Post by Simon »

Hello

I'm trying to get a list of all available devices connected to my computer. Currently I am only intrested in PS5000 devices but this may change in the future to include other ranges.

Is there an easy way to do this? I have found the ps5000aEnumerateUnits command in the programmers manual, this command however does not seem to be included in the PS500AImports.cs file. I have tried adding the following to the file

Code: Select all

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aEnumerateUnits")]
public static extern DataAqu_PicoScope.PicoStatus EnumerateUnits(out short Count, out StringBuilder SerialCSV, out short SerialCSV_Length);
and then calling it with the following

Code: Select all

short deviceCount;
StringBuilder serialCSV = new StringBuilder(); 
short stringLength;
MyImports.EnumerateUnits(out deviceCount, out  serialCSV, out  stringLength);
I'm getting an access violation exception when calling EnumerateUnits

Thanks for any help

Simon
Last edited by Simon on Wed Aug 05, 2015 1:58 pm, edited 1 time in total.

Hitesh

Re: Getting a list of available devices

Post by Hitesh »

Hi Simon,

Try allocating some memory for your string e.g. create a string of 40 characters and set the length parameter accordingly.

The crash is probably occurring as the driver is not able to write the information anywhere.

Hope this helps.

Simon
Newbie
Posts: 0
Joined: Fri Jun 01, 2012 10:26 am

Re: Getting a list of available devices

Post by Simon »

ok so I have now made a few changes to my code, see below.

Code: Select all

 [DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aEnumerateUnits")]
 public static extern DataAqu_PicoScope.PicoStatus EnumerateUnits(out short Count, out StringBuilder SerialCSV, ref short SerialCSV_Length);

Code: Select all

 //Test Code
            short deviceCount;
            StringBuilder serialCSV = new StringBuilder(40);
            short stringLength = 40;
            MyImports.EnumerateUnits(out deviceCount,out serialCSV, ref stringLength);
//Test Code End
This still brings up the same errors.

Simon

Hitesh

Re: Getting a list of available devices

Post by Hitesh »

Hi Simon,

Just ran some tests here - the StringBuilder object needs to be passed as is once you have allocated a size i.e. without an 'out' or a 'ref' keyword prefix.

Here's the declaration to use:

Code: Select all

[DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aEnumerateUnits")]
        public static extern uint EnumerateUnits(
                                                    out short count,
                                                    StringBuilder serials,
                                                    ref short serialLength);
Below is some of the code used to test it with:

Code: Select all

short count = 0;
short serialsLength = 40;
StringBuilder serials = new StringBuilder(serialsLength);

uint status = Imports.EnumerateUnits(out count, serials, ref serialsLength);

if (status != Imports.PICO_OK)
{
  Console.WriteLine("No devices found.\n");
  Console.WriteLine("Error code : {0}", status);
  Console.WriteLine("Press any key to exit.\n");
  WaitForKey();
  Environment.Exit(0);
}
else
{
   if(count == 1)
   {
     Console.WriteLine("Found {0} device:", count);
   }
   else
   {
     Console.WriteLine("Found {0} devices", count);
   }

    Console.WriteLine("Serial(s) {0}", serials);
}
This function definition will be in the imports file in a future SDK release.

Regards,

Simon
Newbie
Posts: 0
Joined: Fri Jun 01, 2012 10:26 am

Re: Getting a list of available devices

Post by Simon »

Thanks for that, I now have it running perfectly in my app

Simon

Simon
Newbie
Posts: 0
Joined: Fri Jun 01, 2012 10:26 am

Re: Getting a list of available devices

Post by Simon »

Sorry to resurrect a really old post but I am having to update my app from a few years ago and the ps5000aEnumerateUnits call is giving me problems again.

I'm having to update the picoscope drivers that I'm using as the new versions of the PS5000 with USB3 have started coming through.
The drivers that I was previously using were:-
PS5000a.dll version 1.1.4.39
Picolpp.dll version 1.1.2.52

I have swapped these out for the following versions
PS5000a.dll version 2.1.27.184
Picolpp.dll version 1.3.0.29

When I call ps5000aEnumerateUnits it returns the correct number of connected devices but the string that contains the serial numbers of the devices is always empty..

Any thoughts?

Post Reply