Hello there!
First off: I know that using DAQmx with Delphi is not officially supported by NI. But I need to get it working anyway!
I'm stuck with the callback calling conventions:
I tried:
function EveryNCallback(TaskHandle : LongWord;everyNsamplesEventType : i32; nSamples : u32;callbackData : Pointer) : i32;cdecl;
begin
..
DAQmxReadBinaryI16(TaskHandle,Device.NumPoints,1,DAQmx_Val_GroupByChannel,PSmallint(Chunk.Data),Chunk.DataSize,@Chunk.DataValid,nil);
..
ShowMessage('DeviceNCallBack'+IntToStr(Device.Number),10,MD_DAQ);
result := 0;
end;
function DoneCallback(TaskHandle : LongWord;status : i32;callbackData : Pointer) : i32;cdecl;
..
function SignalEvent(TaskHandle : LongWord;signalID : i32;callbackData : Pointer) : i32;cdecl;
begin
ShowMessage('SignalEvent!!',10,MD_DAQ);
result := 0;
end;
procedure TDAQ_Device_E_series.Initialize(const OnStartCapture,OnStopCapture : TDAQ_Device_Event);
begin
DAQmxCreateTask('',@TaskHandle);
..
DAQmxCreateAIVoltageChan(TaskHandle,PAnsiChar(ChannelName),'',DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_VoltageUnits2_Volts,nil);
DAQmxSetBufInputBufSize(TaskHandle,2*NumPoints);
DAQmxCfgSampClkTiming(TaskHandle,nil,10,DAQmx_Val_Rising,DAQmx_Val_AcquisitionType_ContSamps,NumPoints);
// For callback testing..
DAQmxRegisterSignalEvent(TaskHandle,DAQmx_Val_Signal2_SampleClock,0,Integer(@SignalEvent),nil);
DAQmxRegisterEveryNSamplesEvent(TaskHandle,DAQmx_Val_Acquired_Into_Buffer,NumPoints,0,Integer(@EveryNCallback),self);
DAQmxRegisterDoneEvent(TaskHandle,0,Integer(@DoneCallback),self);
..
end;
I removed all error handling and internal stuff for clarity..
DAQmxStartTask is called later on.. But never one of my callbacks is executed!
I tried declaring them as stdcall instead of cdecl. No use.
Thx a lot in advance for any clues!!
Johannes Munk
Additional Info:
I'm using the mx8.5 header files provided here:
http://digital.ni.com/public.nsf/websearch/A6715AA42405ACD786256F0A00633B8F?OpenDocument
I replaced "P<not supported>" by "PLongBool" and declared : type PLongBool = ^TLongBool;