• 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

  • 相关阅读:
    lua面向对象(定义与调用)
    luastring(字符串)
    luatable(表)
    lua面向对象(创建与实例化)
    pandas安装方法(常规安装失败解决方法)
    lua循环
    windows常用命令schtasks
    ios UI自动化 appium参数配置
    ios UI自动化环境配置
    jmeter进行websocket 通信
  • 原文地址:https://www.cnblogs.com/zzzsj/p/16266834.html
Copyright © 2020-2023  润新知