Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible array problems with Delphi 5 and DAQ_Start

I am trying to scan channels with a 6034E card using DAQ-Start with Delphi 5/W2000. The program sort of works, in that it does read the data and write it to the buffer, but with 2 less points than programmed, then the program hangs.

The bulk of the program is below.

///////////////////////////////////////

unit tstdaqu;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
_addata = array [1..1000] of smallint;
paddata = ^_addata;

tdaqstart = function(devicenum : smallint;
chan : smallint;
gain : smallint;
var buffer : paddata;
count : word;
tb : smallint;
si : integer): smallint; stdcall;
tdaqrate = function(samprate : double;
units : smallint;
var tb : smallint;
var si : integer): smallint;stdcall;

tdaqchk = function(devicenum : smallint;
var daqstopped : smallint;
var retrieved : word) : smallint; stdcall;

tdaqclear = function(devicenum : smallint;
p1 : smallint;
p2 : smallint): smallint; stdcall;
tdaqyield = function(yield : smallint) : smallint; stdcall;

TForm1 = class(TForm)
Edit1: TEdit;
gobtn: TButton;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure gobtnClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
myhandle : THandle;
exhandle : THandle;

daqstart : Tdaqstart;
daqrate : TDaqrate;
daqchk : Tdaqchk;
daqclear : Tdaqclear;
daqyield : Tdaqyield;
pbuf : paddata;
buf : array [1..1000] of smallint;
tb : smallint;
si : integer;
ds : smallint;
dr : word;

implementation


{$R *.DFM}

procedure TForm1.gobtnClick(Sender: TObject);
var
istatus : smallint;
i : integer;
x : word;
n : integer;
iret : smallint;
begin
myhandle := LoadLibrary('nidaq32.dll');
exhandle := LoadLibrary('nidex32.dll');

edit1.Text := inttostr(myhandle);
@daqrate := GetProcAddress(myhandle,'DAQ_Rate');
@daqstart := GetProcAddress(myhandle,'DAQ_Start');
@daqchk := GetProcAddress(myhandle,'DAQ_Check');
@daqclear := GetProcAddress(myhandle,'DAQ_Clear');
@daqyield := GetProcAddress(exhandle,'NIDAQYield');

for i := 1 to 1000 do
buf[i] := 99; // fill buffer with number
pbuf := @buf; // point to buffer

istatus := daqclear(1,0,0);
istatus := daqrate(10000,0,tb,si);
edit2.Text := inttostr(istatus);
edit3.Text := inttostr(tb);
edit4.text := inttostr(si);

/// start scan

istatus := daqstart(1,0,1,pbuf,150,tb,si);
edit5.text := inttostr(istatus);
{ n := 0;
istatus := 0;
ds := 0;
while (ds <> 1) and (istatus = 0) do
begin
n := n+1;
istatus := daqchk(1,ds,dr);
iret := daqyield(1);
edit6.text := 'dr='+inttostr(dr)+' istatus='+inttostr(istatus)+' n='+inttostr(n);
application.ProcessMessages;
end;
}
{ in this bit the program gets to 2 or 3 less than the
desired number of samples before hanging}

end;

procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
istatus : smallint;
tf : textfile;
begin
assignfile(tf,'out.txt');
rewrite(tf);
for i := 1 to 200 do
begin
writeln(tf,i,' ',buf[i]);
memo1.lines.add('#'+inttostr(i)+' '+inttostr(buf[i]));
end;
closefile(tf);
application.Terminate;
// istatus := daqclear(1,0,0);
end;
{note application.terminate stops the program, but something still goes on in the background}
end.

//////////////////////////

Generated data is given in attached "out.txt"

If anyone has any ideas into why the program does not generate the correct number of data samples and hangs I'd be very grateful. As far as I can see, the arrays must work otherwise the data wouldn't be there, but is there something I'm missing as regards addressing the array/pointer in Delphi when used with a DLL in C.

Andy
0 Kudos
Message 1 of 3
(2,959 Views)
i think
istatus := daqclear(1);
should stand before application.Terminate
otherwise the DMA is not stopped
i use the nidaq.pas unit with the DLL, it looks a little bit easier

If you want, I can send you my units
working with nidaq 7.2 and D7 (6023..6050)
Message 2 of 3
(2,959 Views)
Ulrich

Thanks for the reply. I'm still experimenting with the program. The application.terminate was an attempt to stop the program hanging because just using the daqclear caused it to hang. I'm still confused as to why I'm not getting all the data into the array. It could be something with the function definitions.

I'd really appreciate the units you have. I'm using Nidaq 7.1, but there shouldn't be any difference I'd have thought.

email is andyk@fs1.ae.man.ac.uk

Thanks again

Andy
0 Kudos
Message 3 of 3
(2,959 Views)