Test and Measurement Forum

Delphi - INC file incomplete

Post general discussions on using our drivers to write your own software here

Delphi - INC file incomplete

Postby kmajdenic » Sun Jul 18, 2010 9:11 pm

Greetings,

Writting SW for PicoScope 2205 for capturing and analyzing RS232 data (9600 baud). I'm using Delphi 2009 pro and realized that provided INC file is missing declaration for ps2000_get_streaming_last_values and ps2000_run_streaming_ns (among some others). My question would be:

1. Where can I get INC file with declaration of all PicoScope functions
2. Is there any sample code in Delphi for using ps2000_run_streaming_ns function?

Best regards.
kmajdenic
Newbie
 
Posts: 0
Joined: Sun Jul 18, 2010 8:37 pm

Delphi - INC file incomplete (Addenum)

Postby kmajdenic » Mon Jul 19, 2010 8:42 am

I've tried to add this to INC file. It compiles but it reports error (Invalid floating point operation) when I make a call to: ps2000_run_streaming_ns(ScopeHandle, 1, 3, 1000, 0, 1, 20000);
(time interval set to 1 and time unit set to microseconds)


function ps2000_run_streaming_ns
(handle : smallint;
sample_interval : longint;
time_units : longint;
max_samples : longint;
auto_stop : smallint;
noOfSamplesPerAggregate : longint;
overview_buffer_size : longint)
: smallint;
{$IFDEF WIN32} stdcall; external 'ps2000.dll'{$ENDIF}

function ps2000_get_streaming_last_values
(handle : smallint;
GetOverviewBuffersMaxMin: pointer)
: smallint;
{$IFDEF WIN32} stdcall; external 'ps2000.dll'{$ENDIF}
kmajdenic
Newbie
 
Posts: 0
Joined: Sun Jul 18, 2010 8:37 pm

Delphi - INC file incomplete - Seem to be working with 10 us

Postby kmajdenic » Mon Jul 19, 2010 8:49 am

I've changed call into:

ps2000_run_streaming_ns(ScopeHandle, 10, 3, 1000, 0, 1, 20000);

and now it seems to be working (if I understood correctly values 10,3 should be interpreted as 10 x pico2000_uS)
kmajdenic
Newbie
 
Posts: 0
Joined: Sun Jul 18, 2010 8:37 pm

Re: Delphi - INC file incomplete

Postby Robin » Mon Jul 19, 2010 8:59 am

Hi

The Delphi example was written for the older 2000 series scopes that don't support fast streaming.

I don't know much about Delphi, but shouldn't

sample_interval
max_samples
noOfSamplesPerAggregate
overview_buffer_size

be LongWord rather than LongInt?

Robin
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Delphi - INC file incomplete

Postby kmajdenic » Mon Jul 19, 2010 10:11 am

Hi,

