NI — DO demo(NI — DO demo)-其他
NI — DO demo(NI — DO demo)
Software controlled digital output
To check it connect digital output(s) to oscilloscope or to card analog input.
program doportlpi;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,nidaqmx,SysUtils,StrUtils
{ you can add units after this };
var
DOTaskHandle:TaskHandle;
data: byte;
written:longint = 0;
{************Error handling procedure *****************************************
Example:
ErrorCheck(DAQmxCreateAIVoltageChan(AITaskHandle,'Dev0/ai0','',DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NIL),AITaskHandle);
*******************************************************************************}
procedure ErrorCheck(AError:longint;ATaskHandle:longint);
var
errBuffer:array[0..2048] of char;
begin
//get error description
if Aerror<>0 then begin
DAQmxGetExtendedErrorInfo(@ErrBuffer[0],2048);
writeln(PChar(@ErrBuffer[0]));
//stop and cleat task
if Assigned(@ATaskHandle) then begin
DAQmxStopTask(ATaskHandle);
DAQmxClearTask(ATaskHandle);
end;
//stop program
Halt;
end;
end;
{*******************MAIN PROGRAM WITH ERROR HANDLING*************************}
begin
//task create
ErrorCheck(DAQmxCreateTask('',@DOTaskHandle),DOTaskHandle);
//digital input port create
ErrorCheck(DAQmxCreateDOChan(DOTaskHandle,'Dev1/port0','',DAQmx_Val_ChanForAllLines),DOTaskHandle);
//task start
//no need to start task
ErrorCheck(DAQmxStartTask(DOTaskHandle),DOTaskHandle);
//for 32-bit digital port use DAQmxReadDigitalU32 function
//set 1 on all lines of digital port
//change data:=0 to set 0 or use DAQmxResetDevice function to
data:=0;
ErrorCheck(DAQmxWriteDigitalU8(DOTaskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,@data,@written,Nil),DOTaskHandle);
//use DAQmxResetDevice function here to set signal on Low state
writeln('number of written samples: ',written);
//stop and clear task
if DOTaskHandle<>0 then begin
DAQmxStopTask(DOTaskHandle);
DAQmxClearTask(DOTaskHandle);
end;
end.
see more to:
ttps://wiki.freepascal.org/NI-DAQmx_and_NI-DAQmx_Base_examples
————————
Software controlled digital output
To check it connect digital output(s) to oscilloscope or to card analog input.
program doportlpi;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,nidaqmx,SysUtils,StrUtils
{ you can add units after this };
var
DOTaskHandle:TaskHandle;
data: byte;
written:longint = 0;
{************Error handling procedure *****************************************
Example:
ErrorCheck(DAQmxCreateAIVoltageChan(AITaskHandle,'Dev0/ai0','',DAQmx_Val_RSE,-10.0,10.0,DAQmx_Val_Volts,NIL),AITaskHandle);
*******************************************************************************}
procedure ErrorCheck(AError:longint;ATaskHandle:longint);
var
errBuffer:array[0..2048] of char;
begin
//get error description
if Aerror<>0 then begin
DAQmxGetExtendedErrorInfo(@ErrBuffer[0],2048);
writeln(PChar(@ErrBuffer[0]));
//stop and cleat task
if Assigned(@ATaskHandle) then begin
DAQmxStopTask(ATaskHandle);
DAQmxClearTask(ATaskHandle);
end;
//stop program
Halt;
end;
end;
{*******************MAIN PROGRAM WITH ERROR HANDLING*************************}
begin
//task create
ErrorCheck(DAQmxCreateTask('',@DOTaskHandle),DOTaskHandle);
//digital input port create
ErrorCheck(DAQmxCreateDOChan(DOTaskHandle,'Dev1/port0','',DAQmx_Val_ChanForAllLines),DOTaskHandle);
//task start
//no need to start task
ErrorCheck(DAQmxStartTask(DOTaskHandle),DOTaskHandle);
//for 32-bit digital port use DAQmxReadDigitalU32 function
//set 1 on all lines of digital port
//change data:=0 to set 0 or use DAQmxResetDevice function to
data:=0;
ErrorCheck(DAQmxWriteDigitalU8(DOTaskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,@data,@written,Nil),DOTaskHandle);
//use DAQmxResetDevice function here to set signal on Low state
writeln('number of written samples: ',written);
//stop and clear task
if DOTaskHandle<>0 then begin
DAQmxStopTask(DOTaskHandle);
DAQmxClearTask(DOTaskHandle);
end;
end.
see more to:
ttps://wiki.freepascal.org/NI-DAQmx_and_NI-DAQmx_Base_examples