« Close

Datasheets and User Guides

App Notes

Software & Driver


4.1 - EAnalogIn

Easy function. This is a simplified version of AISample. Reads the voltage from 1 analog input. Calling this function turns/leaves the status LED on.

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


long EAnalogIn (    long *idnum,
                    long demo,
                    long channel,
                    long gain,
                    long *overVoltage,
                    float *voltage )

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.
  • channel – Channel command is 0-7 for single-ended, or 8-11 for differential.
  • gain – Gain command is 0=1, 1=2, …, 7=20. This amplification is only available for differential channels.


  • *idnum – Returns the local ID or -1 if no LabJack is found.
  • overVoltage – If >0, an overvoltage has been detected on one of the selected analog inputs.
  • voltage – Returns the voltage reading.

LabJackPython Example

>>> import u12
>>> d = u12.U12()
>>> d.eAnalogIn(channel=0, gain=0)
{'overVoltage': 0, 'idnum': 12, 'voltage': 1.4599609375}



how to make the call less verbose, e.g. removing the output what bytes were transferred?




It looks like the U12 class has debug turned on by default.  I think that is causing your verbose issues.  To turn that off set the debug parameter to false when creating your U12 object.  Ex.


In a later release I'll look into setting that to false by default.

Random readings?

  V=d.eAnalogIn(0) # 5V on AI0 towards GND
    A=d.eAnalogIn(9,gain=7) # 18mV between AI2 and AI3

While the single ended readings are ok, the differential are simply random.

Neither AI2 nor AI3 are connected to AI0 nor GND

 any ideas?




I did a quick test by placing a jumper between AI0 and AI1. Then used LJLogger to read the values. I also used a 1.5V battery to test the 0/1 differential input. Everything seem to work for me.

Try jumpering two AIs to GND and then run a differential conversion on that pair, does that give good data? Also test some other AIs, there is a chance that one or more of your inputs have been damaged.

i want to read the voltage from a potentiometer(variable resistor) that is connected through a labjack from a c# program using the labjack functions, so how could i do so? 

For the hardware side, I recommend you do a search at labjack.com with the term "potentiometer" or "u12 potentiometer".  You will find various related topics on our forum.  Also see Figure 2-4 of the U12 User's Guide, as that is essentially the same thing.

For software, eAnalogIn is a good function to use.  To get started in C# see the DotNet examples.

Apologies for the simple Python question, but is there a simple way to return the voltage without the rest of the string? At the moment the python command returns something like:

{'overVoltage': 0, 'idnum': 12, 'voltage': 1.4599609375}


I'd like to just get at the voltage reading (1.4599609375) and put that into a floating point variable.


Many thanks,


I'm using the U12 on a Raspberry Pi. It's a freshly installed Pi with standard Rasbian OS.


I've gone through the full build and the installation process for the Labjack software (version 10-22-2012) and I'm using the U12 with Python 2.7

Generally it's working fine but I randomly get crashes.


Here's my simple code to loop around forever setting the DACs (with constant values) and reading one of the ADCs:


import u12, time

d = u12.U12()

Vout1Desired = 1.23

Vout2Desired = 0.0

while True:



    d.eAnalogOut(analogOut0=Vout1, analogOut1=Vout2)


    reading = d.eAnalogIn(channel=0, gain=0)


    print (reading)




And here is a sample of it's output:



{'overVoltage': 0, 'idnum': 0, 'voltage': 1.2255859375}

{'overVoltage': 0, 'idnum': 0, 'voltage': 1.23046875}

{'overVoltage': 0, 'idnum': 0, 'voltage': 1.2255859375}

Traceback (most recent call last):

  File "/home/pi/test.py", line 12, in <module>

    reading = d.eAnalogIn(channel=0, gain=0)

  File "/usr/local/lib/python2.7/dist-packages/u12.py", line 1930, in eAnalogIn

    results = self.rawAISample(channel0PGAMUX = channel0PGAMUX)

  File "/usr/local/lib/python2.7/dist-packages/u12.py", line 678, in rawAISample


IndexError: list index out of range


The problem seems to get worse (possibly) if I reduce the sleep time. But even with a sleep of 1.5 Seconds between commands, the thing still crashes at a random point.

Eventually I want to make my code adjust the DAC outputs to get a desired output voltage by using the ADC for feedback, but until I get this loop running more reliably then that is impossible.

Any ideas?


Take a look at this forum topic:


In particular, in post 5 we mention our tests with the U12 on the Raspberry Pi. Basically we found that on a Raspberry Pi the U12 will get the occasional USB communication error (which the "IndexError: list index out of range" is indicating since the response packet is empty), and disconnecting other USB devices (keyboard, mouse, etc.) besides the U12 may help prevent how often the errors occur but still doesn't fix the issue completely. This may stem from buggy HID support on the Raspberry Pi considering that Linux desktops and the U12 have no issues like this, and our other LabJack devices which aren't HID run without issue on the Raspberry Pi.

Unfortunately at this time the only Raspberry Pi solution is to catch exceptions so your application doesn't crash and retry your call, or use a LabJack other than the U12 such as the U3.