« Close

Datasheets and User Guides

App Notes

Software & Driver

 

4.3.9 - Easy Functions

The easy functions are simple alternatives to the very flexible IOType based method normally used by this driver. There are 6 functions available:

eAIN()       //Read 1 analog input.
eDAC()       //Write to 1 analog output.
eDI()        //Read 1 digital input.
eDO()        //Write to 1 digital output.
eTCConfig()  //Configure all timers and counters.
eTCValues()  //Update/reset and read all timers and counters.

In addition to the basic operations, these functions also automatically handle configuration as needed. For example, eDO() sets the specified line to output if previously configured as input.

The first 4 functions should not be used when speed is critical with multi-channel reads. These functions use one low-level function per operation, whereas using the normal Add/Go/Get method with IOTypes, many operations can be combined into a single low-level call. With single channel operations, however, there will be little difference between using an easy function or Add/Go/Get.

The last two functions handle almost all functionality related to timers and counters, and will usually be as efficient as any other method. These easy functions are recommended for most timer/counter applications.

Following is example pseudocode:

//Take a measurement from AIN3 using 0-5 volt range and 12-bit resolution.
//eAIN	(Handle, ChannelP, ChannelN, *Voltage, Range, Resolution,
//	Settling, Binary,  Reserved1, Reserved2)
//
eAIN(lngHandle, 3, 0, &dblVoltage, LJ_rgUNI5V, 12, 0, 0, 0, 0);
printf("AIN3 value = %.3f\n",dblVoltage);

//Set DAC0 to 3.1 volts.
//eDAC	(Handle, Channel, Voltage, Binary, Reserved1, Reserved2)
//
eDAC(lngHandle, 0, 3.1, 0, 0, 0);

//Read state of FIO2.
//eDI	(Handle, Channel, *State)
//
eDI(lngHandle, 2, &lngState);
printf("FIO2 state = %.0f\n",lngState);

//Set FIO3 to output-high.
//eDO	(Handle, Channel, State)
//
eDO(lngHandle, 3, 1);


//Enable and configure 1 output timer and 1 input timer, and enable Counter0.
//Fill the arrays with the desired values, then make the call.
alngEnableTimers = {1,1,0,0,0,0}; //Enable Timer0-Timer1
alngTimerModes = {LJ_tmPWM8,LJ_tmRISINGEDGES32,0,0,0,0}; //Set timer modes
adblTimerValues = {16384,0,0,0,0,0}; //Set PWM8 duty-cycle to 75%.
alngEnableCounters = {1,0}; //Enable Counter0
//
//eTCConfig	(Handle, *aEnableTimers, *aEnableCounters, TCPinOffset,
//		TimerClockBaseIndex, TimerClockDivisor, *aTimerModes,
//		*aTimerValues, Reserved1, Reserved2);
//
eTCConfig(lngHandle, alngEnableTimers, alngEnableCounters, 0, LJ_tc750KHZ, 3, alngTimerModes, adblTimerValues, 0, 0);


//Read and reset the input timer (Timer1), read and reset Counter0, and update
//the value (duty-cycle) of the output timer (Timer0).
//Fill the arrays with the desired values, then make the call.
alngReadTimers = {0,1,0,0,0,0}; //Read Timer1
alngUpdateResetTimers = {1,1,0,0,0,0}; //Update Timer0 and reset Timer1
alngReadCounters = {1,0}; //Read Counter0
alngResetCounters = {1,0}; //Reset Counter0
adblTimerValues = {32768,0,0,0,0,0}; //Change Timer0 duty-cycle to 50%
//
//eTCValues	(Handle, *aReadTimers, *aUpdateResetTimers, *aReadCounters,
//		*aResetCounters, *aTimerValues, *aCounterValues, Reserved1,
//		Reserved2);
//
eTCValues(lngHandle, alngReadTimers, alngUpdateResetTimers, alngReadCounters, alngResetCounters, adblTimerValues, adblCounterValues, 0, 0);
printf("Timer1 value = %.0f\n",adblTimerValues[1]);
printf("Counter0 value = %.0f\n",adblCounterValues[0]);

4 comments

Is there a way to use these easy functions over an ethernet connection? Because when opening the labjack UE9 through a socket connection (as in the provided example), the handle we get is an int, and there's no such thing as the HANDLE parameter asked by the easy function...

Yes, the 1st parameter of the e-functions is Handle, just like all other functions that deal with hardware.  Whether you use USB or Ethernet you call OpenLabJack() to get a Handle, then pass that Handle to any function such as eAIN().  Make sure you have read through Section 4.1 for an overview of the UD driver.

I forgot to mention that I operate on Linux, thus there doesn't seem to be an appropriate UD driver and OpenLabjack function, I am opening the labjack through a socket connection as described in the provided example (code following below), so the handle is only an int...

 

<code>//Opening UE9 over ethernet

      memset(&_hints, 0, sizeof _hints);

      _hints.ai_family = AF_UNSPEC;

      _hints.ai_socktype = SOCK_STREAM;

      std::cout<<("Getting IP Info... ")<<std::endl;

      r = getaddrinfo(_LJ_IP_address.c_str(), "52360", &_hints, &_res);

      if( r != 0 ){

std::cerr<<("Couldn't parse address info. Error: ")<<std::endl;

exit(-1);

      }

      std::cout<<("Done")<<std::endl;

 

      printf("Getting socket FD... ");

      // Open the UE9, through a socket.

      _devHandle = socket(AF_INET, SOCK_STREAM, 0);

      if( _devHandle < 0 ) {

std::cerr<<("Couldn't open socket.")<<std::endl;

exit(-1);

      }

      std::cout<<("Done")<<std::endl;

 

      std::cout<<("Connecting (time out after a minute)... ")<<std::endl;

      fflush(stdout);

      r = connect(_devHandle, _res->ai_addr, _res->ai_addrlen);

      if( r < 0 ){

std::cerr<<("\nCouldn't connect to UE9. The error was")<<std::endl;

        close(_devHandle);

        exit(-1);

      }

      std::cout<<("Done")<<std::endl;

</code>

Take a look at the UE9 C Native TCP Examples which provides a cross-platform socket implementation of the easy functions in ue9.h/c which differ slightly than the calls on this page in that their handles are a file descriptor int and analog based functions have anadditional calibration constants parameter. The ue9Easy.c example demonstrates their usage and the ue9.h file documents the functions. In general, the ue9.h/c code provides some helpful functions.