NI-DAQmx and NI-DAQmx Base examples

From Free Pascal wiki
Revision as of 13:46, 13 November 2014 by Mig-31 (talk | contribs)
Jump to navigationJump to search

INTRODUCTION

National Instruments produce a wide range of DAQ cards, which generally used for acquiring a generating signals. [1] These cards usually have a few numbers of analog inputs/outputs, digital inputs/ouputs, counters and frequency generator with hardware/software timing. Exiting of feature (type, number, parameters) on card depends on card type.

NIDAQmxBase.pas and NIDAQmx.pas are provided pascal bindings to National Instruments libraries and enabled control NI DAQ cards from program writing on FreePascal.

What National Instruments Hardware are supported

Supported hardware list by NI-DAQmx and NI-DAQ Driver for different operation system [2]

NI-DAQmxBase library

NI-DAQmxBase library or driver is multiplatform library for Linux, Windows and MacOS X, but doesn't implement all device features. For example, digital input/output ports speed is limited by computer speed ~100kHz, because DMA data tranfer is not supported.

Download library for Linux [3], Windows [4], MacOS X [5]. Read readme.txt file to find the list of supported hardware and hardware features.

NI-DAQmx library

Actual (newest) NI-DAQmx library is available only for Windows today.

Download it there [6]

NI-DAQmx version 8.0.2 is also available for Linux 32-bit. You can use it with enterprise RHEL 5,6 distribution or with it clones CentOS 5,6 and Scientific Linux 5,6 or you can use it with old version Linux distribution with kernel 2.6.x.

Download it there [7]

Read readme.txt file to find the list of supported hardware and hardware features.

PASCAL bindings

Your can download pascal bindings nidaqmxbase.pas and nidaqmx.pas in this forum thread [8]

NI-DAQmx examples

Get device list

You can check device list names using NI MAX program under Windows or nilsdev utility under Linux.

program devicelist;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,nidaqmx,SysUtils
  { you can add units after this };
var
  devicenames:array of Char;
  infostr:string;
  DeviceNamesList:TStringList;
  buffersize:longint;
  product_type:array of char;
  devserialnum,is_simulated:longint;
  is_simulated_str:string;
  i:byte;
begin
  DeviceNamesList:=TStringList.Create;
  try
     {**************************************************************************
                      Get device names present in the system
     **************************************************************************}
     //get buffer size or length of string of device list
     buffersize:=DAQmxGetSystemInfoAttribute(DAQmx_Sys_DevNames,devicenames[0],[0]);
     //set array of Char lenght
     if Buffersize<>0 then begin
       writeln('-------------------------------------------------------------');
       writeln('|Device name | Product Type | # Serial number | Is Simulated?');
       writeln('-------------------------------------------------------------');
       SetLength(devicenames,buffersize);
       //get the device list
       DAQmxGetSystemInfoAttribute(DAQmx_Sys_DevNames,devicenames[0],[buffersize]);
       //convert it to string: names are separated by comma
       SetString(infostr,PChar(@devicenames[0]),buffersize);
       //add names to TStringList
       DeviceNamesList.CommaText:=infostr;
       {************************************************************************
                              Get Product info
        ***********************************************************************}
       for i:=0 to DeviceNamesList.Count-1 do begin
          //get buffer size or length of string of product type
          buffersize:=DAQmxGetDeviceAttribute(@DeviceNamesList.Strings[i][1],DAQmx_Dev_ProductType,Nil);
          //set lenght of array of char
          SetLength(product_type,buffersize);
          //get product type info
          DAQmxGetDeviceAttribute(@DeviceNamesList.Strings[i][1],DAQmx_Dev_ProductType,product_type[0],[buffersize]);
          {***********************************************************************
                            Get Serial Number
          **********************************************************************}
          DAQmxGetDeviceAttribute(@DeviceNamesList.Strings[i][1],DAQmx_Dev_SerialNum,devserialnum,[1]);
          //DeviceInfoGrid.Cells[3,i+1]:=IntToHex(devserialnum,8);
          {***********************************************************************
                             Is simulated?
          ***********************************************************************}
          DAQmxGetDeviceAttribute(@DeviceNamesList.Strings[i][1],DAQmx_Dev_IsSimulated,is_simulated,[1]);
          if is_simulated = 0 then is_simulated_str:='No'
          else is_simulated_str:='Yes';
          //Show info
          writeln('| ',DeviceNamesList.Strings[i],' | ',PChar(@product_type[0]),' | $',IntToHex(devserialnum,8),' |',is_simulated_str);
      end;
  end
  else writeln('any device found');
  finally
     DeviceNamesList.Free;
  end;
end.

Output

-------------------------------------------------------------
|Device name | Product Type | # Serial number | Is Simulated?
-------------------------------------------------------------
| Dev1 | PCI-6250 | $018D0B90 |No