Thank you for your kind reply. Yes, you are right regarding longword type but nevertheless my version of INC is working (once I've changed sample interval to be 10 instead of 1).

I've maid it run and at this moment I's struggling with understanding the meaning of call to:

ps2000_get_streaming_last_values(ScopeHandle,@GetDataFromOverviewBuffer);

From what I can see in the manual I have to call this function periodically ... but I do not understand why -

1. isn't enough to call it just once after which Scope DRIVER has pointer to my callback function which does copying from overview buffer into application memory
2. I do not understand the meaning of return value of that function

If you could help me understand logic behind (I've read all previous topics and threads that are dealing with streaming of data and still do not have clear picture).

Best regards.
kmajdenic
Newbie
 
Posts: 0
Joined: Sun Jul 18, 2010 8:37 pm

Re: Delphi - INC file incomplete

Postby Robin » Tue Jul 20, 2010 1:42 pm

Hi

You need to call ps2000_get_streaming_last_values periodically, when you are ready to receive data from the device. The driver will then call in to your code, passing pointers to the location of the new data.

The return value of ps2000_get_streaming_last_values is the number of samples that are available per channel.

Robin
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: Delphi - INC file incomplete

Postby kmajdenic » Tue Jul 20, 2010 5:12 pm

Greetings,

Once again thank you very much for your kind reply. I've put call ps2000_get_streaming_last_values into EXECUTE method of my thread (as you can see later on). In most of thread 'passes' value of NumberOfSamples is equal to 0. Every 8 or 10th pass value of NumberOfSamples changes into 1. Immediately after that my method GetDataFromOverviewBuffer gets called (there I use code which I found in one of previous topics on this forum) but there variable nValues usually have value of 5000 or something like that. That is why I do not see connection between value returned by ps2000_get_streaming_last_values and value given in Callback function.

Can you please comment this and help me understand why do I have such difference in those two values (which suppose to be, by my understandin, more or less close to each other)?

type
TValuesArray = array of array of smallint;
TValuesArrayPtr = ^TValuesArray;

...


procedure THandleScopeThread.Execute;
var
NumberOfSamples: integer;
begin
while (not Terminated) and (not ShutdownThread) do begin
try
Sleep(1);
case ThreadActionStatus of
asExecuting: begin
case UserRequestedAction of
caIdle: begin
// Do nothing
end;
caStart: begin
if HandleScope(caStart) then begin
ThreadActionStatus := asSuccess;
CurrentThreadStatus := caStart;
end else begin
ThreadActionStatus := asFailure;
CurrentThreadStatus := caStop;
end;
end;
caStop: begin
if HandleScope(caStop) then begin
ThreadActionStatus := asSuccess;
CurrentThreadStatus := caStop;
end else begin
ThreadActionStatus := asFailure;
CurrentThreadStatus := caStop;
end;
end;
end;
end;
asSuccess: begin
if CurrentThreadStatus = caStart then begin
NumberOfSamples := ps2000_get_streaming_last_values(ScopeHandle,@GetDataFromOverviewBuffer);
MessagesList.AddNewMessage('Scope has '+IntToStr(NumberOfSamples)+' data ready to be read',msScope,Now);
end;
end;
asFailure: begin
// Let's clean up
end;
end;
except
on E: Exception do begin
MessagesList.AddNewMessage('Scope thread exception with message: '+E.Message,msScope,Now,Error,AllDestinations,1000);
end;
end;
end;
end;

procedure THandleScopeThread.GetDataFromOverviewBuffer(ovBuffer: smallint; overflow: smallint; TriggeredAt: Cardinal; Triggered: smallint; AutoStop: smallint; nValues: Cardinal) stdcall;
var
aValue: smallint;
vArray: TValuesArray;
vArrayPtr: ^TValuesArray;
k: integer;
a,b,c,d: smallint;
begin
try
vArrayPtr := @ovBuffer;
vArray := vArrayPtr^;

if nValues > 0 then begin
MessagesList.AddNewMessage('Scope is about to read '+IntToStr(nValues)+' samples',msScope,Now);
for k := 0 to nValues - 1 do begin
a := vArray[0,k];
b := vArray[1,k];
c := vArray[2,k];
d := vArray[3,k];
end;
end;
except
on E: Exception do begin
MessagesList.AddNewMessage('Exception raised vArrayPtr = '+IntToStr(longword(vArrayPtr)) + ' Length = ' + IntToStr(nValues)+' Exception: '+E.Message,msScope,Now,Error,AllDestinations,1010);
end;
end;
end;
kmajdenic
Newbie
 
Posts: 0
Joined: Sun Jul 18, 2010 8:37 pm

Re: Delphi - INC file incomplete

Postby Robin » Wed Jul 21, 2010 12:17 pm

Hi

After looking in to this further, I found that I was incorrect in my previous post. Sorry.

The value returned by ps2000_get_streaming_last_values is either 0 or 1. 1 indicates that the callback will be called and 0 indicates that it will not, either because one of the inputs is out of range or because there are no samples available.

Robin
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests