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?
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)
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:
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).
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.
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;
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;
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.