Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

6.9 crashed 6.6 fine

Hi,

I'm using DAQ card 6071e, Delphi 6 to program my application. It was working fine in driver 6.6, but not in 6.9. I wrote a simple program, find out that when I called SCAN_Start, it will call the callback function couple times then crash. I only want the callback function once. 6.6 will only call the callback function once, but 6.9 call the callback function couple time. Code on below:


unit TestDAQ;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, nidaq, nidaqcns, StdCtrls, OleCtrls, CWDAQControlsLib_TLB;

type
TForm1 = class(TForm)
InitialButton: TButton;
procedure InitialButtonClick(Sender: TObject);
private
{ Private declarations }
intDevice1: i16;
intDevice2: i16;
intNSamples: LongInt;
ptrBuffer1: pi16;
ptrBuffer2: pi16;
intChanVect: pi16;
intGainVect: pi16;
outchanvec: pi16;
ptrOutWave: pi16;
intOutWaveLen: u32;
public
{ Public declarations }
procedure CreateChannelVec;
procedure CreateGainVec;
procedure OutputStimForDAQInitialization;
end;

procedure DAQInputFinishedCallback(handle : HWND; msg : UINT; wparm : WPARAM; lparm : LPARAM); stdcall;

var
Form1: TForm1;
CalledTimes: Integer;

implementation

{$R *.dfm}

procedure TForm1.InitialButtonClick(Sender: TObject);
var
status1: i16;
status2: i16;
begin
CalledTimes := 0;

intDevice1 := 1;
intDevice2 := 2;

CreateChannelVec;

AI_Configure(intDevice1, -1, 0, -1, 0, 0);
AI_Configure(intDevice2, -1, 0, -1, 0, 0);

intNSamples := 2000;

ptrBuffer1 := SysGetMem (32 * 2 * intNSamples);
ptrBuffer2 := SysGetMem (32 * 2 * intNSamples);

CreateGainVec;

try
DAQ_Clear(intDevice1);

status1 := Set_DAQ_Device_Info(intDevice1, ND_DATA_XFER_MODE_AI, ND_UP_TO_1_DMA_CHANNEL);
if (status1 <> 0) then
ShowMessage('TDAQInterface.InitAnalogIO: Problem with Set_DAQ_Device_Info1 on device1 - status = ' + IntToStr(status1));

status1 := Config_DAQ_Event_Message(intDevice1, 0, nil, 0,0,0,0,0,0,0,0,0);
if (status1 <> 0) then
ShowMessage('TDAQInterface.InitAnalogIO: Problem with Config_DAQ_Event_Message clear on device1 - status = ' + IntToStr(status1));

status1 := Config_DAQ_Event_Message(intDevice1,1,'AI1',2,0,0,0,0,0,0,0,u32(@DAQInputFinishedCallback));
if (status1 <> 0) then
ShowMessage('TDAQInterface.InitAnalogIO: Problem with Config_DAQ_Event_Message callback on device1 - status = ' + IntToStr(status1));

status1 := Scan_Setup(intDevice1, 32, intChanVect, intGainVect);
if (status1 <> 0) then
ShowMessage('TDAQInterface.InitAnalogIO: Problem with Scan_Setup on device1 - status = ' + IntToStr(status1));

except
on EDAQStatus:Exception do
begin
raise;
// ShowMessage(EDAQStatus.Message);
end;
end;
OutputStimForDAQInitialization;
end;

procedure TForm1.CreateChannelVec;
var
chan: pi16;
i, j: Integer;
begin
intChanVect := AllocMem (2 * 32);

chan := intChanVect;
for i := 0 to 3 do
begin
for j := 0 to 7 do
begin
chan^ := i * 16 + j;
Inc (chan, 1);
end;
end;
end;

procedure TForm1.CreateGainVec;
var
gain: pi16;
i: Integer;
begin
intGainVect := AllocMem (2 * 32);

gain := intGainVect;
for i := 0 to 31 do
begin
gain^ := 10;
Inc (gain, 1)
end
end;

procedure TForm1.OutputStimForDAQInitialization ();
var
status, status1, status2 : i16;
count : u32;
scanTimeBase : i16;
scanInterval : u16;
freq: f64;
begin
// reset the card circuitry
DAQ_Clear(intDevice1);
DAQ_Clear(intDevice2);
try
freq := 20000;
count := 32*intNSamples;
status := DAQ_Rate(freq, 0, @scanTimeBase, @scanInterval);

if (status <> 0) then
ShowMessage('TDAQInterface.OutputStimAndRecordInput: Problem getting the DAQ_Rate - status = ' + IntToStr(status));


status1 := SCAN_Start(intDevice1, ptrBuffer1, count, 1, 1, scanTimeBase, scanInterval);
if (status1 <> 0) then
ShowMessage('TDAQInterface.OutputStimAndRecordInput: Problem with SCAN_Start on device1 - status = ' + IntToStr(status1));

except
on EDAQStatus: Exception do
begin
//ShowMessage(EDAQStatus.Message);
end
end
end;

procedure DAQInputFinishedCallback(handle : HWND; msg : UINT; wparm : WPARAM; lparm : LPARAM); stdcall;
begin
Inc(CalledTimes);
ShowMessage('Call Back called ' + IntToStr(CalledTimes) + ' times.');
end;

end.


I wonder is it the default of DAQ is now set to continuous aquiring?
Thank you,
Donald
0 Kudos
Message 1 of 2
(2,263 Views)
Donald:

Unfortunately we do not support Delphi any more so you are doing the right thing by posting it on the Developer Exchange to see if we can get other Delphi developers to help. Meanwhile I can only suggest that you make sure that the support files for Delphi were properly installed by NI-DAQ 6.9 by going into the control panel and making sure the Delphi components are part of the NI-DAQ installation.

If you can't get it to work this way you can always go back to earlier versions of NI-DAQ (although I don't recommend this often) by uninstalling the current version and installing the older one. You can get older NI-DAQ versions from out web site:

http://www.ni.com/downloads/

Let's wait and see if other developers that are using Delphi have something
to say about this. Right now I can only say that we do support NI-DAQ function calls in Visual C++, Borland C++, Visual Basic and that if you choose LabVIEW then we have created libraries that will allow you to create your data acquisition application. Of course, application requirements might force you to use Delphi, so I understand if you can't use other development environments.

Regards

Alejandro Asenjo
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,263 Views)