Test and Measurement Forum

Unable to ps2000_run_streaming_ns for PS 2204, using C#

Post your .Net discussions here

Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby ruff » Mon Apr 08, 2013 3:51 pm

Hello everyone,

I have a problem calling "ps2000_run_streaming_ns" for a Picoscope 2204 in C#.
I only get back "0" as status.
Am I right, that with a 2204 you cannot use ps2000_run_streaming, but have to use ps2000_run_streaming_ns?

After I opened the device I do this:
Code: Select all
        short status;
        int range = 8;
        status = Imports.SetChannel(_handle, 0, 1, 1, range);

        Console.WriteLine("Collect streaming triggered...");

        short auto_trigger_ms = 0; // start recording after x seconds, even if trigger was not found
        short threshold = 10000; //  (mv/range)*maxValue32512
        short source = 0; // channel A

        status = Imports.ps2000_set_trigger(_handle, source, threshold, 0, 0, auto_trigger_ms);

        uint sampleCount = BUFFER_SIZE;


        uint timeInterval = 1;
        uint maxSamples = 1000;
        uint noOfSamplesPerAggregate = 1; // samples that will be merged together
        int timeUnits = 1; //milliseconds is 4

        status = Imports.ps2000_run_streaming_ns(_handle, timeInterval, timeUnits, maxSamples, 0, noOfSamplesPerAggregate, 1000);

        Console.WriteLine("Run Streaming with status: {0}", status);


And I imported as follows:
Code: Select all
        [DllImport(_DRIVER_FILENAME, EntryPoint = "ps2000_run_streaming_ns")]
        public static extern short ps2000_run_streaming_ns(
                                            short handle,
                                            uint sample_interval,
                                            int time_units,
                                            uint max_samples,
                                            short auto_stop,
                                            uint noOfSamplesPerAggregate,
                                            uint overview_buffer_size);
ruff
Newbie
 
Posts: 0
Joined: Mon Mar 04, 2013 12:24 pm

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby Martyn » Tue Apr 09, 2013 9:29 am

With a time interval of 1 and time units of 1 you are asking for 1psec sample interval which is out of range for the scope. Try appropriate values and you should find it works.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby ruff » Tue Apr 09, 2013 12:24 pm

Oh, I'm sorry that was only a temporary state.
Of course, I tried longer intervals for every time_unit.

In the meantime I changed the import slightly:
short time_units instead of int time_units

No success.

Using the 2204 Picoscope in C# is killing me. Without the right examples, I even have to question my driver imports.
And debugging is hell here. Last time it took me about a week to get the triggered block mode to work. And now run streaming.
ruff
Newbie
 
Posts: 0
Joined: Mon Mar 04, 2013 12:24 pm

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby Martyn » Tue Apr 09, 2013 1:35 pm

Can you try with

Code: Select all
        uint timeInterval = 1;
        uint maxSamples = 1000000;
        uint noOfSamplesPerAggregate = 1;
        int timeUnits = 3; //should be int and try usecs
        uint overview_buffer_size= 20000; //This is the parameter that matters
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby ruff » Wed Apr 10, 2013 7:44 am

Hooray! Thank you very much! I get a 1 as status back now.
So the problem was the values of the parameters? How can I know that?

Hopefully you can see the need of a C# example for the 2000 series.
ruff
Newbie
 
Posts: 0
Joined: Mon Mar 04, 2013 12:24 pm

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby Martyn » Wed Apr 10, 2013 8:15 am

The 2204/2205 use our older 2000 driver model which returns 0 for an error, and a non zero value for OK. The newer drivers return error codes, one of which is "Invalid parameter".

We would like to be able to produce examples covering all languages and all devices however our resources are limited and so we have to make choices. Hopefully we will get to add a C# example at some stage.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby drewian » Mon Feb 08, 2016 4:43 pm

Also ssing C#I have a similar problem, I get a status of 0 back from my call to ps2000_run_streaming_ns.

The previous calls to ps2000_open_unit(), ps2000_set_channel() and ps2000_set_trigger() all succeed.
I define ps2000_run_streaming_ns like so:
Code: Select all
[DllImport("ps2000.dll")]
        public static extern unsafe short ps2000_run_streaming_ns(short handle, ulong sample_interval, ReportedTimeUnits time_units, ulong max_samples, short auto_stop, ulong noOfSamplesPerAggregate, ulong overview_buffer_size);

ReportedTimeUnits is defined as int.


I call the function like so:
Code: Select all
if (ps2000_run_streaming_ns(pico_scope_handle, 1, ReportedTimeUnits.MicroSeconds, 2000, 0, 100, 15000) == 0)
                {
                    tbConsole.AppendText("Pico: Streaming setup FAILED.\n");
                    result = false;
                }


I get the 0 returned each time. I have tried using several different values but to no avail.

Any help much appreciated!

Ian Drew

ps
My full list of configuration steps (which appear to work):
Code: Select all
pico_scope_handle = ps2000_open_unit();
ps2000_set_channel(pico_scope_handle, Channel.PS2000_CHANNEL_A, 1, 1, Range.Range_5V) ;
ps2000_set_channel(pico_scope_handle, Channel.PS2000_CHANNEL_B, 1, 1, Range.Range_5V) ;
ps2000_set_trigger(pico_scope_handle, Channel.PS2000_NONE, 0, Trigger.RISING, 0, 0);
ps2000_run_streaming_ns(pico_scope_handle, 1, ReportedTimeUnits.MicroSeconds, 2000, 0, 100, 15000);
drewian
Newbie
 
Posts: 0
Joined: Mon Feb 08, 2016 4:23 pm

Re: Unable to ps2000_run_streaming_ns for PS 2204, using C#

Postby Hitesh » Wed Feb 10, 2016 4:07 pm

Hi Ian,

Try using uint for an unsigned 32-bit integer instead of ulong - below is the definition from our SDK example:

Code: Select all
[DllImport(_DRIVER_FILENAME, EntryPoint = "ps2000_run_streaming_ns")]
        public static extern short ps2000_run_streaming_ns(
                                                short handle,
                                                uint sample_interval,
                                                ReportedTimeUnits time_units,
                                                uint max_samples,
                                                short autostop,
                                                uint noOfSamplesPerAggregate,
                                                uint overview_buffer_size);

Hope this helps,
Hitesh

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


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

Who is online

Users browsing this forum: No registered users and 0 guests