Python for LJM - Windows, Mac, Linux | LabJack
 
« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Python for LJM - Windows, Mac, Linux

Subsections

LJM Python Wrapper/Examples Windows/Mac/Linux (Software Platform)

Cross-platform Python wrapper and examples for the LJM library.

Release

LJM Python Wrapper/Examples Top (Referencable)

GitHub:

This package is available on GitHub: github.com/labjack/labjack-ljm-python

Prerequisites

Instructions

  • Go to the T4 or T7 Quickstart Tutorial and follow the steps to install LabJack software and confirm basic operation.
  • Open a terminal/console window.
  • Install the LJM Python modules with pip, which is commonly installed with Python, using the following command:
    python -m pip install labjack-ljm
    or:
    pip install labjack-ljm
    Run the command with sudo on Linux and Mac.
  • Download/extract the .zip file attached at the top of this page for examples and LJM Python source code.
  • Alternative to pip for installation, in a terminal/console navigate to the extracted folder and run the following command:
    python setup.py install
    Run the command with sudo on Linux and Mac.

Refer to the download's README.TXT file for requirements, installation, installation troubleshooting, documentation, and license information.

Troubleshooting

If you get the following error:

ImportError: No module named labjack

Make sure you install for the Python version you will be using. For example, on Linux if both Python 2.7 and 3.5 are installed, you can install to Python 3.5 with:

      $ python3.5 -m pip labjack-ljm install

Windows

If running the "python setup.py install" command as described in the above instructions causes the following or similar error:

'python' is not recognized as an internal or external command, operable program or batch file.

That means either Python is not installed on your computer or the Python executable's path was not added to the Windows user or system path. To help resolve this issue, please run the Python Windows installer and in the "Customize Python" window, click the "Add python.exe to Path" option towards the bottom and select "Will be installed on local hard drive".



Then continue the installation as normal. Open a new terminal/console window and then go through our installation instructions again.

 

Alternatively, after Python is installed you can run the Python executable from its path. For example:

C:\Python27\python.exe -m pip labjack-ljm

Note that the above command uses the Python 2.7 path, and you should use the correct path on your computer which may differ.

 

Another option is to manually add the Python executable's path to the Windows path as described in the Python documentation.

LJM Examples Where Is An Example To Do XYZ (Referencable)

Overview

With the LJM library, pretty much everything you might want to do with a device is accomplished by writing and/or reading some registers.  Look at the device's datasheet (T7 or T4) or the Modbus Map to determine what registers you need to write and read, then use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers.  The following examples in the Basic folder are a great place to start:

  • LJM_eWriteName Example
  • LJM_eWriteNames Example
  • LJM_eReadName Example
  • LJM_eReadNames Example
  • Write Read Loop with Config

Where is an example to do XYZ?

You will find lots of examples in this archive, but there is not an example for everything the LabJack can do.  The reason for this stems from the "Overview" section above.  Most operations simply involve writing and reading different registers, so you really just need examples that show you how to write and read any register.  If we had examples for every operation, they would just be copies of the example "Write Read Loop with Config" with different registers. The typical workflow to do almost anything beside stream is:

  1. Look at the T-series Datasheet or the Modbus Map to determine what registers you need to write and read.
  2. Use eWriteName (or eWriteNames) to write the desired registers and eReadName (or eReadNames) to read the desired registers. Or just use "Write Read Loop with Config", which provides the basic structure used by many user applications.

An optional step in between those 2 is to use the Register Matrix in Kipling to test writing and reading your desired registers.

Stream mode and other operations that don't fit in "Write Read Loop with Config" will usually have specific examples, and if something seems to be missing let us know.

LJM Python Wrapper/Examples Bottom (Referencable)

Code Snippet

from labjack import ljm

# Open first found LabJack
handle = ljm.openS("ANY", "ANY", "ANY")

# Call eReadName to read the serial number from the LabJack.
name = "SERIAL_NUMBER"
result = ljm.eReadName(handle, name)

