Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 17 Devices > 17.7 LabJack UE9 / U6 / U3 > 17.7.5 Analog and Digital I/O > 17.7.5.1 Low Speed Acquisition < 100hz

17.7.5.1.3 Basic Scripting using eGet

Scroll Prev Top Next More

Channels, however, aren't always the best choice, and sometimes you need script.  The next step up from channels is to use basic scripting and the eGet() function to retrieve a single value, or ePut() to set a single value.  For example, to read channel 1 and then put the result into a channel called MyChannel we would do:

 

private err
private val
private string message
while(1)
   err = eGet(0, LJ_ioGET_AIN, 1, @val, 0)
   if (err)
      ErrorToString(err, @message)

      ? message
   else
      MyChannel.AddValue(val)
   endif
   delay(1)
endwhile

Now truthfully, this next code snippet does the exact same thing, provided MyChannel is setup to read channel 1:

 

while(1)
    read(MyChannel)
    delay(1)
endwhile

The read() function allows you to trigger the reading of a channel from script instead of using the Channel's Timing parameter.  But, this code does not allow for any direct error handling, and of course doesn't demonstrate the eGet function!  eGet is also more useful when you don't know your channel numbers at runtime.  In the first example, we used scalar values in our eGet() function call, but there is no reason why you couldn't use variables that could then be changed from elsewhere:

 

err = eGet(ID, LJ_ioGET_AIN, chan, @val, 0)  

Another thing the first example shows is the AddValue() function of the channel MyChannel.  This function essentially stuffs a value into a channel.  This allows you to utilize the benefits of a channel (history, easy logging, etc), without actually using the channel Timing to trigger the reads.  In this case, we are putting the result of the eGet call into MyChannel.  MyChannel does not have to have the same channel number, I/O type, or even be Device Type "LabJack".

Note: if using the U3, you will need to configure the pins as analog inputs.  With Channels, this is done automatically for you, but when scripting you have to do it yourself.  It only takes one line to enable a channel:

 

ePut(ID, LJ_ioPUT_ANALOG_ENABLE_BIT, 1, 1, 0)