PicoScope3204 - multiple runBlock

Post your .Net discussions here
mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

PicoScope3204 - multiple runBlock

Post by mosine »

Hi,
I have problem with multiple RunBlock. My Application is based on SDK example. My steps are:
for cycle
- initdevice (only first time)
- set channel to 10V
- set timebase to 100 ns
- set trigger
- read data

From second read, I have error on this line:

Code: Select all


           _ready = false;
            _callbackDelegate = BlockCallback;
            do
            {
                retry = false;
                status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, _oversample, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                Thread.Sleep(200);
                if (status == (short)Imports.PICO_POWER_SUPPLY_CONNECTED || status == (short)Imports.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)Imports.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    status = PowerSourceSwitch(_handle, status);
                    retry = true;
                }
                else
                {
                    //return false;
                }
            }
            while (retry);

            Imports.Stop(_handle);

            if (_ready)    //<------- is false

What's my problem?
Thanks in advance

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: PicoScope3204 - multiple runBlock

Post by Martyn »

I am posting from a phone so can't give full detail but try making the program flow :-

Open Scope

Setup Scope

Setup Triggers

Setup Buffers

In a loop
(
RunBlock

Wait for Ready

Read Data
)
Stop Scope

Close Scope
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
Thannk you for reply. My second read has problem: PICO_CANCELLED and _retry = false.
What do you mean about setup Pico?
can you post an example?

Thanks

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
I have the same problem.

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: PicoScope3204 - multiple runBlock

Post by Martyn »

Setup PicoScope -> Configure channels, timebase etc

Have you moved the Stop function so it is at the very end. You don't need to stop after each block collection.
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
thank you for replies.
I understand my problem. I develop picoscope dll (I call it from Form...) and I can't wait the callback function (ps3000aBlockReady -> return _ready). The first block is fast (_ready=true), but the block is not fast from second read (_ready=False).
Now, I don't know if move dll into Form or not...
Thanks

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
can you suggest something?
Thanks

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: PicoScope3204 - multiple runBlock

Post by Martyn »

Does the example code that we provide in the SDK work as supplied ?
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
thank you for reply.

I used as example: C:\PicoSDK\PS3000A\C# console.

If you see in previous posts, my code is similar (now I remove Imports.Stop(_handle)).

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
I used example SDK: PicoSDK\PS3000A\C# console

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
I post my code: part of code of Form and my picoscope dll.
My application works:
- an event call function to handle picoscope
- starts handle form -> dll

I followed your suggest (stop, close...), but I have the same problem.

Can you help me?

Thanks in advance.
Attachments

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

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


Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: PicoScope3204 - multiple runBlock

Post by Martyn »

You are not waiting for the CallBack to set the ready flag.

The console example waits for ready or a key press

Code: Select all

            while (!_ready && !Console.KeyAvailable)
            {
                Thread.Sleep(100);
            }
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
can you suggest me something?
Thanks

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: PicoScope3204 - multiple runBlock

Post by Martyn »

You need to add in

Code: Select all

 while (!_ready)
{
    Thread.Sleep(100);
}
to make sure that you wait for the scope to have collected the data before attempting to retrieve it.
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: PicoScope3204 - multiple runBlock

Post by mosine »

Hi Martin,
I finally solved my problem.
I changed my code (very similar at SDK example):
- I open communication (init) with Picoscope by Form
- I create dll object and pass handle as constructor

I think that were thread problems between Form and dll.

Thanks for your patience.

Post Reply