LabJackPython
LabJackPython is our cross-platform Python module for communicating with LabJack devices. It works on Windows using the UD Driver and on Linux and Mac OS X with the Exodriver.
Download
The latest stable release of LabJackPython is from August 26, 2011: Download 8-26-2011 release of LabJackPython.
Python 2.5, 2.6, or 2.7 is required to use LabJackPython. Python 3 is not currently supported. On Mac OS X, the built-in Python works, and it is 32- and 64-bit compatible. It also comes with Twisted, which you would need to use LJSocket. Use the built-in Python unless you have a good reason not to. Recent Linux distributions also ship with new enough versions of Python built in.
Install
Go to the OSX terminal
$ cd Desktop
$ unzip LabJackPython-7-20-2010.zip
$ cd LabJackPython-7-20-2010/
$ sudo python setup.py install
$ python
>>> import u3
>>> d = u3.U3()
>>> d.configU3()
Development
You can download the latest edge version, or previous tagged versions, of LabJackPython on GitHub.
Driver requirements
The LabJackPython module works with the Windows UD driver, and the Exodriver on Mac OS X and Linux. Refer to the README file for more information.
Firmware requirements
To use the UE9 over Ethernet, install comm firmware 1.50 or higher. At the moment it’s on the beta page.
Quickstart
This quickstart uses a U3-HV, but the principles and most of the code apply to all LabJack devices.
Opening the device
Here’s how to open a U3:
>>> import u3
>>> d = u3.U3()
The constructor for the U3 class will try to automatically open the first found U3. This is good if you only have one U3 connected.
Basic I/O: DAC0, AIN0, FIO4
Wire a jumper from DAC0 to AIN0 and connect an LED from FIO4 to GND. Wire the anode (longer-lead) of the LED to FIO4 and the cathode to GND. Here’s the wiring on a U3-HV:
Set DAC0 to 1.5 V, and read the voltage on AIN0:
>>> DAC0_REGISTER = 5000
>>> d.writeRegister(DAC0_REGISTER, 1.5) # Set DAC0 to 1.5 V
1.5
>>> AIN0_REGISTER = 0
>>> d.readRegister(AIN0_REGISTER) # Read from AIN0
1.5252180099487305
In this example, we’re using the LabJack’s Modbus interface, which is register-based. The values of DAC0_REGISTER and AIN0_REGISTER are taken from the Modbus map. Find the table at the bottom of the Modbus page titled “LabJack ModBus Map”. What register is DAC1 located at? Check the map, and confirm that it’s at 5002.
Now toggle the LED by setting FIO4 to output high and output low:
>>> FIO4_STATE_REGISTER = 6004
>>> d.writeRegister(FIO4_STATE_REGISTER, 1) # Set FIO4 high
1
>>> d.writeRegister(FIO4_STATE_REGISTER, 0) # Set FIO4 low
0
The value of FIO4_STATE_REGISTER is also taken from the Modbus map. Verify that the LED toggles on and off as FIO4’s state changes from high to low.
Now use FIO4 for digital input. First, we configure it for input, then we read its state:
>>> FIO4_DIR_REGISTER = 6104
>>> d.writeRegister(FIO4_DIR_REGISTER, 0) # Set FIO4 to digital input
0
>>> d.readRegister(FIO4_STATE_REGISTER) # Read the state of FIO4
0
>>> # Disconnect the LED
>>> d.readRegister(FIO4_STATE_REGISTER)
1
>>> # Reconnect the LED
>>> d.readRegister(FIO4_STATE_REGISTER)
0
With the LED connected, reading digital input on FIO4 reads low (0). When the LED is disconnected, the FIO’s internal pull-up resistor causes its state to be high (1).
Going further with Modbus
In this quickstart, we’ve used the LabJack’s Modbus interface to use DAC0, AIN0, and FIO4. For more examples of using Modbus, consult the workingWithModbus.py distributed with LabJackPython. The Modbus map is also essential for involved Modbus work.
Beyond Modbus: Low-level commands
The rest of this document will use the LabJack’s low-level command set. Unlike the Modbus interface, the low-level commands were written specifically to communicate with the LabJack.
Low-level Commands
If you skipped the Quickstart above, ensure that your LabJack device is open:
>>> import u3
>>> d = u3.U3()
Basic I/O: DAC0, AIN0, FIO4 with low-level commands
Using the same wiring as the quickstart, let’s recreate the basic I/O operations using LabJack-specific low-level commands. First, before we perform any other operation we will get your LabJack device’s calibration data. This only needs to be performed once after opening your device. The calibration data will be used by functions that convert binary data to voltage/temperature and vice versa.
>>> d.getCalibrationData()
Setting the DAC is a U3 Feedback command, so we’ll use the U3 class getFeedback() function. For every Feedback command, there is a corresponding class in u3.py. The 8-bit DAC0 feedback command from Section 5.2.5.13 has a class named DAC0_8. Here’s how to use it:
>>> DAC0_VALUE = d.voltageToDACBits(1.5, dacNumber = 0, is16Bits = False)
>>> d.getFeedback(u3.DAC0_8(DAC0_VALUE)) # Set DAC0 to 1.5 V
As the documentation in Section 5.2.5.13 states, the 8-bit DAC0 feedback command takes a value between 0 and 255 (inclusive) and the output of the DAC is between 0 and 4.95 V. The variable DAC0_VALUE converts between the two. Reading from an analog input is also a feedback command. As Section 5.2.5.1 of the U3 User’s Guide states, the feedback command returns a 16-bit unsigned value that we must convert into a voltage. Here’s how to do that:
>>> ain0bits, = d.getFeedback(u3.AIN(0)) # Read from raw bits from AIN0
>>> print ain0bits
37584
>>> ainValue = d.binaryToCalibratedAnalogVoltage(ain0bits, isLowVoltage = False)
>>> print ainValue
1.501376
Similar to setting DAC0, we use the getFeedback() function and the AIN class from the u3 module (u3.AIN). The getFeedback() function always returns a list (more on that later), and so we use a trailing comma after ain0bits:
>>> ain0bits, = d.getFeedback(u3.AIN(0))
to automatically unpack the first value in the list. The U3 class has a function binaryToCalibratedAnalogVoltage() that knows how to apply the proper calibration constants to convert the reading into a voltage. The function applies different constants based on whether we are using a U3-LV (default) or one of the high-voltage inputs on the U3-HV. When using a high-voltage input, we specify isLowVoltage = False.
Because reading an analog input is such a common operation, the U3 class provides a getAIN() function that calls getFeedback() and binaryToCalibratedAnalogVoltage() with the correct parameters:
>>> ainValue = d.getAIN(0) # Read from AIN0 in one function
>>> print ainValue
1.501376
Setting a digital line’s state and direction is also done with feedback commands. The relevant ones are BitStateRead, BitStateWrite, BitDirRead, and BitDirWrite.
# Check which FIOs are analog and which are digital
>>> configDict = d.configIO()
>>> configDict["FIOAnalog"]
63
# Set the first four (0-3) to analog (15 = 1111 binary) and the rest to digital
>>> d.configIO(FIOAnalog = 15)
>>> d.getFeedback(u3.BitDirWrite(4, 1)) # Set FIO4 to digital output
[None]
>>> d.getFeedback(u3.BitStateWrite(4, 1)) # Set FIO4 to output high
[None]
>>> d.getFeedback(u3.BitStateWrite(4, 0)) # Set FIO4 to output low
[None]
Note the call to configIO(), which is not a feedback command, but a low-level command in Section 5.2.3. All the low-level commands in Section 5.2 are implemented as functions of the U3 class.
The getFeedback() function also accepts a list of feedback commands, and it accepts multiple arguments directly. For example, here’s how to set FIO4 for digital output and output high at the same time:
>>> outputDirCmd = u3.BitDirWrite(4, 1)
>>> outputHighCmd = u3.BitStateWrite(4, 1)
>>> cmdList = [outputDirCmd, outputHighCmd]
>>> d.getFeedback(cmdList) # Pass a list of commands
[None, None]
>>> d.getFeedback(outputDirCmd, outputHighCmd) # Or pass the commands as arguments
[None, None]
which is exactly what the setFIOState() convenience function does:
>>> d.setFIOState(4, 1) # Set FIO output high in one function
>>> d.setFIOState(4, 0) # Set FIO output low in one function
When you pass multiple feedback commands to getFeedback(), the function processes them sequentially. Here is an example of checking the direction of FIO4 (it’s set to output from above), set the direction to input, and read the direction again:
# Multiple feedback commands
# Read FIO4's direction
# Set FIO4's direction to input
# Read FIO4's direction again
>>> d.getFeedback(u3.BitDirRead(4), u3.BitDirWrite(4, 0), u3.BitDirRead(4))
[1, None, 0]
Now that FIO4 is set to input, we can read its state:
>>> d.getFeedback(u3.BitStateRead(4)) # Read the state of FIO4
[0]
# Disconnect the LED
>>> d.getFeedback(u3.BitStateRead(4))
[1]
# Reconnect the LED
>>> d.getFeedback(u3.BitStateRead(4))
[0]
To get the actual state (first value of the list), don’t forget to unpack it:
>>> v, = d.getFeedback(u3.BitStateRead(4))
>>> v
0
>>> v = d.getFeedback(u3.BitStateRead(4))[0]
>>> v
0
which is exactly what the getFIOState() convenience function does:
>>> d.getFIOState(4)
0
We’ve now recreated all the Modbus (readRegister() and writeRegister()) operations on DAC0, AIN0, and FIO4 using low-level commands. Many low-level commands are feedback commands, so they are passed into getFeedback(), which is a very flexible function that can perform many operations on your device at once. To go beyond the basic low-level operations (basic analog and digital), explore the other built-in commands and the LabJackPython source as described in the sections below.
Low-level commands as built-in functions
Section 5.2 of the U3 User’s Guide describes the low-level commands. All the low-level commands in the U3 User’s Guide have been defined as functions in the U3 LabJackPython class.
For example, we can get helpful information by calling the configU3() command. Note that in Section 5.2.2 of the U3 User’s Guide is a description of ConfigU3.
Here we are going to call configU3 with no arguments to perform only a read.
>>> print d.configU3()
{
'LocalID': 5,
'SerialNumber': 32003XXXX,
'DAC1Enable': 1,
'EIODirection': 0,
'DeviceName': 'U3-HV',
...
}
The configU3() function sets the power-up defaults of the U3. To change the U3’s behavior for this session only, use configIO(). For example, to set the first five FIO lines to analog for this session, call configIO with the FIOAnalog keyword argument:
>>> d.configIO(FIOAnalog = 0x1F)
{'DAC1Enable': 0, 'FIOAnalog': 31, 'EIOAnalog': 0, 'TimerCounterConfig': 64}
The value 0×1F is a bitmask with the lower 5 bits set to 1, signifying the first five FIOs. To make this setting survive power cycles, call configU3() instead of configIO():
>>> d.configU3(FIOAnalog = 0x1F)
{...
'FIOAnalog': 31,
...
}
>>> d.close()
>>> # Unplug the U3 and plug it back in
>>> d.open()
>>> d.configU3()
{...
'FIOAnalog': 31,
...
}
Examining the source
Some of the best low-level documentation of LabJackPython is in the docstrings of the source code. For example, the u3.py module has many examples for the low-level commands. The feedback commands are implemented as classes at the bottom of the module, and every feedback command has a docstring with an example of how to use it.
All Support Guides
Search
Shopping Cart
Testimonials
-
It's working great. Thanks again for your great response. It's a big difference working with Labjack as opposed to [...other companies...].—Frank, USA



