Test and Measurement Forum

ps5000aChangePowerSource cannot function correctly

Post your .Net discussions here

ps5000aChangePowerSource cannot function correctly

Postby gisiu » Wed Jun 15, 2016 11:00 am

Hi,

My oscilloscope is 5244B. I use PS5000A API and my developing language is C#.

I run the example PS5000ABlockCapture first. But an error occurs in RunBlock. It returns PICO_POWER_SUPPLY_NOT_CONNECTED. So I add a function ChangePowerSource(handle, PICO_POWER_SUPPLY_NOT_CONNECTED) before the RunBlock. Then the example works well.

Next, I try to build my own application (I use only two channel). However, in my application, ChangePowerSource(handle, PICO_POWER_SUPPLY_NOT_CONNECTED) returns PICO_INVALID_PARAMETER and RunBlock returns PICO_POWER_SUPPLY_NOT_CONNECTED) again. I cannot find out what the error is.

By the way, the namespace of PS5000AImports.cs is wrong (originally something like PS5000AStreamingConsole), it should be corrected as PS5000A.

Thank you for any assistance
Gisiu
gisiu
Newbie
 
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am

Re: ps5000aChangePowerSource cannot function correctly

Postby Hitesh » Wed Jun 15, 2016 11:21 am

Hi Gisiu,

If you call ChangePowerSource() after OpenUnit() does it return PICO_OK?

It might be useful to see your application code.

We are aware of an error in the imports file. Below is an updated file which specifies the namespace as PS5000AImports.

PS5000AImports.cs
Updated PS5000AImports.cs file
(23.96 KiB) Downloaded 16 times


Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2009
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: ps5000aChangePowerSource cannot function correctly

Postby gisiu » Thu Jun 16, 2016 6:37 am

Hi Hitesh,

Originally, the outline of my application is as follows:

OpenUnit(): return PICO_POWER_SUPPLY_NOT_CONNECTED
SetChannel(): return PICO_OK
SetDataBuffer(): return PICO_OK
GetTimeBase2(): return PICO_OK
ChangePowerSource(): return PICO_INVALID_PARAMETER
RunBlock(): return PICO_POWER_SUPPLY_NOT_CONNECTED

Now, if I move ChangePowerSource() to right after OpenUnit(), it returns PICO_POWER_SUPPLY_NOT_CONNECTED instead of PICO_INVALID_PARAMETER. And RunBlock() still returns PICO_POWER_SUPPLY_NOT_CONNECTED.

Thank you
Gisiu
gisiu
Newbie
 
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am

Re: ps5000aChangePowerSource cannot function correctly

Postby Hitesh » Thu Jun 16, 2016 7:51 am

Hi Gisiu,

When the OpenUnit function returns PICO_POWER_SUPPLY_NOT_CONNECTED, you need to then call the ChangePowerSource() function before you continue to start configuring your oscilloscope.

Please post your code so that we can see the actual call sequence and the parameters being passed to the calls. Are you targeting 'Any CPU' in your IDE or a specific platform?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2009
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: ps5000aChangePowerSource cannot function correctly

Postby gisiu » Thu Jun 16, 2016 8:17 am

Hi Hitesh,

Here is my code. I am targeting any CPU.

Code: Select all
   private void button_openunit_Click(object sender, EventArgs e)
        {
            bool pico_enable = true;
            short _handle = 0;
            short[] _buffers;
            uint _timebase = 5;
            uint sampleCount;
            short status;

            Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_8BIT;
            short handle;

            status = Imports.OpenUnit(out handle, null, resolution);
            System.Console.WriteLine("OpenUnit status: " + status.ToString());

            if (handle > 0)
            {
                _handle = handle;
                status = Imports.ChangePowerSource(_handle, (short)Imports.PICO_POWER_SUPPLY_NOT_CONNECTED);
                System.Console.WriteLine("ChangePowerSource status: " + status.ToString());
            }
            else
            {
                System.Console.WriteLine("handle: " + handle.ToString());
                pico_enable = false;
            }

            if (pico_enable == false) return;

            status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, 1, Imports.Range.Range_5V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 1, 1, Imports.Range.Range_200mV, 0);
            System.Console.WriteLine("SetChannel status: " + status.ToString());

            // Set trigger
            short enable = 1;
            short threshold = 5000;
            uint delay = 0;
            status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, 0);
            System.Console.WriteLine("SetSimpleTrigger status: " + status.ToString());

            _callbackDelegate = BlockCallback;

            // Set data buffer
            sampleCount = 1000;
            _buffers = new short[sampleCount];
            status = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelA, _buffers, (int)sampleCount, 0, Imports.RatioMode.None);
            System.Console.WriteLine("SetDataBuffer status: " + status.ToString());

            // Get time base
            float timeInterval;
            int maxSamples;

            while (Imports.GetTimebase2(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
            {
                _timebase++;
                System.Console.WriteLine("GetTimeBase2 status: " + status.ToString());
            }

            _ready = false;

            int timeIndisposed;

            status = Imports.RunBlock(_handle, 100, (int)sampleCount - 100, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
            System.Console.WriteLine("RunBlock status: " + status.ToString());

        }
gisiu
Newbie
 
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am

Re: ps5000aChangePowerSource cannot function correctly

Postby gisiu » Thu Jun 16, 2016 8:35 am

Hi Hitesh,

I try to configure my project to target to "x86" instead of "Any CPU". Then it works! (But I don't know why)

Thank you for your help.

Regards,
Gisiu
gisiu
Newbie
 
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am

Re: ps5000aChangePowerSource cannot function correctly

Postby Hitesh » Thu Jun 16, 2016 10:32 am

Hi Gisiu,

When you switch to 'Any CPU' I suspect, the application is being run as a 64-bit version and picking up 64-bit drivers.

If any data types are incorrect, this can cause an issue and looking at your code you are using a short data type for the status values as opposed to a uint (unsigned 32-bit integer) data type which is what a PICO_STATUS type is defined as in the PicoStatus.h C header file.

For example:

Code: Select all
uint status;

Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_8BIT;
short handle;

status = Imports.OpenUnit(out handle, null, resolution);
System.Console.WriteLine("OpenUnit status: " + status.ToString());

if (handle > 0)
{
        _handle = handle;
         status = Imports.ChangePowerSource(_handle, Imports.PICO_POWER_SUPPLY_NOT_CONNECTED);
          System.Console.WriteLine("ChangePowerSource status: " + status.ToString());
}
else
{
         System.Console.WriteLine("handle: " + handle.ToString());
         pico_enable = false;
}

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2009
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: ps5000aChangePowerSource cannot function correctly

Postby gisiu » Thu Jun 16, 2016 2:23 pm

Hi Hitesh,

Your response really help me solve my problem. Many thanks for your assistance.

Regards,
Gisiu
gisiu
Newbie
 
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests