Test and Measurement Forum

Problem with ps5000aOpenUnit in C

Having problems ? let us know the details here

Problem with ps5000aOpenUnit in C

Postby jbl » Fri Dec 16, 2016 3:17 pm

Hi,
I'm a new user of the libps5000a.so library with gcc on a Raspberry.
I have written my first C program with this library. No problem for linking and the functions are fully called by the main program.

The first I've used is : ps5000aEnumerateUnits. It gives results. The picoscope is detected, its serial number is obtained.

The second one is ps5000aOpenUnits. It doesn't work. The return handle is -1 that means "The scope fails to open".

I wonder if there is something to do before executing my C program. The LED in front of the Pico is still red. I have connected the pico to the usb and the usbtest program gives good result. Any idea ?

Thank you for your help.
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby Hitesh » Tue Dec 20, 2016 9:15 am

Hi jbl,

Have you tried running your application using the sudo command?

Regards,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2514
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Wed Dec 21, 2016 9:47 am

Hi Hitesh,
Yes, I have tried running it with sudo command or as root.
Do you think that the raspberry usb ports give enough current for the picoscope ?
The pico is supplied with a double usb plug. Perhaps should I use an external power unit.
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby Hitesh » Wed Dec 21, 2016 10:21 am

Hi jbl,

It's possible that this could be the case.

Which PicoScope device are you using? If it is a 2-channel device, please use the dual-headed USB cable.

You can also use this power supply with the device. This is the power supply that is provided in the box with 4-channel models.

Regards,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2514
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Wed Jan 04, 2017 10:50 pm

Hi Hitesh,
Thank you for your help.
I'm using a 5244A dual channel Picoscope and I'm using the dual-headed USB cable.
I have also tried to plug the power head in an auxiliary PC USB port and the second head in the Rasp.
No result.
Last edited by jbl on Thu Jan 05, 2017 11:15 am, edited 1 time in total.
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby Hitesh » Thu Jan 05, 2017 10:41 am

Hi jbl,

Could you please post your code here or e-mail it to support@picotech.com?

We can then see how the calls are being made to the driver.

Thanks,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2514
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Thu Jan 05, 2017 11:30 am

Here is the very simple code (perhaps too simple) :

#include <stdio.h>
#include "PicoStatus.h"
#include "ps5000aApi.h"
main(){
int16_t handle,nb,serialLg=80;
char serial[80];
PICO_STATUS device,channel;
printf("Hello Picoscope\n");

device=ps5000aEnumerateUnits(&nb,serial,&serialLg);

printf("Number of picoscopes %d\nPicoscopes : %s\n",nb,serial);

device=ps5000aOpenUnit(&handle,serial,8);
printf("handle : %d\ndevice : %x\n",handle,device);

channel=ps5000aSetChannel(handle,PS5000A_CHANNEL_A,1,PS5000A_DC,PS5000A_1V,0.0F);
printf("channel : %x\n",channel);
}

.h and .so files are in the current directory with the .c file

Compilation command : gcc Pico.c libps5000a.so
Execution command : ./a.out

This program displays :

Hello Picoscope
Number of picoscopes 1
Picoscopes : CS241/110
handle : -1
device : 3f
channel : c

Regards
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby Hitesh » Thu Jan 05, 2017 1:04 pm

Hi jbl,

Thank you for posting the code.

Referring to this line:

Code: Select all
device=ps5000aOpenUnit(&handle,serial,8);

The resolution value of 8 is not correct. You need to use one of the enumeration values from the header file:

Code: Select all
typedef enum enPS5000ADeviceResolution
{
  PS5000A_DR_8BIT,
  PS5000A_DR_12BIT,
  PS5000A_DR_14BIT,
  PS5000A_DR_15BIT,
  PS5000A_DR_16BIT
} PS5000A_DEVICE_RESOLUTION;

Also, note that trying to pass the serial value to the ps5000aOpenUnit() function if multiple units are returned from the ps5000aEnumerateUnits() function might not work.

Hope this helps,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2514
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Thu Jan 05, 2017 1:10 pm

Good !
It's working with PS5000A_DR_8BIT.
The display is :

handle : 1
device : 11a
channel : 0

Thank you very much.
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Thu Jan 05, 2017 2:52 pm

Well, it's not so good.
If we check the 11a return value in the documentation. It's better than 3f (PICO_NOT_USED).
11a gives : PICO_POWER_SUPPLY_NOT_CONNECTED.
Perhaps it means that an external power supply is mandatory to play with this library ...
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm

Re: Problem with ps5000aOpenUnit in C

Postby Hitesh » Thu Jan 05, 2017 3:06 pm

You will need to pass this status code to the ps5000aChangePowerSource() function which is documented in the Programmer's Guide.

This functionality is shown in the SDK example.

Hope this helps.
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2514
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with ps5000aOpenUnit in C

Postby jbl » Thu Jan 05, 2017 3:29 pm

Thanks, it seems to be ok now.
The returned value is 0 (PICO_OK) and the red led in front of the Pico turned off.
jbl
User
User
 
Posts: 8
Joined: Fri Dec 16, 2016 2:35 pm


Return to Getting Started

Who is online

Users browsing this forum: No registered users and 1 guest