Skip to main content
Skip table of contents

4.6 - AISample [U12 Datasheet]

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] * 2^8) + (element[2] * 2^16) + (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 )

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.