• 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

  • 相关阅读:
    小米手机miui8.5连接电脑
    js数组map方法
    wxui入门
    动画函数封装
    系列属性(offset、scroll、client)
    定时器( setInterval和 setTimeout)
    BOM(浏览器对象模型)
    事件(绑定、解绑、冒泡)
    元素(element)创建
    节点(node)操作
  • 原文地址:https://www.cnblogs.com/zzzsj/p/16266834.html
Copyright © 2020-2023  润新知