ps5000aChangePowerSource cannot function correctly

Post your .Net discussions here
Post Reply
gisiu
Newbie
Posts: 0
Joined: Wed Jun 15, 2016 10:28 am

ps5000aChangePowerSource cannot function correctly

Post by gisiu »

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

Hitesh

Re: ps5000aChangePowerSource cannot function correctly

Post by Hitesh »

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.

[The extension cs has been deactivated and can no longer be displayed.]

Regards,

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

Re: ps5000aChangePowerSource cannot function correctly

Post by gisiu »

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

Hitesh

Re: ps5000aChangePowerSource cannot function correctly

Post by Hitesh »

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,

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

Re: ps5000aChangePowerSource cannot function correctly

Post by gisiu »

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

Post by gisiu »

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

Hitesh

Re: ps5000aChangePowerSource cannot function correctly

Post by Hitesh »

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,

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

Re: ps5000aChangePowerSource cannot function correctly

Post by gisiu »

Hi Hitesh,

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

Regards,
Gisiu

Post Reply