print("\neReadName result: ")
print("    %s = %f" % (name, result))

File list

Python_LJM_2019_04_03.zip contains:

CHANGES.TXT
LICENSE.TXT
README.TXT
setup.cfg
setup.py
Examples\Basic\eAddresses.py
Examples\Basic\eNames.py
Examples\Basic\eReadAddress.py
Examples\Basic\eReadAddresses.py
Examples\Basic\eReadName.py
Examples\Basic\eReadNames.py
Examples\Basic\eWriteAddress.py
Examples\Basic\eWriteAddresses.py
Examples\Basic\eWriteName.py
Examples\Basic\eWriteNames.py
Examples\Basic\write_read_loop_with_config.py
Examples\More\1-Wire\1_wire.py
Examples\More\AIN\dual_ain_loop.py
Examples\More\AIN\single_ain.py
Examples\More\AIN\single_ain_with_config.py
Examples\More\Config\read_config.py
Examples\More\Config\read_device_name_string.py
Examples\More\Config\write_device_name_string.py
Examples\More\Config\write_power_config.py
Examples\More\DIO\single_dio_read.py
Examples\More\DIO\single_dio_write.py
Examples\More\DIO_EF\dio_ef_config_1_pwm_and_1_counter.py
Examples\More\Ethernet\read_ethernet_config.py
Examples\More\Ethernet\read_ethernet_mac.py
Examples\More\Ethernet\write_ethernet_config.py
Examples\More\I2C\i2c_eeprom.py
Examples\More\List_All\list_all.py
Examples\More\SD\__init__.py
Examples\More\SD\change_directory.py
Examples\More\SD\delete_file.py
Examples\More\SD\get_disk_info.py
Examples\More\SD\list_directory.py
Examples\More\SD\print_working_directory.py
Examples\More\SD\read_file.py
Examples\More\SD\sd_util.py
Examples\More\SPI\spi.py
Examples\More\Stream\in_stream_with_non_looping_out_stream.py
Examples\More\Stream\ljm_stream_util.py
Examples\More\Stream\stream_basic.py
Examples\More\Stream\stream_basic_with_stream_out.py
Examples\More\Stream\stream_burst.py
Examples\More\Stream\stream_callback.py
Examples\More\Stream\stream_sequential_ain.py
Examples\More\Stream\stream_triggered.py
Examples\More\Testing\c-r_speed_test.py
Examples\More\Watchdog\read_watchdog_config.py
Examples\More\Watchdog\write_watchdog_config.py
Examples\More\WiFi\read_wifi_config.py
Examples\More\WiFi\read_wifi_mac.py
Examples\More\WiFi\read_wifi_rssi.py
Examples\More\WiFi\write_wifi_config.py
labjack\__init__.py
labjack\ljm\__init__.py
labjack\ljm\constants.py
labjack\ljm\errorcodes.py
labjack\ljm\ljm.py

5 comments

Is this package available for a pip install, I have the enthout canopy python distribution and it seems the only way to install external packages is via pip.

LabJack Support's picture

It looks like you can install the package on this page using pip since it contains a setup.py file for installation.

Try downloading the zip file and running (replace path/to to the directory the file is):

pip install path/to/Python_LJM_2013_12_30.zip

Alternatively, over the network you can try:

pip install http://labjack.com/sites/default/files/2013/12/Python_LJM_2013_12_30.zip

Note that the download's URL and zip file name uses dates, so future releases will have different URL paths and names. Before running either of the above commands, use the current "File attachment" download's URL or zip file name in your "pip install" command.

Can I get a simple Python example to start with LabJack T7 Pro ?

Are there Python code examples for the U3?

You'll want to take a look at the LabJackPython download (it has examples) and the quickstarts:

http://labjack.com/support/labjackpython

The LJM driver/wrapper currently only supports the LabJack T7 and Digit. Older LabJacks such as the U12, UE9, U3 and U6 are supported in LabJackPython.