« Close

Datasheets and User Guides

App Notes

Software & Driver


4.6 - AISample

Reads the voltages from 1,2, or 4 analog inputs. Also controls/reads the 4 IO ports.

Execution time for this function is 20 milliseconds or less (typically 16 milliseconds in Windows).


long AISample (    long *idnum,
                   long demo,
                   long *stateIO,
                   long updateIO,
                   long ledOn,
                   long numChannels,
                   long *channels,
                   long *gains,
                   long disableCal,
                   long *overVoltage,
                   float *voltages )

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.

  • *idnum – Local ID, serial number, or -1 for first found.
  • demo – Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.
  • *stateIO – Output states for IO0-IO3. Has no effect if IO are configured as inputs, so a different function must be used to configure as output.
  • updateIO – If >0, state values will be written. Otherwise, just a read is performed.
  • ledOn – If >0, the LabJack LED is turned on.
  • numChannels – Number of analog input channels to read (1,2, or 4).
  • *channels – Pointer to an array of channel commands with at least numChannels elements. Each channel command is 0-7 for single-ended, or 8-11 for differential.
  • *gains – Pointer to an array of gain commands with at least numChannels elements. Gain commands are 0=1, 1=2, …, 7=20. This amplification is only available for differential channels.
  • disableCal – If >0, voltages returned will be raw readings that are not corrected using calibration constants.
  • *voltages – Pointer to an array where voltage readings are returned. Send a 4-element array of zeros.


  • *idnum – Returns the local ID or –1 if no LabJack is found.
  • *stateIO – Returns input states of IO0-IO3.
  • *overVoltage – If >0, an overvoltage has been detected on one of the selected analog inputs.
  • *voltages – Pointer to an array where numChannels voltage readings are returned.

ActiveX Function Differences:
The “channels” and “gains” arrays are replaced with “channelsPacked” and “gainsPacked”. The OCX has a function “FourPack” which will convert 4 elements to a packed value. The packed value is determined as: element[0] + (element[1] * 28) + (element[2] * 216) + (element[3] * 224).

The “voltages” array is replaced with 4 individual parameters.

Declaration (ActiveX):

long AISampleX (    long FAR* idnum,
                    long demo,
                    long FAR* stateIO,
                    long updateIO,
                    long ledOn,
                    long numChannels,
                    long channelsPacked,
                    long gainsPacked,
                    long disableCal,
                    long FAR* overVoltage,
                    float FAR* voltageA,
                    float FAR* voltageB,
                    float FAR* voltageC,
                    float FAR* voltageD )


I am trying to use the AISample function in LabJackPython.  It looks like if the DLL was not exposing it.  Can you help if I am doing something wrong?

>>> dev = u12.U12()

>>> dev.aiSample(2, [0, 1])

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "u12.py", line 2161, in aiSample

    ecode = staticLib.AISample(ctypes.byref(idNum), demo, ctypes.byref(stateIOin), updateIO, ledOn, numChannels, ctypes.byref(channelsArray), ctypes.byref(gainsArray), disableCal, ctypes.byref(overVoltage), ctypes.byref(voltages))

  File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__

    func = self.__getitem__(name)

  File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__

    func = self._FuncPtr((name_or_ordinal, self))

AttributeError: /usr/local/lib/liblabjackusb.so: undefined symbol: AISample

The U12 method AISample is not available on Linux and Mac OS X. LabJackPython and the U12 class on Linux and Mac OS X only use the Exodriver (liblabjackusb.so) which doesn't provide AISample. Use the U12.rawAISample method instead.

Also, refer to LabJackPython's U12 class description as it explains the "raw" functions for Linux and Mac OS X and the availability of the "e" functions.