aReadCounters array.
1
Array size must be equal to the number of timers available on the device. UE9:6, U6:4, U3:2
2
Array size must be equal to the number of counters available on the device. UE9:2, U6:2, U3:2
4.3 - Example Pseudocode
The following pseudocode examples are simplified for clarity, and in particular no error checking is shown. The language used for
the pseudocode is C.
4.3.1 - Open
The initial step is to open the LabJack and get a handle that the driver uses for further interaction. The DeviceType for the U3 is:
LJ_dtU3
There is only one valid ConnectionType for the U3:
LJ_ctUSB
Following is example pseudocode to open a U3 over USB:
//Open the first found LabJack U3 over USB.
OpenLabJack (LJ_dtU3, LJ_ctUSB, "1", TRUE, &lngHandle);
The reason for the quotes around the address (“1”), is because the address parameter is a string in the OpenLabJack function.
The ampersand (&) in front of lngHandle is a C notation that means we are passing the address of that variable, rather than the
value of that variable. In the definition of the OpenLabJack function, the handle parameter is defined with an asterisk (*) in front,
meaning that the function expects a pointer, i.e. an address.
In general, a function parameter is passed as a pointer (address) rather than a value, when the parameter might need to output
something. The parameter value passed to a function in C cannot be modified in the function, but the parameter can be an
address that points to a value that can be changed. Pointers are also used when passing arrays, as rather than actually passing
the array, an address to the first element in the array is passed.
Talking to multiple devices from a single application is no problem. Make multiple open calls to get a handle to each device and be
sure to set FirstFound=FALSE:
//Open U3s with Local ID #2 and #3.
OpenLabJack (LJ_dtU3, LJ_ctUSB, "2", FALSE, &lngHandleA);
OpenLabJack (LJ_dtU3, LJ_ctUSB, "3", FALSE, &lngHandleB);
… then when making further calls use the handle for the desired device.
4.3.2 - Configuration
One of the most important operations on the U3 is configuring the flexible I/O as digital or analog. The following 4 IOTypes are
used for that:
LJ_ioPUT_ANALOG_ENABLE_BIT
LJ_ioGET_ANALOG_ENABLE_BIT
LJ_ioPUT_ANALOG_ENABLE_PORT //x1 is number of bits.
LJ_ioGET_ANALOG_ENABLE_PORT //x1 is number of bits.
When a request is done with one of the port IOTypes, the Channel parameter is used to specify the starting bit number, and the x1
parameter is used to specify the number of applicable bits. Following are some pseudocode examples:
//Configure FIO3 as an analog input.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, 3, 1, 0);
//Configure FIO3 as digital I/O.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, 3, 0, 0);
//Configure FIO0-FIO2 and EIO0-EIO7 as analog, all others as digital. That
//means a starting channel of 0, a value of b1111111100000111 (=d65287), and
//all 16 bits will be updated.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 65287, 16);
//Configure FIO2-FIO4 as analog, and FIO5-FIO6 as digital, without
//configuring any other bits. That means a starting channel of 2,
//a value of b00111 (=d7), and 5 bits will be updated.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 2, 7, 5);
Because of the pin configuration interaction between digital I/O, analog inputs, and timers/counters, many software applications
will need to initialize the flexible I/O to a known pin configuration. One way to do this is with the following pseudocode:
ePut (lngHandle, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 0, 0);
ePut (lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0);
ePut (lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc48MHZ, 0);
ePut (lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 0, 0);
ePut (lngHandle, LJ_ioPUT_COUNTER_ENABLE, 0, 0, 0);
ePut (lngHandle, LJ_ioPUT_COUNTER_ENABLE, 1, 0, 0);
ePut (lngHandle, LJ_ioPUT_DAC_ENABLE, 1, 0, 0); //Ignored on hardware rev 1.30+.
ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 0, 16);
This disables all timers and counters, sets the timer/counter pin offset to 4, sets the timer clock base to 48 MHz (no divisor), sets
the timer clock divisor to 0, and sets all flexible I/O to digital. A simpler option is using the following IOType created exactly for this
purpose, which does the same thing as the 8 function calls above:
ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
There are two IOTypes used to write or read general U3 configuration parameters:
LJ_ioPUT_CONFIG
LJ_ioGET_CONFIG
The following constants are then used in the channel parameter of the config function call to specify what is being written or read:
LJ_chLOCALID //0-255, Default=1
LJ_chHARDWARE_VERSION
LJ_chSERIAL_NUMBER
LJ_chFIRMWARE_VERSION
LJ_chBOOTLOADER_VERSION
LJ_chPRODUCTID
33