.. _usb-io:

USB I/O units (SimpleGazeTracker 0.7.0 or later)
============================================================

SimpleGazeTracker 0.7.0 came to support Measurement Computing's USB I/O units.
Connecting a USB I/O unit to the recording computer, SimpleGazeTracker can record digital/analog inputs simultaneously with gaze data.

Supported units
----------------

Windows version of SimpleGazeTracker uses `Universal Library (UL) <http://www.mccdaq.com/daq-software/universal-library.aspx>`_ to control USB IO units, while Linux version uses `DAQFlex <http://www.mccdaq.com/solutions/DAQFlex-Solutions.aspx>`_.
So, supported units are different between Windows version and Linux version.

=========== ==============================================
Version     Supported units
=========== ==============================================
Windows     USB IO units supported by UL
Linux       USB IO units supported by DAQFlex
=========== ==============================================

USB-IO support of SimpleGazeTracker is tested with `USB-1208FS-Plus <http://www.mccdaq.com/usb-data-acquisition/USB-1208FS-Plus.aspx>`_.
This unit can be used from both UL and DAQFlex.

**Data acuisition speed of UL is better than that of DAQFlex** (as `comparison chart <http://www.mccdaq.com/DAQFlex-UL-comparison.aspx>`_ says).
With a Core i7 2600k machine, data acquisition takes less than 1 millisecond on Windows 7 (i.e. using UL) while takes several milliseconds on Ubuntu 12.04LTS (i.e. using DAQFlex).


.. note::
    UL supports All Measurement Computing's DAQ Devices (see `comparison chart <http://www.mccdaq.com/DAQFlex-UL-comparison.aspx>`_).
    Therefore, Windows version of SimpleGazeTraker may be able to work with Measurement Computing's non-USB (such as PCI, PCIe) devices although they haven't be tested.

Configuring SimpleGazeTracker (Windows/UL)
--------------------------------------------

============== ====================================================================================
Parameter      Description
============== ====================================================================================
USBIO_BOARD    Specify *Board number* of USB I/O units. Board number can be confirmed by *InstaCal*
               utility, which is installed with UL. If you have connected only one units to the PC,
               board number is 0 in usual.
USBIO_AD       Specify channel and range of analog input channels. Following ranges are supported.
               Of course, ranges unsupported by your unit don't work.
               
               - BIP15VOLTS (bipolar 15V)
               - BIP10VOLTS (bipolar 19V)
               - BIP5VOLTS (bipolar 5V)
               - BIP2PT5VOLTS (bipolar 2.5V)
               - BIP1VOLTS (bipolar 1V)
               - UNI10VOLTS (unipolar 10V)
               - UNI5VOLTS (unipolar 5V)
               - UNI2PT5VOLTS (unipolar 2.5V)
               
               Pairs of channel and range must be separated by semicolon. For example, if you want
               to use channel 0 at bipolar 5V, value of USBIO_AD is **0;BIP5VOLTS**. If you want 
               to use channel 0 at bipolar 5V and channel 1 at unipolar 10V, value of USBIO_AD is 
               **0;BIP5VOLTS;1;UNI10VOLTS**.
               
               If you don't use analog input, leave this parameter empty (i.e. **USBIO_AD=**).
USBIO_DI       Specify digital input port. One pf following ports can be given. Valid ports depend
               on your unit.
               
               - FIRSTPORTA
               - FIRSTPORTB
               - FIRSTPORTCL
               - FIRSTPORTC
               - FIRSTPORTCH
               
               If you don't use digital input, leave this parameter empty (i.e. **USBIO_DI=**).
USB_USE_THREAD This parameter must be **0** or **1**.  A saparate thread is used to read 
               analog/digital inputs from USB I/O device if the value is 1.
============== ====================================================================================


Configuring SimpleGazeTracker (Linux/DAQFlex)
----------------------------------------------

============== ====================================================================================
Parameter      Description
============== ====================================================================================
USBIO_BOARD    Specify product ID of USB I/O unit. Following units can be specified by model name 
               instead of product ID. See below to examine product ID.
               
               - USB_2001_TC (0x00F9)
               - USB_7202(0x00F2)
               - USB_7204(0x00F0)
               - USB_1208(0x00E8)
USBIO_AD       Specify channel and range of analog input channels. Supported ranges depend on 
               unit. In case of USB-1208FS-Plus, following ranges are supported.

               - BIP20V (bipolar 20V)
               - BIP10V (bipolar 10V)
               - BIP5V (bipolar 5V)
               - BIP4V (bipolar 4V)
               - BIP2PT5V (bipolar 2.5V)
               - BIP2V (bipolar 2V)
               - BIP1PT25V (bipolar 1.25V)
               - BIP1V (bipolar 1V)
               
               Pairs of channel and range must be separated by semicolon. For example, if you want
               to use channel 0 at bipolar 5V, value of USBIO_AD is **0;BIP5V**. If you want 
               to use channel 0 at bipolar 5V and channel 1 at bipolar 10V, value of USBIO_AD is 
               **0;BIP5V;1;UNI10V**.
               
               If you don't use analog input, leave this parameter empty (i.e. **USBIO_AD=**).
USBIO_DI       Specify digital input port. If your unit has two digital input ports, you chan 
               specify 0 or 1.
               
               If you don't use digital input, leave this parameter empty (i.e. **USBIO_DI=**).
USB_USE_THREAD This parameter must be **0** or **1**.  A saparate thread is used to read 
               analog/digital inputs from USB I/O device if the value is 1.
============== ====================================================================================

How to examine product ID of your USB I/O unit
-----------------------------------------------

To examine product ID of your unit, connect the unit to PC and type 'lsusb' from terminal.
Then find a line which ends with "Measurement Computing Corp." as following.

::
  Bus 002 Device 003: ID 09db:**00e8** Measurement Computing Corp.

In this example, 09db is the vendor ID and 00e8 is the product ID.

How to allow for standard users to access to USB I/O unit
--------------------------------------------------------------

If you want to give standard users privilege to access DAQFlex USB I/O device, add udev rules.
Here is an example of udev rules. 
Save following lines as "60-daqflex.rules" and copy it to udev rules directory (e.g. /etc/udev/rules.d).

::

    # allow access to usb devices by non-root users
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00f0", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00f2", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00f9", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00fd", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00fe", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0110", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0111", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0112", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0113", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0114", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00ea", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00e8", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00e9", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0116", MODE="0666"
    SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0117", MODE="0666"

.. note::
    These rules allows any user to read/write the devices. If you want to give privilege to a user group,
    change MODE="0666" to MODE="0660" and add GROUP="FOO" at the end of the lines (FOO is the group name).