Difference between revisions of "Contributions:NIDAQLogger"

From BCI2000 Wiki
Jump to: navigation, search
Line 4: Line 4:
The file(s) should be in the following directory:
The file(s) should be in the following directory:

Latest revision as of 12:50, 6 May 2011


National Instruments Data Acquisition Module


The file(s) should be in the following directory: http://www.bci2000.org/svn/trunk/src/contrib/SignalSource/NIDAQ-MX/NIDAQ-Logging/



Justin Renga (justin.renga@gmail.com)

Version History

Source Code Revisions

  • Initial development: --
  • Tested under: --
  • Known to compile under: --
  • Broken since: --


The NIDAQLogger has been tested with the USB-6009 and PCI-6024E National Instruments boards at sampling rates up to and including 4096Hz, with sample block sizes up to and including 1024 samples/block. Both devices were running under DAQmx driver version 8.9.5 .

Known Issues

There are a couple of known issues with the NIDAQLogger that are listed below:

  • Occasional "glitching" may occur : the condition known as "glitching" is when some data gets swapped with slightly older data, producing a result that looks wrong.
  • The NIDAQLogger, when coupled with the NIDAQmx Source Module, does not currently work at sampling rates above 8192Hz.
  • Poor results may occur if the NIDAQLogger is used within 5 minutes of starting the BCI2000 computer up.

Functional Description

Acquires signals using National Instruments Data Acquisition boards, other devices, and the computer. Device(s) must be connected to computer beforehand.

Adding and Compiling

To add and compile the NIDAQLogger module, make sure the latest NIDAQ MX drivers are installed on your computer. When that is done, go into the C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\ folder. Inside are two folders: lib and include. The lib folder will contain the NIDAQmx.lib file (inside of the folder msvc). Copy that into the project's library folder. Inside of the include folder is the NIDAQmx.h file, which contains the function prototypes needed to use the NIDAQLogger module. Move this file into the project's include folder. Make sure the project links the new .lib file, and that the NIDAQLogger.h and NIDAQLogger.cpp files include the NIDAQmx.h file correctly. The NIDAQLogger should now be able to compile normally.


Command Line Parameters

Initializing NIDAQLogger

To begin using the NIDAQLogger module, use the --LogNIDAQin flag, and set it equal to 1. To activate device(s) for specific functions, use the following flags:

  • --LogDigiIn (for digital input)
  • --LogAnaIn (for analog input)

The format for the inputs for the above flags is as follows: [flag]="[device name]-[port specification]" Note that if --LogNIDAQ is used, that at least one of the two above flags MUST be used.

Device Specification

The device name (usually) is to be written as "Dev1" or "Dev2" (without the ""). Afterwards, use a - to indicate the device name is finished. If the device number is unclear, run the program with the --LogNIDAQin flag activated, and look at the Operator Log. The devices (along with their number) will be listed.

Port Specifications

There are two acceptable states that the user can specify for each port:

  • 0 - this indicates the port is INACTIVE.
  • 1 - this indicates the port is ACTIVE

Important: If both the NIDAQLogger and the NIDAQFilter (see Contributions:NIDAQFilter) are being used, and both are using the digital lines on the same device, make sure that any port that is being referenced in a parameter is referenced only once. One port cannot use both digital input and digital output functionality, and will cause BCI2000 to throw an error, saying that the line is RESERVED.


Let's assume that the user wants to use one device for both analog and digital input. The device has 8 Analog Input ports and 12 Digital I/O ports. The user also wants to use the 3rd and 4th analog input ports, and the 4th and 10th digital ports for digital input.

The user needs to use 3 flags to accomplish this:

  • --LogNIDAQin=1 -> This flag activates the NIDAQLogger for use.
  • --LogDigiIn="Dev1-000100000100" -> This flag indicates that the user wants to use digital I/O. "Dev1" is the name of the device connected to the computer that she wants to use. 0001000000100 indicates that the user wants ports 4 and 10 (the 1's) as ACTIVE.
  • --LogAnaIn="Dev1-00011000" -> This flag indicates that she wants to use analog output. "Dev1" is the name of the device connected to the computer that she wants to use. 00011000 indicates that she wants to the use ports 3 and 4 on analog input.

The full command (assuming she uses this with SignalGenerator.exe) that the user would use is the following:

SignalGenerator.exe --LogNIDAQin=1 --LogDigiIn="Dev1-000100000100" --LogAnaIn="Dev1-00011000"

BCI2000 Parameters

There are two possible parameters that the user will be able to use. They are outlined below:

  • #IVRanges - the available voltage ranges for analog input for the given device (where # will be replaced by the device name)
    • This parameter will only be enabled if the --LogAnaIn flag is being used.
  • #InSampleRate - the sampling rate for the NIDAQLogger
    • This parameter will be here if the --LogNIDAQ flag is being used.

The parameters will be located under the Source tab, in the section labeled NILogger.


The states that are available are dependent on the port specifications declared in the command line parameters. The format for the states is the following:


  • The first # refers to the device number.
  • The second # refers to the line number (starting at 0).
  • The [A:D] denotes if the state refers to an analog (A) or a digital (D) channel.

For example, if the command parameters look like this:

SignalGenerator.exe --LogNIDAQin=1 --LogDigiIn="Dev1-000100000100" --LogAnaIn="Dev1-10011000"

the states that will be created are the following:

     NIDev1DINPUT3     NIDev1DINPUT9     NIDev1AINPUT0
             NIDev1AINPUT2     NIDev1AINPUT3

Acquired Data

The data (analog) that is acquired by the device is translated to make sure that all of the data will fit inside of the state's parameters. Due to this fact, the data needs to be translated back in order to return it to units of milliVolts (mV). This can be done by subtracting the data by (2000*upper voltage bound). For example, if the data was logged with the range -10V to 10V, then the data must be subtracted by 20,000.