Comments
#1
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ue9
>>> d=ue9.UE9()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/ue9.py", line 68, in __init__
self.open(**kargs)
File "/usr/local/lib/python2.7/dist-packages/ue9.py", line 87, in open
Device.open(self, 9, Ethernet = ethernet, firstFound = firstFound, serial = serial, localId = localId, devNumber = devNumber, ipAddress = ipAddress, handleOnly = handleOnly, LJSocket = LJSocket)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 600, in open
d = openLabJack(devType, ct, firstFound = True, handleOnly = handleOnly, LJSocket = LJSocket)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 1454, in openLabJack
return _makeDeviceFromHandle(handle, deviceType)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 1498, in _makeDeviceFromHandle
raise e
LabJackPython.LabJackException: Could only write 0 of 38 bytes.
Do you know what seems to be the problem? Normally I never get this kind of problem..this thing never occurred before..please help.
#2
Looks like a command is not getting through when opening your device. You can try your "d=ue9.UE9()" call a couple of more times and see if that helps to clear the issue, otherwise power cycling your UE9 usually fixes most problems. Let us know if this does not help.
I would need more information to figure out what caused the problem. If this occurs again, let us know of any other calls you have made previous to this error. If you ran a previous program/Python interactive mode session please provide the calls you made there. Also, provide your UE9's Control and Comm firmware versions.
#3
From the text above:
"First, before we perform any other operation we will get your LabJack device’s calibration data. [getCalibrationData()] only needs to be performed once after opening your device. The calibration data will be used by functions that convert binary data to voltage/temperature and vice versa."
Since calling getCalibrationData() should be done every time you first open a LabJack device before doing readings that convert binary data to temp/voltage values and because it also takes no arguments, why is it not part of the constructor? Is there any reason you would not call this function? I can understand that, if you were only doing digital IO, you would not need it however, having a separate call for this seems to imply that it is important to not call this function in some circumstances. Is this true? i.e. Does calling this function change the behavior of the LabJack device if only doing digital IO? Does it hurt to call this function every time a LabJack device is used? If not, why have a separate call?
#4
Using getCalibrationData is only necessary when using low-level commands and temperature/voltages. Using Modbus (the first set of "Basic I/O" examples) you do not need to read the calibration. It doesn't hurt to call this automatically, but considering it is only used for low-level commands we let the user perform the getCalibrationData call based on if they need it or not.
#5
Hello, I got that error message after a while:
in _checkCommandBytes
raise LabJackException("Got incorrect command bytes.\nExpected: %s\nGot: %s\nFull packet: %s" % (hexWithoutQuotes(commandBytes), hexWithoutQuotes(results[1:(size+1)]), hexWithoutQuotes(results)))
LabJackException: Got incorrect command bytes.
Expected: [0xf8, 0x5, 0x39]
Got: [0xf8, 0x2, 0x0]
Full packet: [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0x0, 0x97, 0xb7, 0x4, 0x23]
Is this my fault?thanks
#6
What LabJack device and operating system are you using? Also, can you provide the chunk of your code that leads to this exception?
#7
The problem which occurred only once might be attributed to the use of an TCP/IP connected U3 via Silex 1000 SX1000U?
#8
Looking at the exception it looks like you are getting your error during a EI-1050, or some other Sensirion SHT1X sensor, reading. Instead of the expected SHT1X low-level response you got a Feedback low-level response. You may be getting a repeat response packet from the previous call (Feedback in this case) which over straight USB I have not encountered. The cause may stem from the Silex 1000 SX1000U layer as you pointed out. Check that your Silex 1000 SX1000U has the latest firmware for stability. If this becomes a common occurrence, test your code with your U3 connected directly to your computer to see if the Silex device is causing the issue.
#9
How to communicate with multiple LabJacks connected on a system?
#10
When opening your device with the class constructor or the open call, you can specify your LabJack with the serial or localId parameter. The serial number is located on the back of your LabJack on the sticker, or can be retrieved by a configU3/configU6/commConfig U3/U6/UE9 class call after opening the device. The local ID is user defined and stored on the LabJack. It can be read and set with the same config call to get the serial number. Here's a quick example opening two different LabJacks by serial number:
d1 = u3.U3(serial=320025017)
d2 = u6.U6(serial=360006724)
#11
This is very useful, thanks a lot.
#12
>>> DAC0_REGISTER=5000
>>> d.writeRegister(DAC0_REGISTER, 1.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 435, in writeRegister
return self._parseWriteRegisterResponse(response, pkt, value)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 491, in _parseWriteRegisterResponse
if request[7] != response[7]:
IndexError: list index out of range
>>>
My device is ue9-pro..CommFWVersion 1.40 and ControlFWVersion is 2.11..why still i cannot set DAC0 to 1.5V?
#13
Modbus over both USB and ethernet support was not available until Comm firmware version 1.48. You are using version 1.40 which did not support Modbus yet, so that is the cause of the problem. Try installing the newest beta Comm firmware, and see if that help.
#14
Thanks for the previous response. I've also noticed the U6 getTemperature() method doesn't work. I have the latest package from github installed. It causes an AttributeError: 'U6' object has no attribute 'caliInfo'
#15
This is fixed now. It was actually a bug in the U6.getCalibrationData function that slipped by me in yesterday's update. "caliInfo" should of been "calInfo". Thanks for informing us.
#16
>>> import u6
>>> d = u6.U6()
>>> DAC0_VALUE = d.voltageToDACBits(1.5, dacNumber = 0, is16Bits = False)
>>> d.getFeedback(u6.DAC0_8(DAC0_VALUE))
Gives the following error: AttributeError: 'U6' object has no attribute 'voltageToDACBits'
So far as I can see, neither does the U3 module (not that it'd be of use since I have a U6 but I looked since the quickstart is written for U3). Is the quickstart written for different modules to those that were actually released or am I missing something obvious (I'm fairly new to Python)?
#17
I updated the U6 class to include the voltageToDACBits function since it is useful and should of been there in the first place. You can download the latest LabJackPython on github. The code you posted will work with it. For documentation look at the u6.py source code or use the help function built in Python (help(u6.U6) for U6 documentation).
As for the voltageToDACBits in the U3 class, it is there. If you find a conflict with the quickstart and current releases let us know and we will take a look at it.
#18
#a simple script to track a couple of analog inputs.
#note that in "u3.U3()" the first u is small and second is capitalized. Easy to miss!
import u3, time
d = u3.U3()
d.configIO(FIOAnalog = 15) #set lines 0-3 to analog input
for i in range(1,100):
input0 = d.getAIN(0)
input1 = d.getAIN(1)
print input0, input1
time.sleep(1)
#19
Thank you for posting your script. Here's a modified version of your script using the getFeedback method instead of getAIN. It's not as simple, but is more efficient speed wise since it performs only one low-level command/response in the loop instead of the two performed by using two getAIN calls.
import u3, time
d = u3.U3()
d.configIO(FIOAnalog = 15) #set lines 0-3 to analog input
feedbackArguments = [u3.AIN(0), u3.AIN(1)]
for i in range(1,100):
ain0Bits, ain1Bits = d.getFeedback(feedbackArguments)
#if using a U3-HV, set isLowVoltage = False
input0 = d.binaryToCalibratedAnalogVoltage(ain0Bits, isLowVoltage = True)
input1 = d.binaryToCalibratedAnalogVoltage(ain1Bits, isLowVoltage = True)
print input0, input1
time.sleep(1)
#20
Thanks, that is more efficient. How would I modify this to work with the U6, which I just ordered? Is it as simple as changing each u3 or U3 to a u6 or U6?
#21
Some of the modifications are just simple u3/U3 to u6/U6 changes, but the configIO call is not needed, you will want to use the U6.AIN24 class instead of U6.AIN and the binaryToCalibratedAnalogVoltage parameters differ. Here's a quick example of performing +-10 V readings on AIN0 and AIN1:
import u6, time
d = u6.U6()
feedbackArguments = [u6.AIN24(PositiveChannel=0, ResolutionIndex=1, GainIndex=0), u6.AIN24(PositiveChannel=1, ResolutionIndex=1, GainIndex=0)]
for i in range(1,100):
ain0Bits, ain1Bits = d.getFeedback(feedbackArguments)
#Can also use d.binaryToCalibratedAnalogVoltage(0, ain0Bits), d.binaryToCalibratedAnalogVoltage(0, ain1Bits)
input0 = d.binaryToCalibratedAnalogVoltage(gainIndex=0, bytesVoltage=ain0Bits, is16Bits=False)
input1 = d.binaryToCalibratedAnalogVoltage(gainIndex=0, bytesVoltage=ain1Bits, is16Bits=False)
print input0, input1
time.sleep(1)
#22
I'm having troubles with LabJackPython on Windows. In contrast, with TinyCore Linux (it's convenient) I have not yet had any issues. So far I've been able to run some of the examples and feel that I'm making progress.
I have a netbook running Windows 7 and a desktop with XP that I can also use. On the netbook I have ActiveState Python 2.6 and generic Python 2.7.2. In following the quickstart, I can manually open, assign, and read from pins. The following work as expected.
>>> import u3
>>> d = u3.U3()
>>> DAC0_REGISTER = 5000
>>> d.writeRegister(DAC0_REGISTER, 1.5) # Set DAC0 to 1.5
>>> AIN0_REGISTER = 0>>> d.readRegister(AIN0_REGISTER) # Read from AIN0
VWith Win7 I can run streamTest.py with Python under the command prompt but under idle the program misses the majority of the samples. I guess idle is slow.
The example outputSinDAC.py works under Linux but under Win7 I get this:
les>python outputSinDAC.py
This program will attempt to generate a sine wave with a frequency of 10 Hz, upd
ating once every 0.005 seconds.
Opening LabJack... Done
Traceback (most recent call last):
File "outputSinDAC.py", line 86, in <module>
signal.signal(signal.SIGALRM, dacs.handleSetDac)
AttributeError: 'module' object has no attribute 'SIGALRM'
Another time I saw a "LabJack already open" error but I used the task manager to kill the lingering process.
In looking at the code for u3allio.py I see that it's expecting the number of channels as an argument, so that for Win7 for two channels I get:
>python u3allio.py 2
Time difference: 0:00:03.305000
Time per iteration: 0:00:00.003305
Time per iteration in millis: 3.305
Latest readings: [1.4177564800000002, 0.280572816]
I hope this feedback helps.
#23
With streamTest.py and IDLE, as you mentioned it looks like IDLE is slow. Run streamTest.py in the Windows command prompt or remove the slow "print "Average of", len(r['AIN0']), "reading(s):", sum(r['AIN0'])/len(r['AIN0'])" print code and run IDLE. That should take care of the missing packets.
As for the "AttributeError: 'module' object has no attribute 'SIGALRM'" exception, the signal module code requires Unix based systems to run. In this case the SIGALRM signal is not available on Windows. Refer to the top of the outputSinDAC.py source code for more details.
#24
Hi. Can you add just a small example about how to use the timers and counters for the U6? There isn't an example I can find in the collection of examples supplied with LabJackPython.
#25
Take a look at the U3 examples in the Feedback low-level section of the U3 User's Guide. In particular, sections 5.2.5.15, 5.2.5.16, and 5.2.5.17 provide timer and counter examples. These are U3 examples, but they should work on a U6 if you replace the U3 import and u3 class calls with U6/u6. Also, for configIO the FIOAnalog parameter does not exist for the U6.
When we do the Python examples update I'll add a U6 timer/counter example, though there currently is no time frame for that.
#26
Examples of LabJackPython for the UE9 would be helpful. The copious examples in C are very nice, but I get weary translating them to python, as my python experience is limited.
#27
Thank you for your input. Currently on our list of things to do is to improve our Python examples, or in the case of the UE9 have some. I do not know when we will work on those, but in the meantime if you have questions feel free to ask. Our forum is a good place for that.
I will point out that most low-level functions have an equivalent function in the UE9 class that handle the raw bytes of low-level functions and communications for you. The UE9 class and methods are documented in the ue9.py source, which can also be viewed with the "help(ue9.UE9)" call in Python.
#28
Since this page may be a bit jumbled or confusing, which we plan to improve, I would like to clarify some things which may be helpful. There are two protocols to interact with our devices. One is Modbus and the other is the low-level functions.
The Modbus protocol is discussed in the "Basic I/O: DAC0, AIN0, FIO4", "Going further with Modbus", and "Beyond Modbus: Low-level commands" sections. The example code here can be used on a UE9, U3 and U6. The "Modbus Map" link provides more in depth details on the protocol and UE9 firmware requirements.
The "Low-level Commands" section discusses the U3 Python class and its methods that use the low-level function protocol. Along with the U6 and UE9 classes, whose methods are not all exactly the same, they provide a Python interface that handle most low-level functions for you. They also provide helpful functions for sending/receiving the raw bytes of the low-level functions and converting the raw byte data to proper units.
#29
Would be nice to have high level commands for EIO and CIO too.
thanks
#30
Through the Feedback functions you are able to get EIO and CIO readings in a flexible, high-level way. I call the Feedback functions high-level since you do not need to set up a low-level packet.
Here are feedback examples for reading EIO0 on the U3, U6 and UE9:
d.getFeedback(u3.BitStateRead(IONumber = 8)) #U3
d.getFeedback(u6.BitStateRead(IONumber = 8)) #U6
d.feedback()["EIOState"] & 0x01 #UE9
In the U3 class, there is a high-level digital function that will read EIO, MIO lines. setFIOState and getFIOState will get/set EIO lines if you specify a fioNum of 8-15 (->EIO0-8), and CIO lines are 16-19 (->CIO0-4). An example for reading EIO0:
d.getFIOState(8) #U3 only
#31
Error when I tried to set DAC0:
>>> DAC0_REGISTER = 5000
>>> d.writeRegister(DAC0_REGISTER, 1.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/LabJackPython.py", line 409, in writeRegister
return self._parseWriteRegisterResponse(response, pkt, value)
File "/usr/local/lib/python2.6/dist-packages/LabJackPython.py", line 465, in _parseWriteRegisterResponse
if request[7] != response[7]:
IndexError: list index out of range
#32
Which device do you have? My first guess is that perhaps you need newer firmware.
#33
I have a U3. Thank you, I believe you are correct. I was able to update the firmware using Windows and the device is now working in Linux.