├── .gitignore ├── CHANGES.TXT ├── Examples ├── Basic │ ├── eAddresses.py │ ├── eNames.py │ ├── eReadAddress.py │ ├── eReadAddresses.py │ ├── eReadName.py │ ├── eReadNames.py │ ├── eWriteAddress.py │ ├── eWriteAddresses.py │ ├── eWriteName.py │ ├── eWriteNames.py │ └── write_read_loop_with_config.py └── More │ ├── 1-Wire │ └── 1_wire.py │ ├── AIN │ ├── dual_ain_loop.py │ ├── simple_log.py │ ├── single_ain.py │ └── single_ain_with_config.py │ ├── Asynch │ └── asynch.py │ ├── Config │ ├── read_LJM_config.py │ ├── read_config.py │ ├── read_device_name_string.py │ ├── write_device_name_string.py │ └── write_power_config.py │ ├── DAC │ └── single_dac.py │ ├── DIO │ ├── single_dio_read.py │ └── single_dio_write.py │ ├── DIO_EF │ ├── dio_ef_config_2_pwm_2_clock.py │ ├── dio_ef_config_counter.py │ ├── dio_ef_config_freq.py │ ├── dio_ef_config_pwm.py │ └── dio_ef_config_pwm_and_counter.py │ ├── Ethernet │ ├── read_ethernet_config.py │ ├── read_ethernet_mac.py │ └── write_ethernet_config.py │ ├── I2C │ ├── i2c_eeprom.py │ └── sht3x.py │ ├── List_All │ └── list_all.py │ ├── Lua │ └── lua_execution_control.py │ ├── SD │ ├── __init__.py │ ├── change_directory.py │ ├── delete_file.py │ ├── get_disk_info.py │ ├── list_directory.py │ ├── print_working_directory.py │ ├── read_file.py │ └── sd_util.py │ ├── SPI │ └── spi.py │ ├── Stream │ ├── aperiodic_stream_out.py │ ├── periodic_stream_out.py │ ├── stream_basic.py │ ├── stream_basic_with_stream_out.py │ ├── stream_burst.py │ ├── stream_callback.py │ ├── stream_external_clock.py │ ├── stream_sequential_ain.py │ └── stream_triggered.py │ ├── Testing │ ├── auto_reconnect_test.py │ └── c-r_speed_test.py │ ├── Utilities │ ├── thermocouple_example_ain_ef.py │ └── thermocouple_example_inamp.py │ ├── Watchdog │ ├── read_watchdog_config.py │ └── write_watchdog_config.py │ └── WiFi │ ├── read_wifi_config.py │ ├── read_wifi_mac.py │ ├── read_wifi_rssi.py │ └── write_wifi_config.py ├── LICENSE.TXT ├── README.TXT ├── labjack ├── __init__.py └── ljm │ ├── __init__.py │ ├── constants.py │ ├── errorcodes.py │ └── ljm.py ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | *~ 4 | .DS_Store 5 | .installed.cfg 6 | bin 7 | develop-eggs 8 | dist 9 | downloads 10 | eggs 11 | parts 12 | src/*.egg-info 13 | lib 14 | lib64 15 | build/ 16 | -------------------------------------------------------------------------------- /CHANGES.TXT: -------------------------------------------------------------------------------- 1 | Version History 2 | --------------- 3 | 1.23.0 (04/24/2025) 4 | - Updated examples. T8 added to all examples. 5 | 6 | 1.23.0 (12/01/2023) 7 | - Updated functions, constants and errorcodes to LJM v1.23. 8 | - Updates to examples (exception note, T8 updates, clean up and fixes). 9 | - Added asynch.py, read_LJM_config.py, simple_log.py, 10 | stream_external_clock.py, thermocouple_example_ain_ef.py, 11 | thermocouple_example_inamp.py examples. 12 | - Added Conda information to the README.TXT. 13 | 14 | 1.21.0 (06/17/2020) 15 | - Added a Lua example folder and lua_execution_control.py 16 | 17 | 1.21.0 (03/27/2020) 18 | - Updated functions, constants and errorcodes to LJM v1.21. 19 | - Added stream-out function support and examples. 20 | 21 | 1.20.1 (02/28/2020) 22 | - Added device reconnect callback functionality and example. 23 | - Updated stream callback functionality. 24 | 25 | 1.20.0 (04/03/2019) 26 | - Updated functions, constants and errorcodes to LJM v1.20. 27 | - Added string support to eWriteAddressByteArray and eWriteNameByteArray. 28 | - Changed distribution name from LJMPython to labjack-ljm for first PyPi 29 | release. No change to namespace and package names. 30 | - Added SD examples. 31 | 32 | 1.19.0 (10/19/2018) 33 | - Updated functions, constants and errorcodes to LJM v1.19. 34 | - Added stream callback functionality. 35 | - Added 1-Wire, stream_triggered, and stream_callback 36 | examples. 37 | 38 | 1.18.0 (02/23/2018) 39 | - Updated functions, constants and errorcodes to LJM v1.18. 40 | - Added write_read_loop_with_config.py example. 41 | - Updated dual_ain_loop.py. 42 | 43 | 1.16.0 (12/04/2017) 44 | - Updated functions, constants and errorcodes to LJM v1.16. 45 | - Changed Python wrapper version to the LJM version. 46 | - Improved ctypes array to list conversion speed in the ljm module. 47 | - Python 2.5 no longer supported. 48 | - Restructured the Examples directory and added more examples. 49 | - Updated examples to support the T4. 50 | 51 | 1.1.0 (12/03/2015) 52 | - Updated functions, constants and errorcodes to LJM v1.9.0. 53 | - Updated links in the README.txt and setup.py file. 54 | - Renamed o_stream_run example to stream_basic_with_stream_out. 55 | 56 | 1.0.0 (08/28/2015) 57 | - Updated dio_ef_config_1_pwm_and_1_counter example. 58 | 59 | 1.0.0 (06/30/2015) 60 | - Updated o_stream_run example. 61 | 62 | 1.0.0 (06/25/2015) 63 | - Updated constants and errorcodes to LJM v1.8.6. 64 | 65 | 0.9.3 (05/21/2015) 66 | - Updated functions, constants and errorcodes to LJM v1.8.0. 67 | - Added and updated some examples. 68 | 69 | 0.9.2 (10/09/2014) 70 | - Fixed loading the LJM dll in Cygwin. 71 | 72 | 0.9.1 (09/23/2014) 73 | - Updated stream examples. 74 | 75 | 0.9.1 (09/04/2014) 76 | - Updated functions and errorcodes to LJM v1.7.2. LJM_SetStreamCallback not 77 | supported. 78 | - Added and updated some examples. 79 | 80 | 0.9.0 (12/30/2013) 81 | - Updated functions and errorcodes to LJM v1.2. 82 | 83 | 0.8.9 (12/19/2013) 84 | - Updated constants to LJM v1.1.3. 85 | - Added I2C and SPI examples. 86 | - Updated Watchdog example to use current registers. 87 | 88 | 0.8.8 (10/17/2013) 89 | - Updated functions, documentation, constants and errorcodes to LJM v1.1.1. 90 | - Force string returns in functions to str. 91 | - Renamed SimpleStream example to stream_basic and updated it. 92 | 93 | 0.8.7 (10/03/2013) 94 | - Updated functions, documentation, constants and errorcodes to LJM v1.0. 95 | - Added SimpleStream example. 96 | 97 | 0.8.6 (08/16/2013) 98 | - Updated functions, documentation, constants and errorcodes to LJM v0.2.45. 99 | * eRead/eWriteString renamed to eRead/eWriteNameString in LJM v0.2.44. 100 | - Updated to support Python 2.5, 2.6, 2.7 and 3.x. 101 | - Moved labjack/ljm/__init__.py classes and functions to labjack/ljm/ljm.py 102 | module. Functionality from the labjack.ljm import remains the same. 103 | 104 | 0.8.5 (07/01/2013) 105 | - Updated functions, constants and errorcodes to LJM v0.2.43. 106 | * labjack.ljm.open was changed and is not compatible with library versions 107 | below 0.2.42. 108 | * labjack.ljm.eStreamStart and eStreamRead were changed and are not 109 | compatible with LJM library versions below 0.2.43. 110 | 111 | 0.8.4 (05/20/2013) 112 | - Updated functions, constants and errorcodes to LJM v0.2.39. 113 | - Improved platform detection when loading LJM library. 114 | 115 | 0.8.3 (04/18/2013) 116 | - Updated functions, constants and errorcodes to LJM v0.2.35. 117 | * New eStreamStart/Read/Stop, addressToType/addressesToTypes functions. 118 | * listAll/listAllS parameter and return changes. 119 | - Removed warning returns. Only a few functions did this. 120 | 121 | 0.8.2 (02/26/2013) 122 | - Updated functions, constants and errorcodes to LJM v0.2.25. 123 | - Changed errorFrame to errorAddress. 124 | 125 | 0.8.1 (02/06/2013) 126 | - Import changes in __init__.py. 127 | 128 | 0.8.0 (01/25/2013) 129 | - Initial release. 130 | -------------------------------------------------------------------------------- /Examples/Basic/eAddresses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eAddresses (LJM_eAddresses) function. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eAddresses: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmeaddresses 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | 20 | Note: 21 | Our Python interfaces throw exceptions when there are any issues with 22 | device communications that need addressed. Many of our examples will 23 | terminate immediately when an exception is thrown. The onus is on the API 24 | user to address the cause of any exceptions thrown, and add exception 25 | handling when appropriate. We create our own exception classes that are 26 | derived from the built-in Python Exception class and can be caught as such. 27 | For more information, see the implementation in our source code and the 28 | Python standard documentation. 29 | """ 30 | from labjack import ljm 31 | 32 | 33 | # Open first found LabJack 34 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 35 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 36 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 37 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 38 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 39 | 40 | info = ljm.getHandleInfo(handle) 41 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 42 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 43 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 44 | 45 | # Local constants to save screen space 46 | WRITE = ljm.constants.WRITE 47 | READ = ljm.constants.READ 48 | FLOAT32 = ljm.constants.FLOAT32 49 | UINT16 = ljm.constants.UINT16 50 | UINT32 = ljm.constants.UINT32 51 | 52 | # Setup and call eAddresses to write/read values to/from the LabJack. 53 | # Write 2.5V to DAC0, 54 | # write 12345 to TEST_UINT16, 55 | # read TEST_UINT16, 56 | # read serial number, 57 | # read product ID, 58 | # and read firmware version. 59 | numFrames = 6 60 | # [DAC0, TEST_UINT16, TEST_UINT16, SERIAL_NUMBER, PRODUCT_ID, FIRMWARE_VERSION] 61 | aAddresses = [1000, 55110, 55110, 60028, 60000, 60004] 62 | aDataTypes = [FLOAT32, UINT16, UINT16, UINT32, FLOAT32, FLOAT32] 63 | aWrites = [WRITE, WRITE, READ, READ, READ, READ] 64 | aNumValues = [1, 1, 1, 1, 1, 1] 65 | aValues = [2.5, 12345, 0, 0, 0, 0] 66 | results = ljm.eAddresses(handle, numFrames, aAddresses, aDataTypes, aWrites, 67 | aNumValues, aValues) 68 | 69 | print("\neAddresses results: ") 70 | start = 0 71 | for i in range(numFrames): 72 | end = start + aNumValues[i] 73 | print(" Address - %5i, data type - %i, write - %i, values: %s" % 74 | (aAddresses[i], aDataTypes[i], aWrites[i], str(results[start:end]))) 75 | start = end 76 | 77 | # Close handle 78 | ljm.close(handle) 79 | -------------------------------------------------------------------------------- /Examples/Basic/eNames.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eNames (LJM_eNames) function. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmenames 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview(Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Local constants to save screen space 48 | WRITE = ljm.constants.WRITE 49 | READ = ljm.constants.READ 50 | FLOAT32 = ljm.constants.FLOAT32 51 | UINT16 = ljm.constants.UINT16 52 | UINT32 = ljm.constants.UINT32 53 | 54 | # Setup and call eNames to write/read values to/from the LabJack. 55 | # Write 2.5V to DAC0, 56 | # write 12345 to TEST_UINT16, 57 | # read TEST_UINT16, 58 | # read serial number, 59 | # read product ID, 60 | # and read firmware version. 61 | numFrames = 6 62 | aNames = ['DAC0', 'TEST_UINT16', 'TEST_UINT16', 'SERIAL_NUMBER', 'PRODUCT_ID', 63 | 'FIRMWARE_VERSION'] 64 | aWrites = [WRITE, WRITE, READ, READ, READ, READ] 65 | aNumValues = [1, 1, 1, 1, 1, 1] 66 | aValues = [2.5, 12345, 0, 0, 0, 0] 67 | results = ljm.eNames(handle, numFrames, aNames, aWrites, aNumValues, aValues) 68 | 69 | print("\neNames results: ") 70 | start = 0 71 | for i in range(numFrames): 72 | end = start + aNumValues[i] 73 | print(" Name - %16s, write - %i, values %s" % 74 | (aNames[i], aWrites[i], results[start:end])) 75 | start = end 76 | 77 | # Close handle 78 | ljm.close(handle) 79 | -------------------------------------------------------------------------------- /Examples/Basic/eReadAddress.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eReadAddress (LJM_eReadAddress) 3 | function. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eReadAddress: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadaddress 16 | 17 | T-Series and I/O: 18 | Modbus Map: 19 | https://labjack.com/support/software/api/modbus/modbus-map 20 | Hardware Overview(Device Information Registers): 21 | https://labjack.com/support/datasheets/t-series/hardware-overview 22 | 23 | Note: 24 | Our Python interfaces throw exceptions when there are any issues with 25 | device communications that need addressed. Many of our examples will 26 | terminate immediately when an exception is thrown. The onus is on the API 27 | user to address the cause of any exceptions thrown, and add exception 28 | handling when appropriate. We create our own exception classes that are 29 | derived from the built-in Python Exception class and can be caught as such. 30 | For more information, see the implementation in our source code and the 31 | Python standard documentation. 32 | """ 33 | from labjack import ljm 34 | 35 | 36 | # Open first found LabJack 37 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 38 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 39 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 40 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 41 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 42 | 43 | info = ljm.getHandleInfo(handle) 44 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 45 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 46 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 47 | 48 | # Setup and call eReadAddress to read a value from the LabJack. 49 | address = 60028 # Serial number 50 | dataType = ljm.constants.UINT32 51 | result = ljm.eReadAddress(handle, address, dataType) 52 | 53 | print("\neReadAddress result: ") 54 | print(" Address - %i, data type - %i, value : %f" % 55 | (address, dataType, result)) 56 | 57 | # Close handle 58 | ljm.close(handle) 59 | -------------------------------------------------------------------------------- /Examples/Basic/eReadAddresses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eReadAddresses (LJM_eReadAddresses) 3 | function. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eReadAddresses: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadaddresses 16 | 17 | T-Series and I/O: 18 | Modbus Map: 19 | https://labjack.com/support/software/api/modbus/modbus-map 20 | Hardware Overview(Device Information Registers): 21 | https://labjack.com/support/datasheets/t-series/hardware-overview 22 | 23 | Note: 24 | Our Python interfaces throw exceptions when there are any issues with 25 | device communications that need addressed. Many of our examples will 26 | terminate immediately when an exception is thrown. The onus is on the API 27 | user to address the cause of any exceptions thrown, and add exception 28 | handling when appropriate. We create our own exception classes that are 29 | derived from the built-in Python Exception class and can be caught as such. 30 | For more information, see the implementation in our source code and the 31 | Python standard documentation. 32 | """ 33 | from labjack import ljm 34 | 35 | 36 | # Open first found LabJack 37 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 38 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 39 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 40 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 41 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 42 | 43 | info = ljm.getHandleInfo(handle) 44 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 45 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 46 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 47 | 48 | # Setup and call eReadAddresses to read values from the LabJack. 49 | numFrames = 3 50 | aAddresses = [60028, 60000, 60004] # [serial number, product ID, firmware version] 51 | aDataTypes = [ljm.constants.UINT32, ljm.constants.FLOAT32, 52 | ljm.constants.FLOAT32] 53 | results = ljm.eReadAddresses(handle, numFrames, aAddresses, aDataTypes) 54 | 55 | print("\neReadAddresses results: ") 56 | for i in range(numFrames): 57 | print(" Address - %i, data type - %i, value : %f" % 58 | (aAddresses[i], aDataTypes[i], results[i])) 59 | 60 | # Close handle 61 | ljm.close(handle) 62 | -------------------------------------------------------------------------------- /Examples/Basic/eReadName.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eReadName (LJM_eReadName) function. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview(Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Setup and call eReadName to read a value from the LabJack. 48 | name = "SERIAL_NUMBER" 49 | result = ljm.eReadName(handle, name) 50 | 51 | print("\neReadName result: ") 52 | print(" Name - %s, value : %f" % (name, result)) 53 | 54 | # Close handle 55 | ljm.close(handle) 56 | -------------------------------------------------------------------------------- /Examples/Basic/eReadNames.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eReadNames (LJM_eReadNames) function. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnames 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview(Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Setup and call eReadNames to read values from the LabJack. 48 | numFrames = 3 49 | names = ["SERIAL_NUMBER", "PRODUCT_ID", "FIRMWARE_VERSION"] 50 | results = ljm.eReadNames(handle, numFrames, names) 51 | 52 | print("\neReadNames results: ") 53 | for i in range(numFrames): 54 | print(" Name - %s, value : %f" % (names[i], results[i])) 55 | 56 | # Close handle 57 | ljm.close(handle) 58 | -------------------------------------------------------------------------------- /Examples/Basic/eWriteAddress.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eWriteAddress (LJM_eWriteAddress) 3 | function. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eWriteAddress: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmewriteaddress 16 | Constants: 17 | https://labjack.com/support/software/api/ljm/constants 18 | 19 | T-Series and I/O: 20 | Modbus Map: 21 | https://labjack.com/support/software/api/modbus/modbus-map 22 | DAC: 23 | https://labjack.com/support/datasheets/t-series/dac 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | from labjack import ljm 36 | 37 | 38 | # Open first found LabJack 39 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 40 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 41 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 42 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 43 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 44 | 45 | info = ljm.getHandleInfo(handle) 46 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 47 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 48 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 49 | 50 | # Setup and call eWriteAddress to write a value to the LabJack. 51 | address = 1000 # DAC0 52 | dataType = ljm.constants.FLOAT32 53 | value = 2.5 # 2.5 V 54 | ljm.eWriteAddress(handle, address, dataType, value) 55 | 56 | print("\neWriteAddress: ") 57 | print(" Address - %i, data type - %i, value : %f" % 58 | (address, dataType, value)) 59 | 60 | # Close handle 61 | ljm.close(handle) 62 | -------------------------------------------------------------------------------- /Examples/Basic/eWriteAddresses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eWriteAddresses (LJM_eWriteAddresses) 3 | function. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eWriteAddresses: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmewriteaddresses 16 | Constants: 17 | https://labjack.com/support/software/api/ljm/constants 18 | 19 | T-Series and I/O: 20 | Modbus Map: 21 | https://labjack.com/support/software/api/modbus/modbus-map 22 | DAC: 23 | https://labjack.com/support/datasheets/t-series/dac 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | from labjack import ljm 36 | 37 | 38 | # Open first found LabJack 39 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 40 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 41 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 42 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 43 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 44 | 45 | info = ljm.getHandleInfo(handle) 46 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 47 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 48 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 49 | 50 | # Setup and call eWriteAddresses to write values to the LabJack. 51 | numFrames = 2 52 | aAddresses = [1000, 55110] # [DAC0, TEST_UINT16] 53 | aDataTypes = [ljm.constants.FLOAT32, ljm.constants.UINT16] 54 | aValues = [2.5, 12345] # [write 2.5 V, write 12345] 55 | ljm.eWriteAddresses(handle, numFrames, aAddresses, aDataTypes, aValues) 56 | 57 | print("\neWriteAddresses: ") 58 | for i in range(numFrames): 59 | print(" Address - %i, data type - %i, value : %f" % 60 | (aAddresses[i], aDataTypes[i], aValues[i])) 61 | 62 | # Close handle 63 | ljm.close(handle) 64 | -------------------------------------------------------------------------------- /Examples/Basic/eWriteName.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eWriteName (LJM_eWriteName) 3 | function. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eWriteName: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 16 | Constants: 17 | https://labjack.com/support/software/api/ljm/constants 18 | 19 | T-Series and I/O: 20 | Modbus Map: 21 | https://labjack.com/support/software/api/modbus/modbus-map 22 | DAC: 23 | https://labjack.com/support/datasheets/t-series/dac 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | from labjack import ljm 36 | 37 | 38 | # Open first found LabJack 39 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 40 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 41 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 42 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 43 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 44 | 45 | info = ljm.getHandleInfo(handle) 46 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 47 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 48 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 49 | 50 | # Setup and call eWriteName to write a value to the LabJack. 51 | name = "DAC0" 52 | value = 2.5 # 2.5 V 53 | ljm.eWriteName(handle, name, value) 54 | 55 | print("\neWriteName: ") 56 | print(" Name - %s, value : %f" % (name, value)) 57 | 58 | # Close handle 59 | ljm.close(handle) 60 | -------------------------------------------------------------------------------- /Examples/Basic/eWriteNames.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the labjack.ljm.eWriteNames (LJM_eWriteNames) function. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 15 | Constants: 16 | https://labjack.com/support/software/api/ljm/constants 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | DAC: 22 | https://labjack.com/support/datasheets/t-series/dac 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | from labjack import ljm 35 | 36 | 37 | # Open first found LabJack 38 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 39 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 42 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 43 | 44 | info = ljm.getHandleInfo(handle) 45 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 46 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 47 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 48 | 49 | # Setup and call eWriteNames to write values to the LabJack. 50 | numFrames = 2 51 | names = ["DAC0", "TEST_UINT16"] 52 | aValues = [2.5, 12345] # [2.5 V, 12345] 53 | ljm.eWriteNames(handle, numFrames, names, aValues) 54 | 55 | print("\neWriteNames: ") 56 | for i in range(numFrames): 57 | print(" Name - %s, value : %f" % (names[i], aValues[i])) 58 | 59 | # Close handle 60 | ljm.close(handle) 61 | -------------------------------------------------------------------------------- /Examples/Basic/write_read_loop_with_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Performs an initial call to eWriteNames to write configuration values, and then 3 | calls eWriteNames and eReadNames repeatedly in a loop. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | Multiple Value Functions (such as eWriteNames and eReadNames): 15 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 16 | Timing Functions (such as StartInterval, WaitForNextInterval and 17 | CleanInterval): 18 | https://labjack.com/support/software/api/ljm/function-reference/timing-functions 19 | 20 | T-Series and I/O: 21 | Modbus Map: 22 | https://labjack.com/support/software/api/modbus/modbus-map 23 | Analog Inputs: 24 | https://labjack.com/support/datasheets/t-series/ain 25 | Digital I/O: 26 | https://labjack.com/support/datasheets/t-series/digital-io 27 | DAC: 28 | https://labjack.com/support/datasheets/t-series/dac 29 | 30 | Note: 31 | Our Python interfaces throw exceptions when there are any issues with 32 | device communications that need addressed. Many of our examples will 33 | terminate immediately when an exception is thrown. The onus is on the API 34 | user to address the cause of any exceptions thrown, and add exception 35 | handling when appropriate. We create our own exception classes that are 36 | derived from the built-in Python Exception class and can be caught as such. 37 | For more information, see the implementation in our source code and the 38 | Python standard documentation. 39 | """ 40 | import sys 41 | from time import sleep 42 | 43 | from labjack import ljm 44 | 45 | 46 | loopMessage = "" 47 | if len(sys.argv) > 1: 48 | # An argument was passed. The first argument specifies how many times to 49 | # loop. 50 | try: 51 | loopAmount = int(sys.argv[1]) 52 | except: 53 | raise Exception("Invalid first argument \"%s\". This specifies how many" 54 | " times to loop and needs to be a number." % 55 | str(sys.argv[1])) 56 | else: 57 | # An argument was not passed. Loop an infinite amount of times. 58 | loopAmount = "infinite" 59 | loopMessage = " Press Ctrl+C to stop." 60 | 61 | # Open first found LabJack 62 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 63 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 64 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 65 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 66 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 67 | 68 | info = ljm.getHandleInfo(handle) 69 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" \ 70 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % \ 71 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 72 | 73 | deviceType = info[0] 74 | 75 | # Setup and call eWriteNames for AIN0 (all devices) and digital I/O (T4 only) 76 | # configuration. 77 | if deviceType == ljm.constants.dtT8: 78 | # LabJack T8 configuration 79 | 80 | # AIN0: 81 | # Range = +/-11.0 V (11) 82 | # AIN all resolution index = Default (0) 83 | # AIN sampling rate, in Hz = Auto (0) 84 | aNames = ["AIN0_RANGE", "AIN_ALL_RESOLUTION_INDEX", "AIN_SAMPLING_RATE_HZ"] 85 | aValues = [11, 0, 0] 86 | elif deviceType == ljm.constants.dtT4: 87 | # LabJack T4 configuration 88 | 89 | # Set FIO5 (DIO5) and FIO6 (DIO6) lines to digital I/O. 90 | # DIO_INHIBIT = 0xF9F, b111110011111. 91 | # Update only DIO5 and DIO6. 92 | # DIO_ANALOG_ENABLE = 0x000, b000000000000. 93 | # Set DIO5 and DIO6 to digital I/O (b0). 94 | aNames = ["DIO_INHIBIT", "DIO_ANALOG_ENABLE"] 95 | aValues = [0xF9F, 0x000] 96 | numFrames = len(aNames) 97 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 98 | 99 | # AIN0: 100 | # The T4 only has single-ended analog inputs. 101 | # The range of AIN0-AIN3 is +/-10 V. 102 | # The range of AIN4-AIN11 is 0-2.5 V. 103 | # Resolution index = Default (0) 104 | # Settling = Auto (0) 105 | aNames = ["AIN0_RESOLUTION_INDEX", "AIN0_SETTLING_US"] 106 | aValues = [0, 0] 107 | else: 108 | # LabJack T7 configuration 109 | 110 | # AINO: 111 | # Range = +/-10.0 V (10) 112 | # Resolution index = Default (0) 113 | # Negative Channel = Single-ended (199) 114 | # Settling = Auto (0) 115 | aNames = ["AIN0_RANGE", "AIN0_RESOLUTION_INDEX", "AIN0_NEGATIVE_CH", 116 | "AIN0_SETTLING_US"] 117 | aValues = [10, 0, 199, 118 | 0] 119 | 120 | numFrames = len(aNames) 121 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 122 | 123 | print("\nSet configuration:") 124 | for i in range(numFrames): 125 | print(" %s : %f" % (aNames[i], aValues[i])) 126 | 127 | if deviceType == ljm.constants.dtT8: 128 | # Delay for updated settings to take effect on the T8. 129 | sleep(0.050) 130 | 131 | print("\nStarting %s read loops.%s\n" % (str(loopAmount), loopMessage)) 132 | i = 0 133 | dacVolt = 0.0 134 | fioState = 0 135 | intervalHandle = 1 136 | ljm.startInterval(intervalHandle, 1000000) 137 | while True: 138 | try: 139 | # Setup and call eWriteNames to write to DAC0, and FIO5 (T4) or 140 | # FIO1 (T7 and T8). 141 | # DAC0 will cycle ~0.0 to ~5.0 volts in 1.0 volt increments. 142 | # FIO5/FIO1 will toggle output high (1) and low (0) states. 143 | if deviceType == ljm.constants.dtT4: 144 | aNames = ["DAC0", "FIO5"] 145 | else: 146 | aNames = ["DAC0", "FIO1"] 147 | dacVolt = i % 6.0 # 0 to 5 148 | fioState = i % 2 # 0 or 1 149 | aValues = [dacVolt, fioState] 150 | numFrames = len(aNames) 151 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 152 | print("\neWriteNames : " + 153 | "".join(["%s = %f, " % (aNames[j], aValues[j]) for j in range(numFrames)])) 154 | 155 | # Setup and call eReadNames to read AIN0, and FIO6 (T4) or 156 | # FIO2 (T7 and T8). 157 | if deviceType == ljm.constants.dtT4: 158 | aNames = ["AIN0", "FIO6"] 159 | else: 160 | aNames = ["AIN0", "FIO2"] 161 | numFrames = len(aNames) 162 | aValues = ljm.eReadNames(handle, numFrames, aNames) 163 | print("eReadNames : " + 164 | "".join(["%s = %f, " % (aNames[j], aValues[j]) for j in range(numFrames)])) 165 | 166 | # Repeat every 1 second 167 | skippedIntervals = ljm.waitForNextInterval(intervalHandle) 168 | if skippedIntervals > 0: 169 | print("\nSkippedIntervals: %s" % skippedIntervals) 170 | 171 | i += 1 172 | if loopAmount != "infinite": 173 | if i >= loopAmount: 174 | break 175 | except KeyboardInterrupt: 176 | break 177 | except Exception: 178 | print(sys.exc_info()[1]) 179 | break 180 | 181 | # Close interval and device handles 182 | ljm.cleanInterval(intervalHandle) 183 | ljm.close(handle) 184 | -------------------------------------------------------------------------------- /Examples/More/1-Wire/1_wire.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates 1-Wire communication with a DS1822 sensor and a LabJack. This 3 | demonstration: 4 | - Searches for and displays the ROM ID and path of the connected 1-Wire 5 | device on EIO0. 6 | - Reads temperature from a DS1822 sensor. 7 | 8 | Relevant Documentation: 9 | 10 | LJM Library: 11 | LJM Library Installer 12 | https://labjack.com/support/software/installers/ljm 13 | LJM Users Guide: 14 | https://labjack.com/support/software/api/ljm 15 | Opening and Closing: 16 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 17 | eWriteName: 18 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 19 | Multiple Value Functions (such as eWriteNames, eReadNames, 20 | eWriteNameByteArray and eReadNameByteArray): 21 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 22 | 23 | T-Series and I/O: 24 | 1-Wire: 25 | https://labjack.com/support/datasheets/t-series/digital-io/1-wire 26 | Modbus Map: 27 | https://labjack.com/support/software/api/modbus/modbus-map 28 | Digital I/O: 29 | https://labjack.com/support/datasheets/t-series/digital-io 30 | 31 | Note: 32 | Our Python interfaces throw exceptions when there are any issues with 33 | device communications that need addressed. Many of our examples will 34 | terminate immediately when an exception is thrown. The onus is on the API 35 | user to address the cause of any exceptions thrown, and add exception 36 | handling when appropriate. We create our own exception classes that are 37 | derived from the built-in Python Exception class and can be caught as such. 38 | For more information, see the implementation in our source code and the 39 | Python standard documentation. 40 | """ 41 | from labjack import ljm 42 | 43 | 44 | # Open first found LabJack 45 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 46 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 47 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 48 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 49 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 50 | 51 | info = ljm.getHandleInfo(handle) 52 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 53 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 54 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 55 | 56 | deviceType = info[0] 57 | 58 | if deviceType == ljm.constants.dtT4: 59 | # Configure EIO0 as digital I/O. 60 | ljm.eWriteName(handle, "DIO_INHIBIT", 0xFFEFF) 61 | ljm.eWriteName(handle, "DIO_ANALOG_ENABLE", 0x00000) 62 | 63 | 64 | # Configure 1-Wire pins and options. 65 | dqPin = 8 # EIO0 66 | dpuPin = 0 # Not used 67 | options = 0 # bit 2 = 0 (DPU disabled), bit 3 = 0 (DPU polarity low, ignored) 68 | aNames = ["ONEWIRE_DQ_DIONUM", 69 | "ONEWIRE_DPU_DIONUM", 70 | "ONEWIRE_OPTIONS"] 71 | aValues = [dqPin, 72 | dpuPin, 73 | options] 74 | ljm.eWriteNames(handle, len(aNames), aNames, aValues) 75 | print("\nUsing the DS1822 sensor with 1-Wire communications.") 76 | print(" DQ pin = %d" % dqPin) 77 | print(" DPU pin = %d" % dpuPin) 78 | print(" Options = %d" % options) 79 | 80 | # Search for the 1-Wire device and get its ROM ID and path. 81 | function = 0xF0 # Search 82 | numTX = 0 83 | numRX = 0 84 | aNames = ["ONEWIRE_FUNCTION", 85 | "ONEWIRE_NUM_BYTES_TX", 86 | "ONEWIRE_NUM_BYTES_RX"] 87 | aValues = [function, 88 | numTX, 89 | numRX] 90 | ljm.eWriteNames(handle, len(aNames), aNames, aValues) 91 | ljm.eWriteName(handle, "ONEWIRE_GO", 1) 92 | aNames = ["ONEWIRE_SEARCH_RESULT_H", 93 | "ONEWIRE_SEARCH_RESULT_L", 94 | "ONEWIRE_ROM_BRANCHS_FOUND_H", 95 | "ONEWIRE_ROM_BRANCHS_FOUND_L"] 96 | aValues = ljm.eReadNames(handle, len(aNames), aNames) 97 | 98 | romH = int(aValues[0]) 99 | romL = int(aValues[1]) 100 | rom = (romH<<32) + romL 101 | pathH = int(aValues[2]) 102 | pathL = int(aValues[3]) 103 | path = (pathH<<32) + pathL 104 | print(" ROM ID = %d" % rom) 105 | print(" Path = %d" % path) 106 | 107 | # Setup the binary temperature read. 108 | print("Setup the binary temperature read.") 109 | function = 0x55 # Match 110 | numTX = 1 111 | dataTX = [0x44] # 0x44 = DS1822 Convert T command 112 | numRX = 0 113 | aNames = ["ONEWIRE_FUNCTION", 114 | "ONEWIRE_NUM_BYTES_TX", 115 | "ONEWIRE_NUM_BYTES_RX", 116 | "ONEWIRE_ROM_MATCH_H", 117 | "ONEWIRE_ROM_MATCH_L", 118 | "ONEWIRE_PATH_H", 119 | "ONEWIRE_PATH_L"] 120 | aValues = [function, 121 | numTX, 122 | numRX, 123 | romH, 124 | romL, 125 | pathH, 126 | pathL] 127 | ljm.eWriteNames(handle, len(aNames), aNames, aValues) 128 | ljm.eWriteNameByteArray(handle, "ONEWIRE_DATA_TX", numTX, dataTX) 129 | ljm.eWriteName(handle, "ONEWIRE_GO", 1) 130 | 131 | # Read the binary temperature. 132 | print("Read the binary temperature.") 133 | function = 0x55 # Match 134 | numTX = 1 135 | dataTX = [0xBE] # 0xBE = DS1822 Read scratchpad command 136 | numRX = 2 137 | aNames = ["ONEWIRE_FUNCTION", 138 | "ONEWIRE_NUM_BYTES_TX", 139 | "ONEWIRE_NUM_BYTES_RX", 140 | "ONEWIRE_ROM_MATCH_H", 141 | "ONEWIRE_ROM_MATCH_L", 142 | "ONEWIRE_PATH_H", 143 | "ONEWIRE_PATH_L"] 144 | aValues = [function, 145 | numTX, 146 | numRX, 147 | romH, 148 | romL, 149 | pathH, 150 | pathL] 151 | ljm.eWriteNames(handle, len(aNames), aNames, aValues) 152 | ljm.eWriteNameByteArray(handle, "ONEWIRE_DATA_TX", numTX, dataTX) 153 | ljm.eWriteName(handle, "ONEWIRE_GO", 1) 154 | dataRX = ljm.eReadNameByteArray(handle, "ONEWIRE_DATA_RX", numRX) 155 | temperature = (int(dataRX[0]) + (int(dataRX[1])<<8)) 156 | if temperature == 0x0550: 157 | print("The DS1822 power on reset value is 85 C.") 158 | print("Read again get the real temperature.") 159 | else: 160 | temperature = temperature * 0.0625 161 | print("Temperature = %f C" % temperature); 162 | 163 | ljm.close(handle) 164 | -------------------------------------------------------------------------------- /Examples/More/AIN/dual_ain_loop.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates reading 2 analog inputs (AINs) in a loop from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | Multiple Value Functions (such as eWriteNames and eReadNames): 14 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 15 | Timing Functions (such as StartInterval, WaitForNextInterval and 16 | CleanInterval): 17 | https://labjack.com/support/software/api/ljm/function-reference/timing-functions 18 | 19 | T-Series and I/O: 20 | Modbus Map: 21 | https://labjack.com/support/software/api/modbus/modbus-map 22 | Analog Inputs: 23 | https://labjack.com/support/datasheets/t-series/ain 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | import sys 36 | import time 37 | 38 | from labjack import ljm 39 | 40 | 41 | loopMessage = "" 42 | if len(sys.argv) > 1: 43 | # An argument was passed. The first argument specifies how many times to 44 | # loop. 45 | try: 46 | loopAmount = int(sys.argv[1]) 47 | except: 48 | raise Exception("Invalid first argument \"%s\". This specifies how many" 49 | " times to loop and needs to be a number." % 50 | str(sys.argv[1])) 51 | else: 52 | # An argument was not passed. Loop an infinite amount of times. 53 | loopAmount = "infinite" 54 | loopMessage = " Press Ctrl+C to stop." 55 | 56 | # Open first found LabJack 57 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 58 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 59 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 60 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 61 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 62 | 63 | info = ljm.getHandleInfo(handle) 64 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 65 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 66 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 67 | 68 | deviceType = info[0] 69 | 70 | # Setup and call eWriteNames to configure AIN0 and AIN1 on the LabJack. 71 | if deviceType == ljm.constants.dtT8: 72 | # LabJack T8 configuration 73 | 74 | # AIN0 and AIN1: 75 | # Range = +/-11 V (11) 76 | # AIN all resolution index = Default (0) 77 | # AIN sampling rate, in Hz = Auto (0) 78 | aNames = ["AIN0_RANGE", "AIN1_RANGE", 79 | "AIN_ALL_RESOLUTION_INDEX", "AIN_SAMPLING_RATE_HZ"] 80 | aValues = [11, 11, 81 | 0, 0] 82 | elif deviceType == ljm.constants.dtT4: 83 | # LabJack T4 configuration 84 | 85 | # AIN0 and AIN1: 86 | # Resolution index = Default (0) 87 | # Settling, in microseconds = Auto (0) 88 | aNames = ["AIN0_RESOLUTION_INDEX", "AIN0_SETTLING_US", 89 | "AIN1_RESOLUTION_INDEX", "AIN1_SETTLING_US"] 90 | aValues = [0, 0, 91 | 0, 0] 92 | else: 93 | # LabJack T7 configuration 94 | 95 | # AIN0 and AIN1: 96 | # Range = +/-10.0 V (10) 97 | # Resolution index = Default (0) 98 | # Negative Channel = Single-ended (199) 99 | # Settling, in microseconds = Auto (0) 100 | aNames = ["AIN0_RANGE", "AIN0_RESOLUTION_INDEX", 101 | "AIN0_NEGATIVE_CH", "AIN0_SETTLING_US", 102 | "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", 103 | "AIN1_NEGATIVE_CH", "AIN1_SETTLING_US"] 104 | aValues = [10, 0, 105 | 199, 0, 106 | 10, 0, 107 | 199, 0] 108 | 109 | numFrames = len(aNames) 110 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 111 | 112 | print("\nSet configuration:") 113 | for i in range(numFrames): 114 | print(" %s : %f" % (aNames[i], aValues[i])) 115 | 116 | if deviceType == ljm.constants.dtT8: 117 | # Delay for updated settings to take effect on the T8. 118 | time.sleep(0.050) 119 | 120 | # Read AIN0 and AIN1 from the LabJack with eReadNames in a loop. 121 | numFrames = 2 122 | aNames = ["AIN0", "AIN1"] 123 | 124 | print("\nStarting %s read loops.%s\n" % (str(loopAmount), loopMessage)) 125 | intervalHandle = 1 126 | ljm.startInterval(intervalHandle, 1000000) # Delay between readings (in microseconds) 127 | i = 0 128 | while True: 129 | try: 130 | results = ljm.eReadNames(handle, numFrames, aNames) 131 | print("AIN0 : %f V, AIN1 : %f V" % (results[0], results[1])) 132 | ljm.waitForNextInterval(intervalHandle) 133 | if loopAmount != "infinite": 134 | i = i + 1 135 | if i >= loopAmount: 136 | break 137 | except KeyboardInterrupt: 138 | break 139 | except Exception: 140 | print(sys.exc_info()[1]) 141 | break 142 | 143 | # Close handles 144 | ljm.cleanInterval(intervalHandle) 145 | ljm.close(handle) 146 | -------------------------------------------------------------------------------- /Examples/More/AIN/simple_log.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates reading a single analog input (AIN0) from a LabJack at a rate of 3 | 10 samples per second and logging that data to a .csv file. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eReadName: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 16 | 17 | T-Series and I/O: 18 | Modbus Map: 19 | https://labjack.com/support/software/api/modbus/modbus-map 20 | Analog Inputs: 21 | https://labjack.com/support/datasheets/t-series/ain 22 | 23 | Python: 24 | datetime: 25 | https://docs.python.org/3/library/datetime.html 26 | StackOverflow Example: 27 | https://stackoverflow.com/questions/3316882/how-do-i-get-a-string-format-of-the-current-date-time-in-python 28 | os (how to get the CWD and how to join paths): 29 | https://docs.python.org/3/library/os.html 30 | https://docs.python.org/3/library/os.path.html#module-os.path 31 | """ 32 | import datetime 33 | import os 34 | import sys 35 | import time 36 | 37 | from labjack import ljm 38 | 39 | 40 | # Open the first found LabJack 41 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 42 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 43 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 44 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 45 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 46 | 47 | info = ljm.getHandleInfo(handle) 48 | print("\nOpened a LabJack with Device type: %i, Connection type: %i,\n" 49 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 50 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 51 | 52 | # Setup and call eReadName to read from AIN0 on the LabJack. 53 | name = "AIN0" 54 | numIterations = 10 55 | rate = 100 # in ms 56 | rateUS = rate*1000 57 | timestampFormat = "%Y-%m-%d %I:%M:%S.%f" # year-month-day hour:minute:second.microsecond 58 | 59 | # Get the current time to build a time-stamp. 60 | appStartTime = datetime.datetime.now() 61 | #startTimeStr = appStartTime.isoformat(timespec='milliseconds') 62 | startTimeStr = appStartTime.strftime(timestampFormat) 63 | 64 | # Reformat the start timestamp so that it can be used in a file name. 65 | fileDateTime = appStartTime.strftime("%Y-%m-%d_%I-%M-%S") 66 | 67 | # Get the current working directory 68 | cwd = os.getcwd() 69 | 70 | # Build a file-name and the file path. 71 | fileName = "%s-%s-Example.csv" % (fileDateTime, name) 72 | filePath = os.path.join(cwd, fileName) 73 | 74 | # Open the file and write a header line. 75 | f = open(filePath, 'w') 76 | f.write("Timestamp, Duration/Jitter (ms), %s\n" % (name)) 77 | 78 | # Print some program initialization information. 79 | print("\nThe time is: %s" % (startTimeStr)) 80 | print("Reading %s %i times and saving data to the file:\n - %s\n" % (name, numIterations, filePath)) 81 | 82 | # Prepare final variables for program execution. 83 | intervalHandle = 0 84 | ljm.startInterval(intervalHandle, rateUS) 85 | numSkippedIntervals = 0 86 | 87 | lastTick = ljm.getHostTick() 88 | duration = 0 89 | 90 | for i in range(numIterations): 91 | try: 92 | numSkippedIntervals = ljm.waitForNextInterval(intervalHandle) 93 | 94 | # Calculate the time since the last interval. 95 | curTick = ljm.getHostTick() 96 | duration = (curTick-lastTick)/1000 97 | 98 | # Get and format a timestamp. 99 | curTime = datetime.datetime.now() 100 | curTimeStr = curTime.strftime(timestampFormat) 101 | 102 | # Read AIN0. 103 | result = ljm.eReadName(handle, name) 104 | 105 | # Print the results. 106 | print("%s reading: %0.6f V, duration: %0.1f ms, skipped intervals: %i" % (name, result, duration, numSkippedIntervals)) 107 | 108 | # Write the results to file. 109 | f.write("%s, %0.1f, %0.6f\n" % (curTimeStr, duration, result)) 110 | 111 | lastTick = curTick 112 | except Exception: 113 | print(sys.exc_info()[1]) 114 | break 115 | 116 | print("\nFinished!") 117 | 118 | # Get the final time. 119 | appEndTime = datetime.datetime.now() 120 | #endTimeStr = appEndTime.isoformat(timespec='milliseconds') 121 | endTimeStr = appStartTime.strftime(timestampFormat) 122 | print("The final time is: %s" % (endTimeStr)) 123 | 124 | # Close the file. 125 | f.close() 126 | 127 | # Close the interval and device handles. 128 | ljm.cleanInterval(intervalHandle) 129 | ljm.close(handle) 130 | -------------------------------------------------------------------------------- /Examples/More/AIN/single_ain.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates reading a single analog input (AIN) from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Analog Inputs: 20 | https://labjack.com/support/datasheets/t-series/ain 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Setup and call eReadName to read from AIN0 on the LabJack. 48 | name = "AIN0" 49 | result = ljm.eReadName(handle, name) 50 | 51 | print("\n%s reading : %f V" % (name, result)) 52 | 53 | # Close handle 54 | ljm.close(handle) 55 | -------------------------------------------------------------------------------- /Examples/More/AIN/single_ain_with_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates configuring and reading a single analog input (AIN) with a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 15 | Multiple Value Functions (such as eWriteNames): 16 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | Analog Inputs: 22 | https://labjack.com/support/datasheets/t-series/ain 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | from time import sleep 35 | 36 | from labjack import ljm 37 | 38 | 39 | # Open first found LabJack 40 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 41 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 42 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 43 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 44 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 45 | 46 | info = ljm.getHandleInfo(handle) 47 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 48 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 49 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 50 | 51 | deviceType = info[0] 52 | 53 | # Setup and call eWriteNames to configure AIN0 on the LabJack. 54 | if deviceType == ljm.constants.dtT8: 55 | # LabJack T8 configuration 56 | 57 | # AIN0: 58 | # Range = +/-11.0 V (11) 59 | # AIN all resolution index = Default (0) 60 | # AIN sampling rate, in Hz = Auto (0) 61 | aNames = ["AIN0_RANGE", "AIN_ALL_RESOLUTION_INDEX", "AIN_SAMPLING_RATE_HZ"] 62 | aValues = [11, 0, 0] 63 | elif deviceType == ljm.constants.dtT4: 64 | # LabJack T4 configuration 65 | 66 | # AIN0: 67 | # Resolution index = Default (0) 68 | # Settling, in microseconds = Auto (0) 69 | aNames = ["AIN0_RESOLUTION_INDEX", "AIN0_SETTLING_US"] 70 | aValues = [0, 0] 71 | else: 72 | # LabJack T7 configuration 73 | 74 | # AIN0: 75 | # Range = +/-10.0 V (10) 76 | # Resolution index = Default (0) 77 | # Negative Channel = Single-ended (199) 78 | # Settling, in microseconds = Auto (0) 79 | aNames = ["AIN0_RANGE", "AIN0_RESOLUTION_INDEX", "AIN0_NEGATIVE_CH", 80 | "AIN0_SETTLING_US"] 81 | aValues = [10, 0, 199, 82 | 0] 83 | 84 | numFrames = len(aNames) 85 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 86 | 87 | print("\nSet configuration:") 88 | for i in range(numFrames): 89 | print(" %s : %f" % (aNames[i], aValues[i])) 90 | 91 | if deviceType == ljm.constants.dtT8: 92 | # Delay for updated settings to take effect on the T8. 93 | sleep(0.050) 94 | 95 | # Setup and call eReadName to read AIN0 from the LabJack. 96 | name = "AIN0" 97 | result = ljm.eReadName(handle, name) 98 | 99 | print("\n%s reading : %f V" % (name, result)) 100 | 101 | # Close handle 102 | ljm.close(handle) 103 | -------------------------------------------------------------------------------- /Examples/More/Asynch/asynch.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple asynch example using the first found device and 9600/8/N/1. 3 | Does a write, waits 1 second, then returns whatever was read in that 4 | time. If you short RX to TX, then you will read back the same bytes that you 5 | write. 6 | 7 | Relevant Documentation: 8 | 9 | LJM Library: 10 | LJM Library Installer: 11 | https://labjack.com/support/software/installers/ljm 12 | LJM Users Guide: 13 | https://labjack.com/support/software/api/ljm 14 | Opening and Closing: 15 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 16 | eWriteName: 17 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 18 | Multiple Value Functions (such as eWriteNameArray and eReadNameArray): 19 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 20 | 21 | T-Series and I/O: 22 | Modbus Map: 23 | https://labjack.com/support/software/api/modbus/modbus-map 24 | Digital I/O: 25 | https://labjack.com/support/datasheets/t-series/digital-io 26 | Asynchronous Serial: 27 | https://labjack.com/support/datasheets/t-series/digital-io/asynchronous-serial 28 | 29 | """ 30 | from time import sleep 31 | 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | deviceType = info[0] 48 | 49 | # Configure the asynch feature 50 | ljm.eWriteName(handle, "ASYNCH_ENABLE", 0) 51 | if deviceType == ljm.constants.dtT4: 52 | # Configure FIO4, FIO5, and FIO6 as digital I/O. 53 | ljm.eWriteName(handle, "DIO_INHIBIT", 0xFFF8F) 54 | ljm.eWriteName(handle, "DIO_ANALOG_ENABLE", 0x00000) 55 | 56 | # For the T4, using FIO4 and FIO5 for RX and TX pins. FIO0 to FIO3 are 57 | # reserved for analog inputs, and digital lines are required. 58 | ljm.eWriteName(handle, "ASYNCH_RX_DIONUM", 4) # RX pin number = 4 (FIO4) 59 | ljm.eWriteName(handle, "ASYNCH_TX_DIONUM", 5) # TX pin number = 5 (FIO5) 60 | else: 61 | # For the T7 and T8, use FIO0 and FIO1 for the RX and TX pins. 62 | ljm.eWriteName(handle, "ASYNCH_RX_DIONUM", 0) # RX pin number = 0 (FIO0) 63 | ljm.eWriteName(handle, "ASYNCH_TX_DIONUM", 1) # TX pin number = 1 (FIO1) 64 | 65 | ljm.eWriteName(handle, "ASYNCH_BAUD", 9600) 66 | ljm.eWriteName(handle, "ASYNCH_NUM_DATA_BITS", 8) 67 | ljm.eWriteName(handle, "ASYNCH_PARITY", 0) 68 | ljm.eWriteName(handle, "ASYNCH_NUM_STOP_BITS", 1) 69 | ljm.eWriteName(handle, "ASYNCH_ENABLE", 1) 70 | 71 | writeValues = [0x12, 0x34, 0x56, 0x78] 72 | numBytes = len(writeValues) 73 | print("Writing:") 74 | print([hex(x) for x in writeValues]) 75 | ljm.eWriteName(handle, "ASYNCH_NUM_BYTES_TX", numBytes) 76 | ljm.eWriteNameArray(handle, "ASYNCH_DATA_TX", numBytes, writeValues) 77 | ljm.eWriteName(handle, "ASYNCH_TX_GO", 1) 78 | 79 | sleep(1) 80 | 81 | readValues = ljm.eReadNameArray(handle, "ASYNCH_DATA_RX", numBytes) 82 | print("\nRead:") 83 | print([hex(int(val)) for val in readValues]) 84 | 85 | # Close handle 86 | ljm.close(handle) 87 | -------------------------------------------------------------------------------- /Examples/More/Config/read_LJM_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates ReadLibraryConfigS, ReadLibraryConfigStringS and 3 | WriteLibraryConfigS usage. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Constants: 13 | https://labjack.com/support/software/api/ljm/constants 14 | Library Configuration Functions: 15 | https://labjack.com/support/software/api/ljm/function-reference/library-configuration-functions 16 | 17 | Note: 18 | Our Python interfaces throw exceptions when there are any issues with 19 | device communications that need addressed. Many of our examples will 20 | terminate immediately when an exception is thrown. The onus is on the API 21 | user to address the cause of any exceptions thrown, and add exception 22 | handling when appropriate. We create our own exception classes that are 23 | derived from the built-in Python Exception class and can be caught as such. 24 | For more information, see the implementation in our source code and the 25 | Python standard documentation. 26 | """ 27 | from labjack import ljm 28 | 29 | 30 | # Read the name of the error constants file being used by LJM 31 | configString = "LJM_ERROR_CONSTANTS_FILE" 32 | print("%s: %s" % (configString, ljm.readLibraryConfigStringS(configString))) 33 | 34 | # Write the communication send/receive timeout for LJM 35 | configString = "LJM_SEND_RECEIVE_TIMEOUT_MS" 36 | ljm.writeLibraryConfigS(configString, 5000) 37 | 38 | # Read the communication send/receive timeout for LJM 39 | print("%s: %d" % (configString, ljm.readLibraryConfigS(configString))) 40 | -------------------------------------------------------------------------------- /Examples/More/Config/read_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read configuration settings on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnames 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview(Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | deviceType = info[0] 48 | 49 | # Setup and call eReadNames to read configuration values from the LabJack. 50 | if deviceType == ljm.constants.dtT4: 51 | # LabJack T4 configuration to read 52 | names = ["PRODUCT_ID", "HARDWARE_VERSION", "FIRMWARE_VERSION", 53 | "BOOTLOADER_VERSION", "SERIAL_NUMBER", "POWER_ETHERNET_DEFAULT", 54 | "POWER_AIN_DEFAULT", "POWER_LED_DEFAULT"] 55 | else: 56 | # LabJack T7 and T8 configuration to read 57 | names = ["PRODUCT_ID", "HARDWARE_VERSION", "FIRMWARE_VERSION", 58 | "BOOTLOADER_VERSION", "WIFI_VERSION", "SERIAL_NUMBER", 59 | "POWER_ETHERNET_DEFAULT", "POWER_WIFI_DEFAULT", 60 | "POWER_AIN_DEFAULT", "POWER_LED_DEFAULT"] 61 | 62 | numFrames = len(names) 63 | results = ljm.eReadNames(handle, numFrames, names) 64 | 65 | print("\nConfiguration settings:") 66 | for i in range(numFrames): 67 | print(" %s : %f" % (names[i], results[i])) 68 | 69 | # Close handle 70 | ljm.close(handle) 71 | -------------------------------------------------------------------------------- /Examples/More/Config/read_device_name_string.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the device name string from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNameString: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnamestring 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview(Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Call eReadNameString to read the name string from the LabJack. 48 | string = ljm.eReadNameString(handle, "DEVICE_NAME_DEFAULT") 49 | 50 | print("\nDevice name : %s" % string) 51 | 52 | # Close handle 53 | ljm.close(handle) 54 | -------------------------------------------------------------------------------- /Examples/More/Config/write_device_name_string.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to set the device name string on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteNameString: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenamestring 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Hardware Overview (Device Information Registers): 20 | https://labjack.com/support/datasheets/t-series/hardware-overview 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Call eWriteNameString to set the name string on the LabJack. 48 | string = "LJTest" 49 | ljm.eWriteNameString(handle, "DEVICE_NAME_DEFAULT", string) 50 | 51 | print("\nSet device name : %s" % string) 52 | 53 | # Close handle 54 | ljm.close(handle) 55 | -------------------------------------------------------------------------------- /Examples/More/Config/write_power_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to configure default power settings on a LabJack. 3 | Note: The T8 is not supported for this example. 4 | 5 | Relevant Documentation: 6 | 7 | LJM Library: 8 | LJM Library Installer: 9 | https://labjack.com/support/software/installers/ljm 10 | LJM Users Guide: 11 | https://labjack.com/support/software/api/ljm 12 | Opening and Closing: 13 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 14 | eWriteNames: 15 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 16 | 17 | T-Series and I/O: 18 | Modbus Map: 19 | https://labjack.com/support/software/api/modbus/modbus-map 20 | WiFi: 21 | https://labjack.com/support/datasheets/t-series/wifi 22 | Ethernet: 23 | https://labjack.com/support/datasheets/t-series/ethernet 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | from labjack import ljm 36 | 37 | 38 | # Open first found LabJack 39 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 42 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 43 | 44 | info = ljm.getHandleInfo(handle) 45 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 46 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 47 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 48 | 49 | # Setup and call eWriteNames to write config. values to the LabJack. 50 | numFrames = 4 51 | names = ["POWER_ETHERNET_DEFAULT", "POWER_WIFI_DEFAULT", "POWER_AIN_DEFAULT", 52 | "POWER_LED_DEFAULT"] 53 | aValues = [1, 0, 1, 54 | 1] 55 | ljm.eWriteNames(handle, numFrames, names, aValues) 56 | 57 | print("\nSet configuration settings:") 58 | for i in range(numFrames): 59 | print(" %s : %f" % (names[i], aValues[i])) 60 | 61 | # Close handle 62 | ljm.close(handle) 63 | -------------------------------------------------------------------------------- /Examples/More/DAC/single_dac.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates setting a single DAC on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 15 | Constants: 16 | https://labjack.com/support/software/api/ljm/constants 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | DAC: 22 | https://labjack.com/support/datasheets/t-series/dac 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | from labjack import ljm 35 | 36 | 37 | # Open first found LabJack 38 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 39 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 42 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 43 | 44 | info = ljm.getHandleInfo(handle) 45 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 46 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 47 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 48 | 49 | # Setup and call eWriteName to set DAC0's voltage. 50 | name = "DAC0" 51 | value = 3.5 # 3.5 V 52 | ljm.eWriteName(handle, name, value) 53 | 54 | print("\n%s set to %0.3f V." % (name, value)) 55 | 56 | # Close handle 57 | ljm.close(handle) 58 | -------------------------------------------------------------------------------- /Examples/More/DIO/single_dio_read.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read a single digital input/output. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Digital I/O: 20 | https://labjack.com/support/datasheets/t-series/digital-io 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | deviceType = info[0] 48 | 49 | # Setup and call eReadName to read a DIO state from the LabJack. 50 | if deviceType == ljm.constants.dtT4: 51 | # Reading from FIO4 on the LabJack T4. FIO0-FIO3 are reserved for AIN0-AIN3. 52 | # Note: Reading a single digital I/O will change the line from analog to 53 | # digital input. 54 | name = "FIO4" 55 | else: 56 | # Reading from FIO0 on the LabJack T7 and T8. 57 | name = "FIO0" 58 | result = ljm.eReadName(handle, name) 59 | 60 | print("\n%s state : %f" % (name, result)) 61 | 62 | # Close handle 63 | ljm.close(handle) 64 | -------------------------------------------------------------------------------- /Examples/More/DIO/single_dio_write.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to set a single digital state on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Digital I/O: 20 | https://labjack.com/support/datasheets/t-series/digital-io 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | deviceType = info[0] 48 | 49 | # Setup and call eWriteName to set a DIO state on the LabJack. 50 | if deviceType == ljm.constants.dtT4: 51 | # Setting FIO4 on the LabJack T4. FIO0-FIO3 are reserved for AIN0-AIN3. 52 | name = "FIO4" 53 | 54 | # If the FIO/EIO line is an analog input, it needs to first be changed to a 55 | # digital I/O by reading from the line or setting it to digital I/O with the 56 | # DIO_ANALOG_ENABLE register. 57 | 58 | # Reading from the digital line in case it was previously an analog input. 59 | ljm.eReadName(handle, name) 60 | else: 61 | # Setting FIO0 on the LabJack T7 and T8. 62 | name = "FIO0" 63 | 64 | state = 0 # Output state = low (0 = low, 1 = high) 65 | ljm.eWriteName(handle, name, state) 66 | print("\nSet %s state : %f" % (name, state)) 67 | 68 | # Close handle 69 | ljm.close(handle) 70 | -------------------------------------------------------------------------------- /Examples/More/DIO_EF/dio_ef_config_counter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Enables an Interrupt Counter measurement to rising edges and a 10 Hz square 3 | wave on DAC1. To measure the rising edges on DAC1, connect a jumper between 4 | DAC1 and FIO0 on T7/T8 or FIO4 on T4. 5 | 6 | The Interrupt Counter counts the rising edge of pulses on the associated IO 7 | line. This interrupt-based digital I/O extended feature (DIO-EF) is not purely 8 | implemented in hardware, but rather firmware must service each edge. 9 | 10 | This example will read the DAC1 rising edge count at 1 second intervals 5 11 | times. Then the count will be read and reset, and after 1 second, the count is 12 | read again. 13 | 14 | For more information on the Interrupt Counter DIO_EF mode see section 13.2.9 of 15 | the T-Series Datasheet. 16 | https://support.labjack.com/docs/13-2-9-interrupt-counter-t-series-datasheet 17 | 18 | Note: 19 | Our Python interfaces throw exceptions when there are any issues with 20 | device communications that need addressed. Many of our examples will 21 | terminate immediately when an exception is thrown. The onus is on the API 22 | user to address the cause of any exceptions thrown, and add exception 23 | handling when appropriate. We create our own exception classes that are 24 | derived from the built-in Python Exception class and can be caught as such. 25 | For more information, see the implementation in our source code and the 26 | Python standard documentation. 27 | """ 28 | import time 29 | 30 | from labjack import ljm 31 | 32 | 33 | # Open first found LabJack 34 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 35 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 36 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 37 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 38 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 39 | 40 | info = ljm.getHandleInfo(handle) 41 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 42 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 43 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 44 | 45 | deviceType = info[0] 46 | 47 | 48 | # --- Interrupt Counter --- 49 | counterDIO = 0 # DIO Pin that will measure the signal, T7/T8 use FIO0, T4 use FIO4. 50 | 51 | 52 | # Selecting a specific DIO# Pin is necessary for each T-Series Device, only specific DIO# pins can do an Interrupt Counter measurement. 53 | # For detailed T-Series Device DIO_EF pin mapping tables see section 13.2 of the T-Series Datasheet: 54 | # https://support.labjack.com/docs/13-2-dio-extended-features-t-series-datasheet 55 | if deviceType == ljm.constants.dtT4: 56 | # For the T4, use FIO4/DIO4 for the Interrupt Counter measurement. 57 | counterDIO = 4 58 | 59 | # --- How to Configure Interrupt Counter Measurment --- 60 | # See Datasheet reference for DIO_EF Interrupt Counter: 61 | # https://support.labjack.com/docs/13-2-9-interrupt-counter-t-series-datasheet 62 | # 63 | # -- Registers used for configuring DAC1 Frequency Out --- 64 | # "DAC1_FREQUENCY_OUT_ENABLE": 0 = off, 1 = output 10 Hz signal on DAC1. The signal will be a square wave with peaks of 0 and 3.3V. 65 | # 66 | # --- Registers used for configuring Interrupt Counter --- 67 | # "DIO#_EF_INDEX": Sets desired DIO_EF feature, Interrupt Counter is DIO_EF Index 8. 68 | # "DIO#_EF_ENABLE": Enables/Disables the DIO_EF mode. 69 | # 70 | # Interrupt Counter counts the rising edge of pulses on the associated IO line. 71 | # This interrupt-based digital I/O extended feature (DIO-EF) is not purely implemented in hardware, but rather firmware must service each edge. 72 | # 73 | # For a more detailed walkthrough see Configuring and Reading a Counter: 74 | # https://support.labjack.com/docs/configuring-reading-a-counter 75 | # 76 | # For a more accurate measurement for counting Rising edges, use the hardware clocked High-Speed Counter mode. 77 | # See the docs for High-Speed Counter here: 78 | # https://support.labjack.com/docs/13-2-8-high-speed-counter-t-series-datasheet 79 | 80 | 81 | # Configure Interrupt Counter Registers 82 | ljm.eWriteName(handle, "DIO%d_EF_INDEX" % counterDIO, 8) # Set DIO#_EF_INDEX to 8 for Interrupt Counter. 83 | ljm.eWriteName(handle, "DAC1_FREQUENCY_OUT_ENABLE", 1) # Enable 10 Hz square wave on DAC1. 84 | ljm.eWriteName(handle, "DIO%d_EF_ENABLE" % counterDIO, 1) # Enable the DIO#_EF Mode. 85 | 86 | print("\n--- Outputting a 10 Hz signal on DAC1, measuring signal on FIO%d ---\n" % counterDIO) 87 | 88 | # --- How to read the measured count of rising edges? --- 89 | # To read the count of Rising Edges, use the register below. 90 | # DIO#_EF_READ_A: Returns the current Count. 91 | # 92 | # To read and reset the count: 93 | # DIO#_EF_READ_A_AND_RESET: Reads the current count then clears the counter. 94 | # 95 | # Note that there is a brief period of time between reading and clearing during which edges can be missed. 96 | # During normal operation this time period is 10-30 microseconds. 97 | # If missed edges at this point can not be tolerated then reset should not be used. 98 | 99 | # If measuring at 1 second intervals, you should expect to see ~10 rising edges per second on the 10 Hz DAC1_FREQUENCY_OUT signal. 100 | 101 | numRisingEdges = 0 102 | numRisingEdgesBeforeReset = 0 103 | numRisingEdgesAfterReset = 0 104 | 105 | # Read all of the measured values. 106 | for i in range(5): 107 | time.sleep(1.0) # Sleep for 1 Second 108 | numRisingEdges = ljm.eReadName(handle, "DIO%d_EF_READ_A" % counterDIO) 109 | 110 | print("DIO_EF Measured Values - Rising Edges: %.1f" % numRisingEdges) 111 | 112 | print("\n--- Reading and Resetting the count of DIO%d ---\n" % counterDIO) 113 | 114 | numRisingEdgesBeforeReset = ljm.eReadName(handle, "DIO%d_EF_READ_A_AND_RESET" % counterDIO) 115 | time.sleep(1.0) # Sleep for 1 Second 116 | numRisingEdgesAfterReset = ljm.eReadName(handle, "DIO%d_EF_READ_A_AND_RESET" % counterDIO) 117 | 118 | print("DIO_EF Edges Before Read and Reset: %.1f" % numRisingEdgesBeforeReset) 119 | print("DIO_EF Edges After Read and Reset + 1 sec sleep: %.1f" % numRisingEdgesAfterReset) 120 | 121 | 122 | # Disable Counter and DAC1 Frequency Out. 123 | aNames = ["DIO%d_EF_ENABLE" % counterDIO, 124 | "DAC1_FREQUENCY_OUT_ENABLE"] 125 | aValues = [0, 126 | 0, 127 | 0] 128 | numFrames = len(aNames) 129 | print("\n--- Disabling Interrupt Counter and DAC1_FREQUENCY_OUT ---") 130 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 131 | 132 | 133 | # Close handle 134 | ljm.close(handle) 135 | -------------------------------------------------------------------------------- /Examples/More/Ethernet/read_ethernet_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the ethernet configuration settings from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnames 15 | NumberToIP: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertoip 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | Ethernet: 22 | https://labjack.com/support/datasheets/t-series/ethernet 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | from labjack import ljm 35 | 36 | 37 | # Open first found LabJack 38 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 39 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 42 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 43 | 44 | info = ljm.getHandleInfo(handle) 45 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 46 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 47 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 48 | 49 | # Setup and call eReadNames to read ethernet configuration from the LabJack. 50 | names = ["ETHERNET_IP", "ETHERNET_SUBNET", "ETHERNET_GATEWAY", 51 | "ETHERNET_IP_DEFAULT", "ETHERNET_SUBNET_DEFAULT", 52 | "ETHERNET_GATEWAY_DEFAULT", "ETHERNET_DHCP_ENABLE", 53 | "ETHERNET_DHCP_ENABLE_DEFAULT"] 54 | numFrames = len(names) 55 | results = ljm.eReadNames(handle, numFrames, names) 56 | 57 | print("\nEthernet configuration:") 58 | for i in range(numFrames): 59 | if names[i].startswith("ETHERNET_DHCP_ENABLE"): 60 | print(" %s : %.0f" % (names[i], results[i])) 61 | else: 62 | print(" %s : %.0f - %s" % 63 | (names[i], results[i], ljm.numberToIP(int(results[i])))) 64 | 65 | # Close handle 66 | ljm.close(handle) 67 | -------------------------------------------------------------------------------- /Examples/More/Ethernet/read_ethernet_mac.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the ethernet MAC from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadAddressByteArray: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadaddressbytearray 15 | NumberToMAC: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertomac 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | Ethernet: 22 | https://labjack.com/support/datasheets/t-series/ethernet 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | import struct 35 | 36 | from labjack import ljm 37 | 38 | 39 | # Open first found LabJack 40 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 41 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 42 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 43 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 44 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 45 | 46 | info = ljm.getHandleInfo(handle) 47 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 48 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 49 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 50 | 51 | # Call eReadAddressByteArray to read the ethernet MAC (address 60020) from the 52 | # LabJack. We are reading a byte array which is the big endian binary 53 | # representation of the 64-bit MAC. 54 | macBytes = ljm.eReadAddressByteArray(handle, 60020, 8) 55 | 56 | # Convert big endian byte array to a 64-bit unsigned integer value 57 | mac, = struct.unpack(">Q", struct.pack("B"*8, *macBytes)) 58 | 59 | print("\nEthernet MAC : %i - %s" % (mac, ljm.numberToMAC(mac))) 60 | 61 | # Close handle 62 | ljm.close(handle) 63 | -------------------------------------------------------------------------------- /Examples/More/Ethernet/write_ethernet_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to set ethernet configuration settings on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 15 | IPToNumber: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmiptonumber 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | Ethernet: 22 | https://labjack.com/support/datasheets/t-series/ethernet 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | from labjack import ljm 35 | 36 | 37 | # Open first found LabJack 38 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 39 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 42 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 43 | 44 | info = ljm.getHandleInfo(handle) 45 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 46 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 47 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 48 | 49 | # Setup and call eWriteNames to set the ethernet configuration on the LabJack. 50 | numFrames = 4 51 | names = ["ETHERNET_IP_DEFAULT", "ETHERNET_SUBNET_DEFAULT", 52 | "ETHERNET_GATEWAY_DEFAULT", "ETHERNET_DHCP_ENABLE_DEFAULT"] 53 | values = [ljm.ipToNumber("192.168.1.207"), ljm.ipToNumber("255.255.255.0"), 54 | ljm.ipToNumber("192.168.1.1"), 1] 55 | ljm.eWriteNames(handle, numFrames, names, values) 56 | 57 | print("\nSet ethernet configuration:") 58 | for i in range(numFrames): 59 | if names[i] == "ETHERNET_DHCP_ENABLE_DEFAULT": 60 | print(" %s : %.0f" % (names[i], values[i])) 61 | else: 62 | print(" %s : %.0f - %s" % 63 | (names[i], values[i], ljm.numberToIP(int(values[i])))) 64 | 65 | # Close handle 66 | ljm.close(handle) 67 | -------------------------------------------------------------------------------- /Examples/More/I2C/i2c_eeprom.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates I2C communication using a LabJack. The demonstration uses a 3 | LJTick-DAC connected to FIO0/FIO1 for the T7 and T8, or FIO4/FIO5 for the T4, 4 | and configures the I2C settings. Then a read, write and again a read are 5 | performed on the LJTick-DAC EEPROM. 6 | 7 | Relevant Documentation: 8 | 9 | LJM Library: 10 | LJM Library Installer: 11 | https://labjack.com/support/software/installers/ljm 12 | LJM Users Guide: 13 | https://labjack.com/support/software/api/ljm 14 | Opening and Closing: 15 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 16 | eWriteName: 17 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 18 | Multiple Value Functions (such as eWriteNameByteArray and 19 | eReadNameByteArray): 20 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 21 | 22 | T-Series and I/O: 23 | Modbus Map: 24 | https://labjack.com/support/software/api/modbus/modbus-map 25 | Digital I/O: 26 | https://labjack.com/support/datasheets/t-series/digital-io 27 | I2C: 28 | https://labjack.com/support/datasheets/t-series/digital-io/i2c 29 | LJTick-DAC: 30 | https://labjack.com/support/datasheets/accessories/ljtick-dac 31 | 32 | Note: 33 | Our Python interfaces throw exceptions when there are any issues with 34 | device communications that need addressed. Many of our examples will 35 | terminate immediately when an exception is thrown. The onus is on the API 36 | user to address the cause of any exceptions thrown, and add exception 37 | handling when appropriate. We create our own exception classes that are 38 | derived from the built-in Python Exception class and can be caught as such. 39 | For more information, see the implementation in our source code and the 40 | Python standard documentation. 41 | """ 42 | from random import randrange 43 | 44 | from labjack import ljm 45 | 46 | 47 | # Open first found LabJack 48 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 49 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 50 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 51 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 52 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 53 | 54 | info = ljm.getHandleInfo(handle) 55 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 56 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 57 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 58 | 59 | deviceType = info[0] 60 | 61 | # Configure the I2C communication. 62 | if deviceType == ljm.constants.dtT4: 63 | # Configure FIO4 and FIO5 as digital I/O. 64 | ljm.eWriteName(handle, "DIO_INHIBIT", 0xFFFCF) 65 | ljm.eWriteName(handle, "DIO_ANALOG_ENABLE", 0x00000) 66 | 67 | # For the T4, using FIO4 and FIO5 for SCL and SDA pins. FIO0 to FIO3 are 68 | # reserved for analog inputs, and digital lines are required. 69 | ljm.eWriteName(handle, "I2C_SDA_DIONUM", 5) # SDA pin number = 5 (FIO5) 70 | ljm.eWriteName(handle, "I2C_SCL_DIONUM", 4) # SCL pin number = 4 (FIO4) 71 | else: 72 | # For the T7 and T8, using FIO0 and FIO1 for the SCL and SDA pins. 73 | ljm.eWriteName(handle, "I2C_SDA_DIONUM", 1) # SDA pin number = 1 (FIO1) 74 | ljm.eWriteName(handle, "I2C_SCL_DIONUM", 0) # SCL pin number = 0 (FIO0) 75 | 76 | # Speed throttle is inversely proportional to clock frequency. 0 = max. 77 | ljm.eWriteName(handle, "I2C_SPEED_THROTTLE", 65516) # Speed throttle = 65516 (~100 kHz) 78 | 79 | # Options bits: 80 | # bit0: Reset the I2C bus. 81 | # bit1: Restart w/o stop 82 | # bit2: Disable clock stretching. 83 | ljm.eWriteName(handle, "I2C_OPTIONS", 0) # Options = 0 84 | 85 | ljm.eWriteName(handle, "I2C_SLAVE_ADDRESS", 80) # Slave Address of the I2C chip = 80 (0x50) 86 | 87 | # Initial read of EEPROM bytes 0-3 in the user memory area. We need a single I2C 88 | # transmission that writes the chip's memory pointer and then reads the data. 89 | ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 1) # Set the number of bytes to transmit 90 | ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 4) # Set the number of bytes to receive 91 | 92 | # Set the TX bytes. We are sending 1 byte for the address. 93 | numBytes = 1 94 | aBytes = [0] # Byte 0: Memory pointer = 0 95 | ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", numBytes, aBytes) 96 | 97 | ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. 98 | 99 | # Read the RX bytes. 100 | numBytes = 4 101 | # aBytes[0] to aBytes[3] will contain the data 102 | aBytes = [0]*4 103 | aBytes = ljm.eReadNameByteArray(handle, "I2C_DATA_RX", numBytes) 104 | 105 | print("\nRead User Memory [0-3] = %s" % 106 | " ".join([("%.0f" % val) for val in aBytes])) 107 | 108 | # Write EEPROM bytes 0-3 in the user memory area, using the page write 109 | # technique. Note that page writes are limited to 16 bytes max, and must be 110 | # aligned with the 16-byte page intervals. For instance, if you start writing 111 | # at address 14, you can only write two bytes because byte 16 is the start of a 112 | # new page. 113 | ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 5) # Set the number of bytes to transmit 114 | ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 0) # Set the number of bytes to receive 115 | 116 | # Set the TX bytes. 117 | numBytes = 5 118 | aBytes = [0] # Byte 0: Memory pointer = 0 119 | # Create 4 new random numbers to write (aBytes[1-4]). 120 | aBytes.extend([randrange(0, 256) for _ in range(4)]) 121 | ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", numBytes, aBytes) 122 | 123 | ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. 124 | 125 | print("Write User Memory [0-3] = %s" % 126 | " ".join([("%.0f" % val) for val in aBytes[1:]])) 127 | 128 | # Final read of EEPROM bytes 0-3 in the user memory area. We need a single I2C 129 | # transmission that writes the address and then reads the data. 130 | ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 1) # Set the number of bytes to transmit 131 | ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 4) # Set the number of bytes to receive 132 | 133 | # Set the TX bytes. We are sending 1 byte for the address. 134 | numBytes = 1 135 | aBytes = [0] # Byte 0: Memory pointer = 0 136 | ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", numBytes, aBytes) 137 | 138 | ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. 139 | 140 | # Read the RX bytes. 141 | numBytes = 4 142 | # aBytes[0] to aBytes[3] will contain the data 143 | aBytes = [0]*4 144 | aBytes = ljm.eReadNameByteArray(handle, "I2C_DATA_RX", numBytes) 145 | 146 | print("Read User Memory [0-3] = %s" % 147 | " ".join([("%.0f" % val) for val in aBytes])) 148 | 149 | # Close handle 150 | ljm.close(handle) 151 | -------------------------------------------------------------------------------- /Examples/More/I2C/sht3x.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates I2C communication using a LabJack. The demonstration uses an 3 | SHT3X temperature and humidity sensor connected to FIO0/FIO1/FIO2 for the T7 4 | and T8, or FIO4/FIO5/FIO6 for the T4. A write command to set up single shot 5 | acquisition is performed, then subsequently a read only transaction is 6 | performed to read sensor data. 7 | 8 | Note about the SHT3X sensor: 9 | 10 | LabJack firmware has been updated to support SHT3X through SBUS registers. SBUS 11 | is much easier to use and is the recommended way to interface with the SHT3X 12 | sensor. Support was added in these firmware versions: 13 | T4 v1.0029+ 14 | T7 v1.0305+ 15 | T8 v1.0017+ 16 | 17 | SBUS is documented here: 18 | https://support.labjack.com/docs/13-5-sbus-t-series-datasheet 19 | 20 | Relevant Documentation: 21 | 22 | LJM Library: 23 | LJM Library Installer: 24 | https://labjack.com/support/software/installers/ljm 25 | LJM Users Guide: 26 | https://labjack.com/support/software/api/ljm 27 | Opening and Closing: 28 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 29 | eWriteName: 30 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 31 | Multiple Value Functions(such as eWriteNameByteArray): 32 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 33 | 34 | T-Series and I/O: 35 | Modbus Map: 36 | https://labjack.com/support/software/api/modbus/modbus-map 37 | Digital I/O: 38 | https://labjack.com/support/datasheets/t-series/digital-io 39 | I2C: 40 | https://labjack.com/support/datasheets/t-series/digital-io/i2c 41 | 42 | Note: 43 | Our Python interfaces throw exceptions when there are any issues with 44 | device communications that need addressed. Many of our examples will 45 | terminate immediately when an exception is thrown. The onus is on the API 46 | user to address the cause of any exceptions thrown, and add exception 47 | handling when appropriate. We create our own exception classes that are 48 | derived from the built-in Python Exception class and can be caught as such. 49 | For more information, see the implementation in our source code and the 50 | Python standard documentation. 51 | """ 52 | from time import sleep 53 | 54 | from labjack import ljm 55 | 56 | 57 | # Open first found LabJack 58 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 59 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 60 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 61 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 62 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 63 | 64 | info = ljm.getHandleInfo(handle) 65 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 66 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 67 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 68 | 69 | deviceType = info[0] 70 | # Configure the I2C communication. 71 | if deviceType == ljm.constants.dtT4: 72 | # Configure FIO4, FIO5, and FIO6 as digital I/O. 73 | ljm.eWriteName(handle, "DIO_INHIBIT", 0xFFF8F) 74 | ljm.eWriteName(handle, "DIO_ANALOG_ENABLE", 0x00000) 75 | 76 | # For the T4, using FIO4 and FIO5 for SCL and SDA pins. FIO0 to FIO3 are 77 | # reserved for analog inputs, and digital lines are required. 78 | ljm.eWriteName(handle, "I2C_SDA_DIONUM", 5) # SDA pin number = 5 (FIO5) 79 | ljm.eWriteName(handle, "I2C_SCL_DIONUM", 4) # SCL pin number = 4 (FIO4) 80 | # Use FIO6 for power by setting it to output high 81 | ljm.eWriteName(handle, "FIO6", 1) 82 | else: 83 | # For the T7 and T8, using FIO0 and FIO1 for the SCL and SDA pins. 84 | ljm.eWriteName(handle, "I2C_SDA_DIONUM", 1) # SDA pin number = 1 (FIO1) 85 | ljm.eWriteName(handle, "I2C_SCL_DIONUM", 0) # SCL pin number = 0 (FIO0) 86 | # Use FIO2 for power by setting it to output high 87 | ljm.eWriteName(handle, "FIO2", 1) 88 | 89 | # Speed throttle is inversely proportional to clock frequency. 0 = max. 90 | ljm.eWriteName(handle, "I2C_SPEED_THROTTLE", 65000) # Speed throttle = 65516 (~100 kHz) 91 | 92 | # Options bits: 93 | # bit0: Reset the I2C bus. 94 | # bit1: Restart w/o stop. 95 | # bit2: Disable clock stretching. 96 | ljm.eWriteName(handle, "I2C_OPTIONS", 0) # Options = 0 97 | 98 | # The SHT3x address could be 0x44 or 0x45 depending on the address pin voltage. 99 | # A slave address of 0x44 indicates the ADDR pin is connected to a logic low. 100 | ljm.eWriteName(handle, "I2C_SLAVE_ADDRESS", 0x44) 101 | 102 | # Start with a single shot write command to the SHT3x sensor. 103 | ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 2) # Set the number of bytes to transmit 104 | ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 0) # Set the number of bytes to receive 105 | 106 | # Set the TX bytes 107 | numBytes = 2 108 | # 0x24 = clock stretching disabled, 0x00 = high repeatability 109 | aBytes = [0x24, 0x00] 110 | ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", numBytes, aBytes) 111 | ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. 112 | 113 | # The sensor needs at least 15ms for the measurement. Wait 20ms. 114 | sleep(0.02) 115 | 116 | # Do a read only transaction to obtain the readings 117 | ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 0) # Set the number of bytes to transmit 118 | ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 6) # Set the number of bytes to receive 119 | ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. 120 | 121 | # SHT3x sensors should always return 6 bytes for single shot acquisition: 122 | # [temp MSB, temp LSB, CRC, RH MSB, RH LSB, CRC] 123 | numBytes = 6 124 | aBytes = [0]*6 125 | aBytes = ljm.eReadNameByteArray(handle, "I2C_DATA_RX", numBytes) 126 | tempBin = aBytes[0]*256 + aBytes[1] 127 | tempC = 175*tempBin / 65535 - 45 128 | rhBin = aBytes[3]*256 + aBytes[4] 129 | rh = 100*rhBin / 65535 130 | print("tempC = %f degC, RH = %f%%\n" % (tempC, rh)) 131 | 132 | # Close handle 133 | ljm.close(handle) 134 | -------------------------------------------------------------------------------- /Examples/More/List_All/list_all.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates usage of the listAll functions (LJM_ListAll) which scans for 3 | LabJack devices and returns information describing the found devices. This will 4 | only find LabJack devices supported by the LJM library. 5 | 6 | Relevant Documentation: 7 | 8 | LJM Library: 9 | LJM Library Installer: 10 | https://labjack.com/support/software/installers/ljm 11 | LJM Users Guide: 12 | https://labjack.com/support/software/api/ljm 13 | ListAll: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmlistall 15 | ListAllS: 16 | https://labjack.com/support/software/api/ljm/function-reference/ljmlistalls 17 | NumberToIP: 18 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertoip 19 | Constants: 20 | https://labjack.com/support/software/api/ljm/constants 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | DEVICE_TYPES = {ljm.constants.dtT8: "T8", 36 | ljm.constants.dtT7: "T7", 37 | ljm.constants.dtT4: "T4", 38 | ljm.constants.dtDIGIT: "Digit"} 39 | CONN_TYPES = {ljm.constants.ctUSB: "USB", 40 | ljm.constants.ctTCP: "TCP", 41 | ljm.constants.ctETHERNET: "Ethernet", 42 | ljm.constants.ctWIFI: "WiFi"} 43 | 44 | 45 | def displayDeviceInfo(functionName, info): 46 | """Displays the LabJack devices information from listAll or 47 | listAllS. 48 | 49 | Args: 50 | functionName: The name of the function used 51 | info: tuple returned by listAll or listAllS 52 | 53 | """ 54 | print("\n%s found %i LabJacks:\n" % (functionName, info[0])) 55 | fmt = ''.join(["{%i:<18}" % i for i in range(0, 4)]) 56 | print(fmt.format("Device Type", "Connection Type", "Serial Number", 57 | "IP Address")) 58 | for i in range(info[0]): 59 | print(fmt.format(DEVICE_TYPES.setdefault(info[1][i], str(info[1][i])), 60 | CONN_TYPES.setdefault(info[2][i], str(info[2][i])), 61 | str(info[3][i]), ljm.numberToIP(info[4][i]))) 62 | 63 | 64 | # listAll and listAllS returns the tuple (numFound, aDeviceTypes, 65 | # aConnectionTypes, aSerialNumbers, aIPAddresses) 66 | 67 | # Find and display LabJack devices with listAllS. 68 | info = ljm.listAllS("ANY", "ANY") 69 | displayDeviceInfo("listAllS", info) 70 | 71 | 72 | # Find and display LabJack devices with listAll. 73 | #info = ljm.listAll(ljm.constants.ctANY, ljm.constants.ctANY) 74 | #displayDeviceInfo("listAll", info) 75 | -------------------------------------------------------------------------------- /Examples/More/Lua/lua_execution_control.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to control Lua script execution with an LJM host app. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | Single Value Functions (such as eWriteName and eReadName): 14 | https://labjack.com/support/software/api/ljm/function-reference/single-value-functions 15 | Multiple Value Functions (such as eWriteNameByteArray and 16 | eReadNameByteArray): 17 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 18 | 19 | T-Series and I/O: 20 | Modbus Map: 21 | https://labjack.com/support/software/api/modbus/modbus-map 22 | User-RAM: 23 | https://labjack.com/support/datasheets/t-series/lua-scripting 24 | 25 | Note: 26 | Our Python interfaces throw exceptions when there are any issues with 27 | device communications that need addressed. Many of our examples will 28 | terminate immediately when an exception is thrown. The onus is on the API 29 | user to address the cause of any exceptions thrown, and add exception 30 | handling when appropriate. We create our own exception classes that are 31 | derived from the built-in Python Exception class and can be caught as such. 32 | For more information, see the implementation in our source code and the 33 | Python standard documentation. 34 | """ 35 | from time import sleep 36 | 37 | from labjack import ljm 38 | 39 | 40 | def loadLuaScript(handle, luaScript): 41 | """Function that loads and begins running a Lua script. 42 | 43 | """ 44 | try: 45 | scriptLen = len(luaScript) 46 | print("\nScript length: %u\n" % scriptLen) 47 | 48 | # LUA_RUN must be written to twice to disable any running scripts. 49 | ljm.eWriteName(handle, "LUA_RUN", 0) 50 | 51 | # Then, wait for the Lua VM to shut down. Some T7 firmware 52 | # versions need a longer time to shut down than others. 53 | sleep(0.6) 54 | 55 | ljm.eWriteName(handle, "LUA_RUN", 0) 56 | ljm.eWriteName(handle, "LUA_SOURCE_SIZE", scriptLen) 57 | ljm.eWriteNameByteArray(handle, "LUA_SOURCE_WRITE", scriptLen, luaScript) 58 | ljm.eWriteName(handle, "LUA_DEBUG_ENABLE", 1) 59 | ljm.eWriteName(handle, "LUA_DEBUG_ENABLE_DEFAULT", 1) 60 | ljm.eWriteName(handle, "LUA_RUN", 1) 61 | except ljm.LJMError: 62 | print("Error while loading the Lua script") 63 | raise 64 | 65 | 66 | def readLuaInfo(handle): 67 | """Function that selects the current Lua execution block and prints 68 | out associated info from Lua. 69 | 70 | """ 71 | try: 72 | for i in range(20): 73 | # The script sets the interval length with LJ.IntervalConfig. 74 | # Note that LJ.IntervalConfig has some jitter and that this 75 | # program's interval (set by sleep) will have some minor drift 76 | # from LJ.IntervalConfig. 77 | sleep(1) 78 | 79 | print("LUA_RUN: %d" % ljm.eReadName(handle, "LUA_RUN")) 80 | 81 | # Add custom logic to control the Lua execution block. 82 | executionLoopNum = i % 3 83 | 84 | # Write which Lua control block to run using the user ram register. 85 | ljm.eWriteName(handle, "USER_RAM0_U16", executionLoopNum) 86 | 87 | numBytes = ljm.eReadName(handle, "LUA_DEBUG_NUM_BYTES") 88 | if (int(numBytes) == 0): 89 | continue 90 | print("LUA_DEBUG_NUM_BYTES: %d\n" % numBytes) 91 | aBytes = ljm.eReadNameByteArray(handle, "LUA_DEBUG_DATA", int(numBytes)) 92 | luaMessage = "".join([("%c" % val) for val in aBytes]) 93 | print("LUA_DEBUG_DATA: %s" % luaMessage) 94 | except ljm.LJMError: 95 | print("Error while running the main loop") 96 | raise 97 | 98 | 99 | def main(): 100 | luaScript = """-- Use USER_RAM0_U16 (register 46180) to determine which control loop to run 101 | local ramval = 0 102 | MB.W(46180, 0, ramval) 103 | local loop0 = 0 104 | local loop1 = 1 105 | local loop2 = 2 106 | 107 | -- Setup an interval to control loop execution speed. Update every second 108 | LJ.IntervalConfig(0,1000) 109 | while true do 110 | if LJ.CheckInterval(0) then 111 | ramval = MB.R(46180, 0) 112 | 113 | if ramval == loop0 then 114 | print("using loop0") 115 | end 116 | 117 | if ramval == loop1 then 118 | print("using loop1") 119 | end 120 | 121 | if ramval == loop2 then 122 | print("using loop2") 123 | end 124 | 125 | end 126 | end\0""" 127 | 128 | # Open first found LabJack 129 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 130 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 131 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 132 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 133 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 134 | 135 | try: 136 | info = ljm.getHandleInfo(handle) 137 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 138 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 139 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 140 | 141 | loadLuaScript(handle, luaScript) 142 | print("LUA_RUN %d" % ljm.eReadName(handle, "LUA_RUN")) 143 | print("LUA_DEBUG_NUM_BYTES: %d" % ljm.eReadName(handle, "LUA_DEBUG_NUM_BYTES")) 144 | readLuaInfo(handle) 145 | 146 | # Close handle 147 | ljm.close(handle) 148 | except: 149 | ljm.eWriteName(handle, "LUA_RUN", 0) 150 | 151 | # Close handle 152 | ljm.close(handle) 153 | raise 154 | 155 | 156 | if __name__ == "__main__": 157 | main() 158 | -------------------------------------------------------------------------------- /Examples/More/SD/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labjack/labjack-ljm-python/ddf4a3f0a08b1757d8473f466644f6362a70fe88/Examples/More/SD/__init__.py -------------------------------------------------------------------------------- /Examples/More/SD/change_directory.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s directory' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | if len(sys.argv) != 2: 12 | usage() 13 | 14 | handle = sd_util.openDevice() 15 | sd_util.goToPath(handle, sys.argv[1]) 16 | ljm.close(handle) 17 | -------------------------------------------------------------------------------- /Examples/More/SD/delete_file.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s file_to_delete' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | if len(sys.argv) != 2: 12 | usage() 13 | 14 | handle = sd_util.openDevice() 15 | sd_util.deleteFile(handle, sys.argv[1]) 16 | ljm.close(handle) 17 | -------------------------------------------------------------------------------- /Examples/More/SD/get_disk_info.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | if len(sys.argv) != 1: 12 | print('No arguments are allowed') 13 | usage() 14 | 15 | handle = sd_util.openDevice() 16 | sd_util.printDiskInfo(handle) 17 | ljm.close(handle) 18 | -------------------------------------------------------------------------------- /Examples/More/SD/list_directory.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s [directory]' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | listCwd = None 12 | if len(sys.argv) == 1: 13 | listCwd = True 14 | elif len(sys.argv) == 2: 15 | listCwd = False 16 | else: 17 | usage() 18 | 19 | handle = sd_util.openDevice() 20 | 21 | if listCwd: 22 | dirToRead = sd_util.getCWD(handle) 23 | else: 24 | dirToRead = sys.argv[1] 25 | 26 | sd_util.listDirContents(handle, dirToRead) 27 | ljm.close(handle) 28 | -------------------------------------------------------------------------------- /Examples/More/SD/print_working_directory.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | if len(sys.argv) != 1: 12 | print('No arguments are allowed') 13 | usage() 14 | 15 | handle = sd_util.openDevice() 16 | print(sd_util.getCWD(handle)) 17 | ljm.close(handle) 18 | -------------------------------------------------------------------------------- /Examples/More/SD/read_file.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from labjack import ljm 3 | import sd_util 4 | 5 | 6 | def usage(): 7 | print('Usage: %s file_to_read' % (sys.argv[0])) 8 | exit() 9 | 10 | 11 | if len(sys.argv) != 2: 12 | usage() 13 | 14 | handle = sd_util.openDevice() 15 | print(sd_util.readFile(handle, sys.argv[1])) 16 | ljm.close(handle) 17 | -------------------------------------------------------------------------------- /Examples/More/SPI/spi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates SPI communication. 3 | 4 | You can short MOSI to MISO for testing. 5 | 6 | T7 and T8: 7 | MOSI FIO2 8 | MISO FIO3 9 | CLK FIO0 10 | CS FIO1 11 | 12 | T4: 13 | MOSI FIO6 14 | MISO FIO7 15 | CLK FIO4 16 | CS FIO5 17 | 18 | If you short MISO to MOSI, then you will read back the same bytes that you 19 | write. If you short MISO to GND, then you will read back zeros. If you 20 | short MISO to VS or leave it unconnected, you will read back 255s. 21 | 22 | Relevant Documentation: 23 | 24 | LJM Library: 25 | LJM Library Installer: 26 | https://labjack.com/support/software/installers/ljm 27 | LJM Users Guide: 28 | https://labjack.com/support/software/api/ljm 29 | Opening and Closing: 30 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 31 | eWriteName: 32 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 33 | Multiple Value Functions (such as eReadNames, eWriteNameByteArray and 34 | eReadNameByteArray): 35 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 36 | 37 | T-Series and I/O: 38 | Modbus Map: 39 | https://labjack.com/support/software/api/modbus/modbus-map 40 | Digital I/O: 41 | https://labjack.com/support/datasheets/t-series/digital-io 42 | SPI: 43 | https://labjack.com/support/datasheets/t-series/digital-io/spi 44 | 45 | Note: 46 | Our Python interfaces throw exceptions when there are any issues with 47 | device communications that need addressed. Many of our examples will 48 | terminate immediately when an exception is thrown. The onus is on the API 49 | user to address the cause of any exceptions thrown, and add exception 50 | handling when appropriate. We create our own exception classes that are 51 | derived from the built-in Python Exception class and can be caught as such. 52 | For more information, see the implementation in our source code and the 53 | Python standard documentation. 54 | """ 55 | from random import randrange 56 | 57 | from labjack import ljm 58 | 59 | 60 | # Open first found LabJack 61 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 62 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 63 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 64 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 65 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 66 | 67 | info = ljm.getHandleInfo(handle) 68 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 69 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 70 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 71 | 72 | deviceType = info[0] 73 | 74 | if deviceType == ljm.constants.dtT4: 75 | # Configure FIO4 to FIO7 as digital I/O. 76 | ljm.eWriteName(handle, "DIO_INHIBIT", 0xFFF0F) 77 | ljm.eWriteName(handle, "DIO_ANALOG_ENABLE", 0x00000) 78 | 79 | # Setting CS, CLK, MISO, and MOSI lines for the T4. FIO0 to FIO3 are 80 | # reserved for analog inputs, and SPI requires digital lines. 81 | ljm.eWriteName(handle, "SPI_CS_DIONUM", 5) # CS is FIO5 82 | ljm.eWriteName(handle, "SPI_CLK_DIONUM", 4) # CLK is FIO4 83 | ljm.eWriteName(handle, "SPI_MISO_DIONUM", 7) # MISO is FIO7 84 | ljm.eWriteName(handle, "SPI_MOSI_DIONUM", 6) # MOSI is FIO6 85 | else: 86 | # Setting CS, CLK, MISO, and MOSI lines for the T7 and T8. 87 | ljm.eWriteName(handle, "SPI_CS_DIONUM", 1) # CS is FIO1 88 | ljm.eWriteName(handle, "SPI_CLK_DIONUM", 0) # CLK is FIO0 89 | ljm.eWriteName(handle, "SPI_MISO_DIONUM", 3) # MISO is FIO3 90 | ljm.eWriteName(handle, "SPI_MOSI_DIONUM", 2) # MOSI is FIO2 91 | 92 | # Selecting Mode CPHA=1 (bit 0), CPOL=1 (bit 1) 93 | ljm.eWriteName(handle, "SPI_MODE", 3) 94 | 95 | # Speed Throttle: 96 | # Valid speed throttle values are 1 to 65536 where 0 = 65536. 97 | # Configuring Max. Speed (~800 kHz) = 0 98 | ljm.eWriteName(handle, "SPI_SPEED_THROTTLE", 0) 99 | 100 | # SPI_OPTIONS: 101 | # bit 0: 102 | # 0 = Active low clock select enabled 103 | # 1 = Active low clock select disabled. 104 | # bit 1: 105 | # 0 = DIO directions are automatically changed 106 | # 1 = DIO directions are not automatically changed. 107 | # bits 2-3: Reserved 108 | # bits 4-7: Number of bits in the last byte. 0 = 8. 109 | # bits 8-15: Reserved 110 | 111 | # Enabling active low clock select pin 112 | ljm.eWriteName(handle, "SPI_OPTIONS", 0) 113 | 114 | # Read back and display the SPI settings 115 | aNames = ["SPI_CS_DIONUM", "SPI_CLK_DIONUM", "SPI_MISO_DIONUM", 116 | "SPI_MOSI_DIONUM", "SPI_MODE", "SPI_SPEED_THROTTLE", 117 | "SPI_OPTIONS"] 118 | aValues = [0]*len(aNames) 119 | numFrames = len(aNames) 120 | aValues = ljm.eReadNames(handle, numFrames, aNames) 121 | 122 | print("\nSPI Configuration:") 123 | for i in range(numFrames): 124 | print(" %s = %0.0f" % (aNames[i], aValues[i])) 125 | 126 | # Write(TX)/Read(RX) 4 bytes 127 | numBytes = 4 128 | ljm.eWriteName(handle, "SPI_NUM_BYTES", numBytes) 129 | 130 | # Write the bytes 131 | dataWrite = [] 132 | dataWrite.extend([randrange(0, 256) for _ in range(numBytes)]) 133 | ljm.eWriteNameByteArray(handle, "SPI_DATA_TX", len(dataWrite), dataWrite) 134 | ljm.eWriteName(handle, "SPI_GO", 1) # Do the SPI communications 135 | 136 | # Display the bytes written 137 | print("") 138 | for i in range(numBytes): 139 | print("dataWrite[%i] = %0.0f" % (i, dataWrite[i])) 140 | 141 | # Read the bytes 142 | dataRead = ljm.eReadNameByteArray(handle, "SPI_DATA_RX", numBytes) 143 | 144 | # Display the bytes read 145 | print("") 146 | for i in range(numBytes): 147 | print("dataRead[%i] = %0.0f" % (i, dataRead[i])) 148 | 149 | # Close handle 150 | ljm.close(handle) 151 | -------------------------------------------------------------------------------- /Examples/More/Stream/aperiodic_stream_out.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates usage of the aperiodic stream-out functions. 3 | 4 | Streams out two alternating sine waves on DAC0. Values are generated before the 5 | stream starts in this demonstration, but could be dynamically generated, read 6 | from a file, etc., during the stream run time. 7 | 8 | Relevant Documentation: 9 | 10 | LJM Library: 11 | LJM Library Installer: 12 | https://labjack.com/support/software/installers/ljm 13 | LJM Users Guide: 14 | https://labjack.com/support/software/api/ljm 15 | Opening and Closing: 16 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 17 | LJM Single Value Functions (like eReadName, eReadAddress): 18 | https://labjack.com/support/software/api/ljm/function-reference/single-value-functions 19 | Stream Functions (eStreamStart, eStreamStop, initializeAperiodicStreamOut 20 | and writeAperiodicStreamOut): 21 | https://labjack.com/support/software/api/ljm/function-reference/stream-functions 22 | 23 | T-Series and I/O: 24 | Modbus Map: 25 | https://labjack.com/support/software/api/modbus/modbus-map 26 | Stream Mode: 27 | https://labjack.com/support/datasheets/t-series/communication/stream-mode 28 | Analog Inputs: 29 | https://labjack.com/support/datasheets/t-series/ain 30 | Stream-Out: 31 | https://labjack.com/support/datasheets/t-series/communication/stream-mode/stream-out 32 | Digital I/O: 33 | https://labjack.com/support/datasheets/t-series/digital-io 34 | DAC: 35 | https://labjack.com/support/datasheets/t-series/dac 36 | 37 | Note: 38 | Our Python interfaces throw exceptions when there are any issues with 39 | device communications that need addressed. Many of our examples will 40 | terminate immediately when an exception is thrown. The onus is on the API 41 | user to address the cause of any exceptions thrown, and add exception 42 | handling when appropriate. We create our own exception classes that are 43 | derived from the built-in Python Exception class and can be caught as such. 44 | For more information, see the implementation in our source code and the 45 | Python standard documentation. 46 | """ 47 | import math 48 | import time 49 | 50 | from labjack import ljm 51 | 52 | 53 | def generateSineWave(amp, freq, phase, numSamples, sampleRate, dcOffset): 54 | """ 55 | Generates a sine wave as a list of samples. 56 | 57 | Args: 58 | amp: The amplitude of the sine wave. 59 | freq: The frequency of the sine wave in Hz. 60 | phase: The phase of the sine wave in radians. 61 | numSamples: The number of samples to generate. 62 | sampleRate: The sample rate in Hz. This is the scan rate of 63 | the stream mode. 64 | 65 | Returns: 66 | A list of floats representing the sine wave samples. 67 | 68 | """ 69 | wave = [] 70 | for i in range(numSamples): 71 | time = i / sampleRate 72 | sample = amp * math.sin(2 * math.pi * freq * time + phase) + dcOffset 73 | wave.append(sample) 74 | return wave 75 | 76 | 77 | # Open the first found LabJack. 78 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 79 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 80 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 81 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 82 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 83 | 84 | # Display the currently opened device information. 85 | info = ljm.getHandleInfo(handle) 86 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 87 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 88 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 89 | 90 | # Stream settings 91 | 92 | # Scan rate in Hz. 93 | scanRate = 10000 94 | # Not streaming inputs so scansPerRead is not used. Needs to be a non-zero 95 | # value for stream start. 96 | scansPerRead = 1 97 | # The LJM max. buffer size for the aperiodic stream-out function. 98 | ljmBufferSize = scanRate * 20 99 | # Using stream out index 0 (valid indexes are 0-3). 100 | streamOutIndex = 0 101 | # Stream-out 0 target is DAC0. Note that the register address needs to be used. 102 | streamOutTarget = ljm.nameToAddress("DAC0")[0] 103 | # Scan list will be STREAM_OUT0, whose target is DAC0. Note that the register 104 | # address needs to be used. 105 | scanList = [ljm.nameToAddress("STREAM_OUT%d" % streamOutIndex)[0]] 106 | 107 | # Generate our waveforms. 108 | waveforms = [0]*2 109 | waveforms[0] = generateSineWave(amp=1, freq=500, phase=0, numSamples=1000, sampleRate=scanRate, dcOffset=2) 110 | waveforms[1] = generateSineWave(amp=2, freq=1000, phase=0, numSamples=1000, sampleRate=scanRate, dcOffset=2) 111 | waveformCount = 0 # Keeps track of which waveform to update with. 112 | waveformCountMax = len(waveforms) # The total number of waveforms. 113 | 114 | # Try to stop any previously ran stream. 115 | try: 116 | ljm.eStreamStop(handle) 117 | except: 118 | pass 119 | 120 | # Initialize aperiodic stream out. 121 | ljm.initializeAperiodicStreamOut(handle, streamOutIndex, streamOutTarget, scanRate) 122 | 123 | # Write some data to the buffer before the stream starts. 124 | ljm.writeAperiodicStreamOut(handle, streamOutIndex, len(waveforms[0]), waveforms[0]) 125 | ljm.writeAperiodicStreamOut(handle, streamOutIndex, len(waveforms[1]), waveforms[1]) 126 | 127 | # Configure and start stream mode with stream-out channel. 128 | scanRate = ljm.eStreamStart(handle, scansPerRead, len(scanList), scanList, scanRate) 129 | 130 | # Update the waveform for 20 seconds. 131 | 132 | # How long to run our stream-out in the loop. 133 | runTimeMax = 20 134 | # Loop rate in Hz. When streaming in data also, this is the 135 | # scan rate / scans per read. 136 | loopRate = 10 137 | # Used to determine when to load new stream-out data, in seconds. 138 | # Users may need to adjust. 139 | loadThreshhold = 1.0 / loopRate 140 | # The start time to keep track how long our loop has run for. 141 | startTime = time.time() 142 | # A user set handle for the interval timer. 143 | intervalHandle = 1 144 | # Interval timer to delay loop, in microseconds. Based on loopRate. 145 | ljm.startInterval(intervalHandle, int(1000000 // loopRate)) 146 | 147 | while (time.time() - startTime) < runTimeMax: 148 | # Get the LJM buffer status. No additional data written to stream out buffer. 149 | ljmBufferStatus = ljm.writeAperiodicStreamOut(handle, streamOutIndex, 0, []) 150 | print("\nLJM Buffer Status = %d" % ljmBufferStatus) 151 | 152 | # Number of seconds until LJM buffer is empty. 153 | secondsUntilEmpty = (200000 - ljmBufferStatus) / scanRate 154 | if secondsUntilEmpty < loadThreshhold: 155 | # Add new data to stream out when above threshold. 156 | ljmBufferStatus = ljm.writeAperiodicStreamOut(handle, streamOutIndex, len(waveforms[waveformCount]), waveforms[waveformCount]) 157 | print("Wrote %d samples from waveform %d to stream-out" % (len(waveforms[waveformCount]), waveformCount)) 158 | 159 | # Figure out which waveform to update with next. 160 | waveformCount += 1 161 | if waveformCount >= waveformCountMax: 162 | waveformCount = 0 163 | 164 | # Wait until next loopRate interval. Not needed when reading stream inputs. 165 | skippedIntervals = ljm.waitForNextInterval(intervalHandle) 166 | 167 | # Clean up interval memory. 168 | ljm.cleanInterval(intervalHandle) 169 | 170 | # Stop stream mode. 171 | ljm.eStreamStop(handle) 172 | -------------------------------------------------------------------------------- /Examples/More/Stream/periodic_stream_out.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates usage of the periodic stream-out functions. 3 | 4 | Streams out arbitrary values. These arbitrary values act on DAC0 to cyclically 5 | increase the voltage from 0 to 2.5 V. 6 | 7 | Note: This example requires LJM 1.21 or higher. 8 | 9 | Relevant Documentation: 10 | 11 | LJM Library: 12 | LJM Library Installer: 13 | https://labjack.com/support/software/installers/ljm 14 | LJM Users Guide: 15 | https://labjack.com/support/software/api/ljm 16 | Opening and Closing: 17 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 18 | LJM Single Value Functions (such as eReadName and eReadAddress): 19 | https://labjack.com/support/software/api/ljm/function-reference/single-value-functions 20 | Stream Functions (eStreamRead, eStreamStart, etc.): 21 | https://labjack.com/support/software/api/ljm/function-reference/stream-functions 22 | 23 | T-Series and I/O: 24 | Modbus Map: 25 | https://labjack.com/support/software/api/modbus/modbus-map 26 | Stream Mode: 27 | https://labjack.com/support/datasheets/t-series/communication/stream-mode 28 | Stream-Out: 29 | https://labjack.com/support/datasheets/t-series/communication/stream-mode/stream-out 30 | Digital I/O: 31 | https://labjack.com/support/datasheets/t-series/digital-io 32 | DAC: 33 | https://labjack.com/support/datasheets/t-series/dac 34 | 35 | Note: 36 | Our Python interfaces throw exceptions when there are any issues with 37 | device communications that need addressed. Many of our examples will 38 | terminate immediately when an exception is thrown. The onus is on the API 39 | user to address the cause of any exceptions thrown, and add exception 40 | handling when appropriate. We create our own exception classes that are 41 | derived from the built-in Python Exception class and can be caught as such. 42 | For more information, see the implementation in our source code and the 43 | Python standard documentation. 44 | """ 45 | import sys 46 | from time import sleep 47 | 48 | from labjack import ljm 49 | 50 | 51 | def main(): 52 | # Open first found LabJack 53 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 54 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 55 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 56 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 57 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 58 | 59 | info = ljm.getHandleInfo(handle) 60 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 61 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 62 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 63 | 64 | scanRate = 1000 # Scans per second 65 | scansPerRead = int(scanRate / 2) 66 | runTimeS = 5.0 # Number of seconds to stream out waveforms 67 | 68 | # The desired stream channels. Up to 4 out-streams can be ran at once. 69 | scanListNames = ["STREAM_OUT0"] # Scan list names to stream. 70 | scanList = ljm.namesToAddresses(len(scanListNames), scanListNames)[0] 71 | 72 | targetAddr = 1000 # Stream out to DAC0. 73 | 74 | # Stream out index can be a value of 0 to 3. 75 | streamOutIndex = 0 76 | 77 | # Make an arbitrary waveform that increases voltage linearly from 78 | # 0 to 2.5 V. 79 | samplesToWrite = 512 80 | writeData = [] 81 | for i in range(samplesToWrite): 82 | sample = 2.5*i/samplesToWrite 83 | writeData.append(sample) 84 | 85 | try : 86 | print("\nInitializing stream out...\n") 87 | ljm.periodicStreamOut(handle, streamOutIndex, targetAddr, scanRate, len(writeData), writeData) 88 | print("Beginning stream out...\n") 89 | actualScanRate = ljm.eStreamStart(handle, scansPerRead, len(scanList), scanList, scanRate) 90 | print("Stream started with scan rate of %f Hz." % actualScanRate) 91 | print(" Running for %d seconds.\n" % runTimeS) 92 | sleep(runTimeS) 93 | except ljm.LJMError: 94 | ljme = sys.exc_info()[1] 95 | print(ljme) 96 | except Exception: 97 | e = sys.exc_info()[1] 98 | print(e) 99 | 100 | try: 101 | print("Stopping Stream...") 102 | ljm.eStreamStop(handle) 103 | except ljm.LJMError: 104 | ljme = sys.exc_info()[1] 105 | print(ljme) 106 | except Exception: 107 | e = sys.exc_info()[1] 108 | print(e) 109 | 110 | 111 | if __name__ == "__main__": 112 | main() 113 | -------------------------------------------------------------------------------- /Examples/More/Stream/stream_basic.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to stream using the eStream functions. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | Constants: 14 | https://labjack.com/support/software/api/ljm/constants 15 | NamesToAddresses: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnamestoaddresses 17 | eWriteName: 18 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 19 | eWriteNames: 20 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 21 | Stream Functions (such as eStreamStart, eStreamRead and eStreamStop): 22 | https://labjack.com/support/software/api/ljm/function-reference/stream-functions 23 | 24 | T-Series and I/O: 25 | Modbus Map: 26 | https://labjack.com/support/software/api/modbus/modbus-map 27 | Stream Mode: 28 | https://labjack.com/support/datasheets/t-series/communication/stream-mode 29 | Analog Inputs: 30 | https://labjack.com/support/datasheets/t-series/ain 31 | 32 | Note: 33 | Our Python interfaces throw exceptions when there are any issues with 34 | device communications that need addressed. Many of our examples will 35 | terminate immediately when an exception is thrown. The onus is on the API 36 | user to address the cause of any exceptions thrown, and add exception 37 | handling when appropriate. We create our own exception classes that are 38 | derived from the built-in Python Exception class and can be caught as such. 39 | For more information, see the implementation in our source code and the 40 | Python standard documentation. 41 | """ 42 | from datetime import datetime 43 | import sys 44 | 45 | from labjack import ljm 46 | 47 | 48 | MAX_REQUESTS = 10 # The number of eStreamRead calls that will be performed. 49 | 50 | # Open first found LabJack 51 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 52 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 53 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 54 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 55 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 56 | 57 | info = ljm.getHandleInfo(handle) 58 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 59 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 60 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 61 | 62 | deviceType = info[0] 63 | 64 | # Stream Configuration 65 | aScanListNames = ["AIN0", "AIN1"] # Scan list names to stream 66 | numAddresses = len(aScanListNames) 67 | aScanList = ljm.namesToAddresses(numAddresses, aScanListNames)[0] 68 | scanRate = 1000 69 | scansPerRead = int(scanRate / 2) 70 | 71 | try: 72 | # When streaming, negative channels and ranges can be configured for 73 | # individual analog inputs, but the stream has only one settling time and 74 | # resolution. 75 | 76 | if deviceType == ljm.constants.dtT4: 77 | # LabJack T4 configuration 78 | 79 | # Stream settling is 0 (default) and 80 | # stream resolution index is 0 (default). 81 | aNames = ["STREAM_SETTLING_US", "STREAM_RESOLUTION_INDEX"] 82 | aValues = [0, 0] 83 | else: 84 | # LabJack T7 and T8 configuration 85 | 86 | # Ensure triggered stream is disabled. 87 | ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 0) 88 | # Enabling internally-clocked stream. 89 | ljm.eWriteName(handle, "STREAM_CLOCK_SOURCE", 0) 90 | 91 | # AIN0 and AIN1 ranges are +/-10 V (T7) or +/-11 V (T8). 92 | # Stream resolution index is 0 (default). 93 | aNames = ["AIN0_RANGE", "AIN1_RANGE", "STREAM_RESOLUTION_INDEX"] 94 | aValues = [10.0, 10.0, 0] 95 | 96 | # Negative channel and settling configurations do not apply to the T8. 97 | if deviceType == ljm.constants.dtT7: 98 | # Negative Channel = 199 (Single-ended) 99 | # Settling = 0 (auto) 100 | aNames.extend(["AIN0_NEGATIVE_CH", "STREAM_SETTLING_US", 101 | "AIN1_NEGATIVE_CH"]) 102 | aValues.extend([199, 0, 199]) 103 | 104 | # Write the analog inputs' negative channels (when applicable), ranges, 105 | # stream settling time and stream resolution configuration. 106 | numFrames = len(aNames) 107 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 108 | 109 | # Configure and start stream 110 | scanRate = ljm.eStreamStart(handle, scansPerRead, numAddresses, aScanList, scanRate) 111 | print("\nStream started with a scan rate of %0.0f Hz." % scanRate) 112 | 113 | print("\nPerforming %i stream reads." % MAX_REQUESTS) 114 | start = datetime.now() 115 | totScans = 0 116 | totSkip = 0 # Total skipped samples 117 | 118 | i = 1 119 | while i <= MAX_REQUESTS: 120 | ret = ljm.eStreamRead(handle) 121 | 122 | aData = ret[0] 123 | scans = len(aData) / numAddresses 124 | totScans += scans 125 | 126 | # Count the skipped samples which are indicated by -9999 values. Missed 127 | # samples occur after a device's stream buffer overflows and are 128 | # reported after auto-recover mode ends. 129 | curSkip = aData.count(-9999.0) 130 | totSkip += curSkip 131 | 132 | print("\neStreamRead %i" % i) 133 | ainStr = "" 134 | for j in range(0, numAddresses): 135 | ainStr += "%s = %0.5f, " % (aScanListNames[j], aData[j]) 136 | print(" 1st scan out of %i: %s" % (scans, ainStr)) 137 | print(" Scans Skipped = %0.0f, Scan Backlogs: Device = %i, LJM = " 138 | "%i" % (curSkip/numAddresses, ret[1], ret[2])) 139 | i += 1 140 | 141 | end = datetime.now() 142 | 143 | print("\nTotal scans = %i" % (totScans)) 144 | tt = (end - start).seconds + float((end - start).microseconds) / 1000000 145 | print("Time taken = %f seconds" % (tt)) 146 | print("LJM Scan Rate = %f scans/second" % (scanRate)) 147 | print("Timed Scan Rate = %f scans/second" % (totScans / tt)) 148 | print("Timed Sample Rate = %f samples/second" % (totScans * numAddresses / tt)) 149 | print("Skipped scans = %0.0f" % (totSkip / numAddresses)) 150 | except ljm.LJMError: 151 | ljme = sys.exc_info()[1] 152 | print(ljme) 153 | except Exception: 154 | e = sys.exc_info()[1] 155 | print(e) 156 | 157 | try: 158 | print("\nStop Stream") 159 | ljm.eStreamStop(handle) 160 | except ljm.LJMError: 161 | ljme = sys.exc_info()[1] 162 | print(ljme) 163 | except Exception: 164 | e = sys.exc_info()[1] 165 | print(e) 166 | 167 | # Close handle 168 | ljm.close(handle) 169 | -------------------------------------------------------------------------------- /Examples/More/Stream/stream_burst.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to use the streamBurst function for streaming. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | NamesToAddresses: 14 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnamestoaddresses 15 | eWriteName: 16 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 17 | eWriteNames: 18 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 19 | StreamBurst: 20 | https://labjack.com/support/software/api/ljm/function-reference/ljmstreamburst 21 | 22 | T-Series and I/O: 23 | Modbus Map: 24 | https://labjack.com/support/software/api/modbus/modbus-map 25 | Stream Mode: 26 | https://labjack.com/support/datasheets/t-series/communication/stream-mode 27 | Special Stream Modes (such as burst): 28 | https://support.labjack.com/docs/3-2-2-special-stream-modes-t-series-datasheet 29 | Analog Inputs: 30 | https://labjack.com/support/datasheets/t-series/ain 31 | 32 | Note: 33 | Our Python interfaces throw exceptions when there are any issues with 34 | device communications that need addressed. Many of our examples will 35 | terminate immediately when an exception is thrown. The onus is on the API 36 | user to address the cause of any exceptions thrown, and add exception 37 | handling when appropriate. We create our own exception classes that are 38 | derived from the built-in Python Exception class and can be caught as such. 39 | For more information, see the implementation in our source code and the 40 | Python standard documentation. 41 | """ 42 | from datetime import datetime 43 | import sys 44 | 45 | from labjack import ljm 46 | 47 | 48 | # Open first found LabJack 49 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 50 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 51 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 52 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 53 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 54 | 55 | info = ljm.getHandleInfo(handle) 56 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 57 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 58 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 59 | 60 | deviceType = info[0] 61 | 62 | # Stream Configuration 63 | aScanListNames = ["AIN0", "AIN1"] # Scan list names to stream 64 | numAddresses = len(aScanListNames) 65 | aScanList = ljm.namesToAddresses(numAddresses, aScanListNames)[0] # Scan list addresses for streamBurst 66 | scanRate = 1000 # Scans per second 67 | numScans = 2000 # Number of scans to perform 68 | 69 | try: 70 | # When streaming, negative channels and ranges can be configured for 71 | # individual analog inputs, but the stream has only one settling time and 72 | # resolution. 73 | 74 | if deviceType == ljm.constants.dtT4: 75 | # LabJack T4 configuration 76 | 77 | # Stream settling is 0 (default) and 78 | # stream resolution index is 0 (default). 79 | aNames = ["STREAM_SETTLING_US", "STREAM_RESOLUTION_INDEX"] 80 | aValues = [0, 0] 81 | else: 82 | # LabJack T7 and T8 configuration 83 | 84 | # Ensure triggered stream is disabled. 85 | ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 0) 86 | # Enabling internally-clocked stream. 87 | ljm.eWriteName(handle, "STREAM_CLOCK_SOURCE", 0) 88 | 89 | # AIN0 and AIN1 ranges are +/-10 V (T7) or +/-11 V (T8). 90 | # Stream resolution index is 0 (default). 91 | aNames = ["AIN0_RANGE", "AIN1_RANGE", "STREAM_RESOLUTION_INDEX"] 92 | aValues = [10.0, 10.0, 0] 93 | 94 | # Negative channel and settling configurations do not apply to the T8. 95 | if deviceType == ljm.constants.dtT7: 96 | # Negative Channel = 199 (Single-ended) 97 | # Settling = 0 (auto) 98 | aNames.extend(["AIN0_NEGATIVE_CH", "STREAM_SETTLING_US", 99 | "AIN1_NEGATIVE_CH"]) 100 | aValues.extend([199, 0, 199]) 101 | 102 | # Write the analog inputs' negative channels (when applicable), ranges, 103 | # stream settling time and stream resolution configuration. 104 | numFrames = len(aNames) 105 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 106 | 107 | print("\nScan list:") 108 | for chan in aScanListNames: 109 | print(" %s" % chan) 110 | print("Scan rate = %s Hz" % scanRate) 111 | print("Sample rate = %s Hz" % (scanRate * numAddresses)) 112 | print("Total number of scans: %s" % numScans) 113 | print("Total number of samples: %s" % (numScans * numAddresses)) 114 | print("Seconds of samples = %s" % (numScans / scanRate)) 115 | 116 | print("\nStreaming with streamBurst ...") 117 | start = datetime.now() 118 | scanRate, aData = ljm.streamBurst(handle, numAddresses, aScanList, scanRate, numScans) 119 | end = datetime.now() 120 | print("Done") 121 | 122 | skipped = aData.count(-9999.0) 123 | print("\nSkipped scans = %0.0f" % (skipped / numAddresses)) 124 | tt = (end - start).seconds + float((end - start).microseconds) / 1000000 125 | print("Time taken = %f seconds" % (tt)) 126 | 127 | ainStr1 = "" 128 | ainStr2 = "" 129 | lastScanIndex = len(aData) - numAddresses 130 | for j in range(0, numAddresses): 131 | ainStr1 += "%s = %0.5f, " % (aScanListNames[j], aData[j]) 132 | ainStr2 += "%s = %0.5f, " % (aScanListNames[j], aData[lastScanIndex + j]) 133 | print("\nFirst scan: %s" % ainStr1) 134 | print("Last scan: %s" % ainStr2) 135 | except ljm.LJMError: 136 | ljme = sys.exc_info()[1] 137 | print(ljme) 138 | except Exception: 139 | e = sys.exc_info()[1] 140 | print(e) 141 | 142 | # Close handle 143 | ljm.close(handle) 144 | -------------------------------------------------------------------------------- /Examples/More/Testing/auto_reconnect_test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests the LJM auto reconnect functionality. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | WriteLibraryConfigS: 14 | https://labjack.com/support/software/api/ljm/function-reference/LJMWriteLibraryConfigS 15 | RegisterDeviceReconnectCallback: 16 | https://labjack.com/support/software/api/ljm/function-reference/LJMRegisterDeviceReconnectCallback 17 | eReadName: 18 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 19 | 20 | T-Series and I/O: 21 | Modbus Map: 22 | https://labjack.com/support/software/api/modbus/modbus-map 23 | Hardware Overview (Device Information Registers): 24 | https://labjack.com/support/datasheets/t-series/hardware-overview 25 | 26 | Note: 27 | Our Python interfaces throw exceptions when there are any issues with 28 | device communications that need addressed. Many of our examples will 29 | terminate immediately when an exception is thrown. The onus is on the API 30 | user to address the cause of any exceptions thrown, and add exception 31 | handling when appropriate. We create our own exception classes that are 32 | derived from the built-in Python Exception class and can be caught as such. 33 | For more information, see the implementation in our source code and the 34 | Python standard documentation. 35 | """ 36 | import sys 37 | import threading 38 | import time 39 | 40 | from labjack import ljm 41 | 42 | 43 | try: 44 | input = raw_input # Set input to raw_input for Python 2.x 45 | except: 46 | pass 47 | 48 | def myReconnectCallback(handle): 49 | print("Reconnected handle: %s" % handle) 50 | 51 | 52 | # Set the timeouts shorter for testing convenience 53 | ljm.writeLibraryConfigS(ljm.constants.OPEN_TCP_DEVICE_TIMEOUT_MS, 500) 54 | ljm.writeLibraryConfigS(ljm.constants.SEND_RECEIVE_TIMEOUT_MS, 500) 55 | 56 | # Open first found LabJack 57 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 58 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 59 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 60 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 61 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 62 | 63 | ljm.registerDeviceReconnectCallback(handle, myReconnectCallback) 64 | 65 | print("\nPress Ctrl+C to exit.") 66 | i = 0 67 | while True: 68 | try: 69 | try: 70 | i = i + 1 71 | print("\nIteration: %d" % i) 72 | 73 | # Read the serial number from the device 74 | name = "SERIAL_NUMBER" 75 | value = ljm.eReadName(handle, name) 76 | print(" Read %s: %.0f" % (name, value)) 77 | 78 | # Above read succeeded. Displaying device information. 79 | info = ljm.getHandleInfo(handle) 80 | print(" Handle: %i, Device type: %i, Connection type: %i, Serial number: %i,\n" 81 | " IP address: %s, Port: %i, Max bytes per MB: %i" % 82 | (handle, info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 83 | except ljm.LJMError: 84 | ljme = sys.exc_info()[1] 85 | print(" " + str(ljme)) 86 | 87 | print(" Unplug, replug, wait") 88 | input(" Press Enter to continue\n") 89 | except KeyboardInterrupt: 90 | break 91 | except: 92 | print(sys.exc_info()[1]) 93 | break 94 | 95 | # Close handle 96 | ljm.close(handle) 97 | -------------------------------------------------------------------------------- /Examples/More/Utilities/thermocouple_example_ain_ef.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates thermocouple configuration and measurement using the thermocouple 3 | AIN_EF (T7/T8 only). 4 | 5 | Relevant Documentation: 6 | 7 | Thermocouple App-Note: 8 | https://labjack.com/support/app-notes/thermocouples 9 | 10 | LJM Library: 11 | LJM Library Installer: 12 | https://labjack.com/support/software/installers/ljm 13 | LJM Users Guide: 14 | https://labjack.com/support/software/api/ljm 15 | Opening and Closing: 16 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 17 | Single Value Functions (such as eWriteName and eReadName): 18 | https://labjack.com/support/software/api/ljm/function-reference/single-value-functions 19 | Multiple Value Functions (such as eReadNames): 20 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 21 | Timing Functions (such as StartInterval, WaitForNextInterval and 22 | CleanInterval): 23 | https://labjack.com/support/software/api/ljm/function-reference/timing-functions 24 | 25 | T-Series and I/O: 26 | Modbus Map: 27 | https://labjack.com/support/software/api/modbus/modbus-map 28 | Analog Inputs: 29 | https://labjack.com/support/datasheets/t-series/ain 30 | Thermocouple AIN_EF (T7/T8 only): 31 | https://labjack.com/support/datasheets/t-series/ain/extended-features/thermocouple 32 | """ 33 | import sys 34 | 35 | from labjack import ljm 36 | 37 | 38 | if __name__ == "__main__": 39 | # Open first found LabJack 40 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 41 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 42 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 43 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 44 | 45 | info = ljm.getHandleInfo(handle) 46 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 47 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 48 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 49 | deviceType = info[0] 50 | 51 | # Read 10 times 52 | numIterations = 10 53 | 54 | # Take a measurement of a thermocouple connected to AIN0 55 | channel = 0 56 | channelName = "AIN%i" % channel 57 | 58 | # Thermocouple AIN_EF indices: 59 | # 20=type E 60 | # 21=type J 61 | # 22=type K 62 | # 23=type R 63 | # 24=type T 64 | # 25=type S 65 | # 27=type N 66 | # 28=type B 67 | # 30=type C 68 | tcIndex = 22 69 | 70 | # Temperature reading units (0=K, 1=C, 2=F) 71 | tempUnitIndex = 0 72 | tempUnit = {0: "K", 1: "C", 2: "F"}[tempUnitIndex] 73 | 74 | # The CJC configurations should be set up such that: 75 | # tempK = reading * cjcSlope + cjcOffset 76 | # Where 'tempK' is the CJC reading in Kelvin and 'reading' is the value 77 | # read from the register at cjcAddress. 78 | if deviceType == ljm.constants.dtT8: 79 | # Use TEMPERATURE# for the T8 for CJC. Since the thermocouple is 80 | # connected to AIN0, we are using TEMPERATURE0 for the CJC. 81 | cjcAddress = 600 + 2*channel 82 | else: 83 | # Use TEMPERATURE_DEVICE_K for the T7 for CJC 84 | cjcAddress = 60052 85 | 86 | # CJC slope when using TEMPERATURE_DEVICE_K 87 | cjcSlope = 1.0 88 | 89 | # CJC offset when using TEMPERATURE_DEVICE_K 90 | cjcOffset = 0.0 91 | 92 | # Set the resolution index to the default setting. 93 | # Default setting has different meanings depending on the device. 94 | # See our AIN documentation (linked above) for more information. 95 | resIndexRegister = "%s_RESOLUTION_INDEX" % channelName 96 | ljm.eWriteName(handle, resIndexRegister, 0) 97 | 98 | # Set up any negative channel configurations required. The T8 inputs are 99 | # isolated and therefore do not require any negative channel configuration. 100 | if deviceType == ljm.constants.dtT7: 101 | # There are only certain valid differential channel pairs. For AIN0-13 102 | # the valid pairs are an even numbered AIN and next odd AIN. For 103 | # example, AIN0-AIN1, AIN2-AIN3. To take a differential reading between 104 | # AIN0 and AIN1, set AIN0_NEGATIVE_CH to 1. 105 | 106 | # Set up a single ended measurement 107 | negChannelValue = ljm.constants.GND 108 | negChannelRegister = "%s_NEGATIVE_CH" % channelName 109 | ljm.eWriteName(handle, negChannelRegister, negChannelValue) 110 | elif deviceType == ljm.constants.dtT4: 111 | print("\nThe T4 does not support the thermocouple AIN_EF. See our InAmp thermocouple example.") 112 | exit(0) 113 | 114 | # Configure all of the necessary thermocouple AIN_EF registers 115 | aNames = [] 116 | aValues = [] 117 | 118 | # For setting up the AIN#_EF_INDEX (thermocouple type) 119 | indexRegister = "%s_EF_INDEX" % channelName 120 | aNames.append(indexRegister) 121 | aValues.append(tcIndex) 122 | 123 | # For setting up the AIN#_EF_CONFIG_A (temperature units) 124 | configA = "%s_EF_CONFIG_A" % channelName 125 | aNames.append(configA) 126 | aValues.append(tempUnitIndex) 127 | 128 | # For setting up the AIN#_EF_CONFIG_B (CJC address) 129 | configB = "%s_EF_CONFIG_B" % channelName 130 | aNames.append(configB) 131 | aValues.append(cjcAddress) 132 | 133 | # For setting up the AIN#_EF_CONFIG_D (CJC slope) 134 | configD = "%s_EF_CONFIG_D" % channelName 135 | aNames.append(configD) 136 | aValues.append(cjcSlope) 137 | 138 | # For setting up the AIN#_EF_CONFIG_E (CJC offset) 139 | configE = "%s_EF_CONFIG_E" % channelName 140 | aNames.append(configE) 141 | aValues.append(cjcOffset) 142 | 143 | # Write all of the AIN_EF settings 144 | ljm.eWriteNames(handle, len(aNames), aNames, aValues) 145 | 146 | print("\nReading thermocouple temperature %d times...\n" % numIterations) 147 | intervalHandle = 1 148 | 149 | # AIN#_EF_READ_A returns the thermocouple temperature reading 150 | readA = "%s_EF_READ_A" % channelName 151 | 152 | # AIN#_EF_READ_B returns the thermocouple voltage reading 153 | readB = "%s_EF_READ_B" % channelName 154 | 155 | # AIN#_EF_READ_C returns the thermocouple CJC temperature reading 156 | readC = "%s_EF_READ_C" % channelName 157 | 158 | # Delay between readings (in microseconds) 159 | ljm.startInterval(intervalHandle, 1000000) 160 | 161 | for i in range(numIterations): 162 | try: 163 | # Read the thermocouple temperature 164 | [tcTemp, tcVolts, cjTemp] = ljm.eReadNames(handle, 3, [readA, readB, readC]) 165 | 166 | # Print the temperature read 167 | print("TCTemp = %0.3f %s, TCVolts = %0.6f V, CJTemp = %0.3f %s\n" % 168 | (tcTemp, tempUnit, tcVolts, cjTemp, tempUnit)) 169 | 170 | ljm.waitForNextInterval(intervalHandle) 171 | except Exception: 172 | print(sys.exc_info()[1]) 173 | break 174 | 175 | # Close handles 176 | ljm.cleanInterval(intervalHandle) 177 | ljm.close(handle) 178 | print("Done!") 179 | -------------------------------------------------------------------------------- /Examples/More/Utilities/thermocouple_example_inamp.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates thermocouple configuration and measurement using our LJTick-InAmp 3 | (commonly used with the T4). 4 | 5 | Relevant Documentation: 6 | 7 | Thermocouple App-Note: 8 | https://labjack.com/support/app-notes/thermocouples 9 | 10 | LJM Library: 11 | LJM Library Installer: 12 | https://labjack.com/support/software/installers/ljm 13 | LJM Users Guide: 14 | https://labjack.com/support/software/api/ljm 15 | Opening and Closing: 16 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 17 | Single Value Functions (such as eWriteName): 18 | https://labjack.com/support/software/api/ljm/function-reference/single-value-functions 19 | Multiple Value Functions (such as eReadNames): 20 | https://labjack.com/support/software/api/ljm/function-reference/multiple-value-functions 21 | TCVoltsToTemp: 22 | https://labjack.com/support/software/api/ud/function-reference/tcvoltstotemp 23 | Timing Functions (such as StartInterval, WaitForNextInterval and 24 | CleanInterval): 25 | https://labjack.com/support/software/api/ljm/function-reference/timing-functions 26 | 27 | T-Series and I/O: 28 | Modbus Map: 29 | https://labjack.com/support/software/api/modbus/modbus-map 30 | Analog Inputs: 31 | https://labjack.com/support/datasheets/t-series/ain 32 | """ 33 | import sys 34 | 35 | from labjack import ljm 36 | 37 | 38 | if __name__ == "__main__": 39 | # Open first found LabJack 40 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 41 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 42 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 43 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 44 | 45 | info = ljm.getHandleInfo(handle) 46 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 47 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 48 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 49 | deviceType = info[0] 50 | 51 | # Read 10 times 52 | numIterations = 10 53 | 54 | # Take a measurement of a thermocouple connected to AIN0 55 | # That would be INA of an InAmp connected to the VS/GND/AIN0/AIN1 terminals 56 | channelName = "AIN0" 57 | 58 | # Gain setting on the InAmp 59 | gain = 201 60 | 61 | # Offset setting (V) on the InAmp 62 | offset = 1.25 63 | tcType = ljm.constants.ttK # Type K thermocouple 64 | #tcType = ljm.constants.ttB # Type B thermocouple 65 | #tcType = ljm.constants.ttE # Type E thermocouple 66 | #tcType = ljm.constants.ttJ # Type J thermocouple 67 | #tcType = ljm.constants.ttN # Type N thermocouple 68 | #tcType = ljm.constants.ttR # Type R thermocouple 69 | #tcType = ljm.constants.ttS # Type S thermocouple 70 | #tcType = ljm.constants.ttT # Type T thermocouple 71 | #tcType = ljm.constants.ttC # Type C thermocouple 72 | 73 | # Set the resolution index to the default setting. 74 | # Default setting has different meanings depending on the device. 75 | # See our AIN documentation (linked above) for more information. 76 | resIndexRegister = "%s_RESOLUTION_INDEX" % channelName 77 | ljm.eWriteName(handle, resIndexRegister, 0) 78 | 79 | # This section is for range and negative channel settings. The T4 does not 80 | # support these configurations. 81 | if deviceType == ljm.constants.dtT7: 82 | # ±10 V range setting 83 | rangeRegister = "%s_RANGE" % channelName 84 | ljm.eWriteName(handle, rangeRegister, 10) 85 | 86 | # Set up a single ended measurement 87 | negChannelValue = ljm.constants.GND 88 | negChannelRegister = "%s_NEGATIVE_CH" % channelName 89 | ljm.eWriteName(handle, negChannelRegister, negChannelValue) 90 | elif deviceType == ljm.constants.dtT8: 91 | print("\nThe T8 is not compatible with the InAmp. See our AIN_EF example.") 92 | exit(0) 93 | 94 | print("\nReading thermocouple temperature %d times...\n" % numIterations) 95 | intervalHandle = 1 96 | # Delay between readings (in microseconds) 97 | ljm.startInterval(intervalHandle, 1000000) 98 | 99 | for i in range(numIterations): 100 | try: 101 | # Read the InAmp output voltage and internal temp sensor at once. 102 | aNames = [channelName, "TEMPERATURE_DEVICE_K"] 103 | [voltage, cjTempK] = ljm.eReadNames(handle, len(aNames), aNames) 104 | 105 | # Convert the InAmp output to the raw thermocouple voltage. 106 | tcVolts = (voltage - offset) / gain 107 | 108 | # Convert voltage to thermocouple temperature (K). 109 | tcTempK = ljm.tcVoltsToTemp(tcType, tcVolts, cjTempK) 110 | 111 | # Print the temperature read 112 | print("TCTemp = %0.3f K, TCVolts = %0.6f V, CJTemp = %0.3f K\n" % 113 | (tcTempK, tcVolts, cjTempK)) 114 | 115 | ljm.waitForNextInterval(intervalHandle) 116 | except Exception: 117 | print(sys.exc_info()[1]) 118 | break 119 | 120 | # Close handles 121 | ljm.cleanInterval(intervalHandle) 122 | ljm.close(handle) 123 | print("Done!") 124 | -------------------------------------------------------------------------------- /Examples/More/Watchdog/read_watchdog_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the Watchdog configuration from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnames 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Watchdog: 20 | https://labjack.com/support/datasheets/t-series/watchdog 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Setup and call eReadNames to read the Watchdog configuration from the LabJack. 48 | aNames = ["WATCHDOG_ENABLE_DEFAULT", "WATCHDOG_ADVANCED_DEFAULT", 49 | "WATCHDOG_TIMEOUT_S_DEFAULT", "WATCHDOG_STARTUP_DELAY_S_DEFAULT", 50 | "WATCHDOG_STRICT_ENABLE_DEFAULT", "WATCHDOG_STRICT_KEY_DEFAULT", 51 | "WATCHDOG_RESET_ENABLE_DEFAULT", "WATCHDOG_DIO_ENABLE_DEFAULT", 52 | "WATCHDOG_DIO_STATE_DEFAULT", "WATCHDOG_DIO_DIRECTION_DEFAULT", 53 | "WATCHDOG_DIO_INHIBIT_DEFAULT", "WATCHDOG_DAC0_ENABLE_DEFAULT", 54 | "WATCHDOG_DAC0_DEFAULT", "WATCHDOG_DAC1_ENABLE_DEFAULT", 55 | "WATCHDOG_DAC1_DEFAULT"] 56 | numFrames = len(aNames) 57 | results = ljm.eReadNames(handle, numFrames, aNames) 58 | 59 | print("\nWatchdog configuration:") 60 | for i in range(numFrames): 61 | print(" %s : %f" % (aNames[i], results[i])) 62 | 63 | # Close handle 64 | ljm.close(handle) 65 | -------------------------------------------------------------------------------- /Examples/More/Watchdog/write_watchdog_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to configure the Watchdog on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | Watchdog: 20 | https://labjack.com/support/datasheets/t-series/watchdog 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | from labjack import ljm 33 | 34 | 35 | # Open first found LabJack 36 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 37 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 38 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 39 | #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier 40 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 41 | 42 | info = ljm.getHandleInfo(handle) 43 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 44 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 45 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 46 | 47 | # Setup and call eWriteNames to configure the Watchdog on a LabJack. 48 | # Disable the Watchdog first before any other configuration. 49 | aNames = ["WATCHDOG_ENABLE_DEFAULT", "WATCHDOG_ADVANCED_DEFAULT", 50 | "WATCHDOG_TIMEOUT_S_DEFAULT", "WATCHDOG_STARTUP_DELAY_S_DEFAULT", 51 | "WATCHDOG_STRICT_ENABLE_DEFAULT", "WATCHDOG_STRICT_KEY_DEFAULT", 52 | "WATCHDOG_RESET_ENABLE_DEFAULT", "WATCHDOG_DIO_ENABLE_DEFAULT", 53 | "WATCHDOG_DIO_STATE_DEFAULT", "WATCHDOG_DIO_DIRECTION_DEFAULT", 54 | "WATCHDOG_DIO_INHIBIT_DEFAULT", "WATCHDOG_DAC0_ENABLE_DEFAULT", 55 | "WATCHDOG_DAC0_DEFAULT", "WATCHDOG_DAC1_ENABLE_DEFAULT", 56 | "WATCHDOG_DAC1_DEFAULT", "WATCHDOG_ENABLE_DEFAULT"] 57 | aValues = [0, 0, 58 | 20, 0, # Timeout set to 20 seconds 59 | 0, 0, 60 | 1, 0, # Reset the device on timeout 61 | 0, 0, 62 | 0, 0, 63 | 0, 0, 64 | 0, 0] # Change the last WATCHDOG_ENABLE_DEFAULT to 1 to enable 65 | numFrames = len(aNames) 66 | ljm.eWriteNames(handle, numFrames, aNames, aValues) 67 | 68 | print("\nSet Watchdog configuration:") 69 | for i in range(numFrames): 70 | print(" %s : %f" % (aNames[i], aValues[i])) 71 | 72 | # Close handle 73 | ljm.close(handle) 74 | -------------------------------------------------------------------------------- /Examples/More/WiFi/read_wifi_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the WiFi configuration from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadNames: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnames 15 | NumberToIP: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertoip 17 | eReadNameString: 18 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadnamestring 19 | 20 | T-Series and I/O: 21 | Modbus Map: 22 | https://labjack.com/support/software/api/modbus/modbus-map 23 | WiFi: 24 | https://labjack.com/support/datasheets/t-series/wifi 25 | 26 | Note: 27 | Our Python interfaces throw exceptions when there are any issues with 28 | device communications that need addressed. Many of our examples will 29 | terminate immediately when an exception is thrown. The onus is on the API 30 | user to address the cause of any exceptions thrown, and add exception 31 | handling when appropriate. We create our own exception classes that are 32 | derived from the built-in Python Exception class and can be caught as such. 33 | For more information, see the implementation in our source code and the 34 | Python standard documentation. 35 | """ 36 | import sys 37 | 38 | from labjack import ljm 39 | 40 | 41 | # Open first found LabJack 42 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 43 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 44 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 45 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 46 | 47 | info = ljm.getHandleInfo(handle) 48 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 49 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 50 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 51 | 52 | if info[0] == ljm.constants.dtT4: 53 | print("\nThe LabJack T4 does not support WiFi.") 54 | sys.exit() 55 | 56 | # Setup and call eReadNames to read WiFi configuration from the LabJack. 57 | names = ["WIFI_IP", "WIFI_SUBNET", "WIFI_GATEWAY", "WIFI_DHCP_ENABLE", 58 | "WIFI_IP_DEFAULT", "WIFI_SUBNET_DEFAULT", "WIFI_GATEWAY_DEFAULT", 59 | "WIFI_DHCP_ENABLE_DEFAULT", "WIFI_STATUS"] 60 | numFrames = len(names) 61 | results = ljm.eReadNames(handle, numFrames, names) 62 | print("\nWiFi configuration: ") 63 | for i in range(numFrames): 64 | if names[i] == "WIFI_STATUS" or names[i].startswith("WIFI_DHCP_ENABLE"): 65 | print(" %s : %.0f" % (names[i], results[i])) 66 | else: 67 | print(" %s : %.0f - %s" % 68 | (names[i], results[i], ljm.numberToIP(int(results[i])))) 69 | 70 | # Setup and call eReadNameString to read the WiFi SSID string from the LabJack. 71 | name = "WIFI_SSID" 72 | result = ljm.eReadNameString(handle, name) 73 | print(" %s : %s" % (name, result)) 74 | 75 | # Close handle 76 | ljm.close(handle) 77 | -------------------------------------------------------------------------------- /Examples/More/WiFi/read_wifi_mac.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the WiFi MAC from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadAddressByteArray: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadaddressbytearray 15 | NumberToMAC: 16 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertomac 17 | 18 | T-Series and I/O: 19 | Modbus Map: 20 | https://labjack.com/support/software/api/modbus/modbus-map 21 | WiFi: 22 | https://labjack.com/support/datasheets/t-series/wifi 23 | 24 | Note: 25 | Our Python interfaces throw exceptions when there are any issues with 26 | device communications that need addressed. Many of our examples will 27 | terminate immediately when an exception is thrown. The onus is on the API 28 | user to address the cause of any exceptions thrown, and add exception 29 | handling when appropriate. We create our own exception classes that are 30 | derived from the built-in Python Exception class and can be caught as such. 31 | For more information, see the implementation in our source code and the 32 | Python standard documentation. 33 | """ 34 | import struct 35 | import sys 36 | 37 | from labjack import ljm 38 | 39 | 40 | # Open first found LabJack 41 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 42 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 43 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 44 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 45 | 46 | info = ljm.getHandleInfo(handle) 47 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 48 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 49 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 50 | 51 | if info[0] == ljm.constants.dtT4: 52 | print("\nThe LabJack T4 does not support WiFi.") 53 | sys.exit() 54 | 55 | # Call eReadAddressByteArray to read the WiFi MAC (address 60024) from the 56 | # LabJack. We are reading a byte array which is the big endian binary 57 | # representation of the 64-bit MAC. 58 | macBytes = ljm.eReadAddressByteArray(handle, 60024, 8) 59 | 60 | # Convert big endian byte array to a 64-bit unsigned integer value 61 | mac, = struct.unpack(">Q", struct.pack("B"*8, *macBytes)) 62 | 63 | print("\nWiFi MAC : %i - %s" % (mac, ljm.numberToMAC(mac))) 64 | 65 | # Close handle 66 | ljm.close(handle) 67 | -------------------------------------------------------------------------------- /Examples/More/WiFi/read_wifi_rssi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to read the WiFi RSSI from a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eReadName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmereadname 15 | 16 | T-Series and I/O: 17 | Modbus Map: 18 | https://labjack.com/support/software/api/modbus/modbus-map 19 | WiFi: 20 | https://labjack.com/support/datasheets/t-series/wifi 21 | 22 | Note: 23 | Our Python interfaces throw exceptions when there are any issues with 24 | device communications that need addressed. Many of our examples will 25 | terminate immediately when an exception is thrown. The onus is on the API 26 | user to address the cause of any exceptions thrown, and add exception 27 | handling when appropriate. We create our own exception classes that are 28 | derived from the built-in Python Exception class and can be caught as such. 29 | For more information, see the implementation in our source code and the 30 | Python standard documentation. 31 | """ 32 | import sys 33 | 34 | from labjack import ljm 35 | 36 | 37 | # Open first found LabJack 38 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 39 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 40 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 41 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 42 | 43 | info = ljm.getHandleInfo(handle) 44 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 45 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 46 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 47 | 48 | if info[0] == ljm.constants.dtT4: 49 | print("\nThe LabJack T4 does not support WiFi.") 50 | sys.exit() 51 | 52 | # Setup and call eReadName to read the WiFi RSSI from the LabJack. 53 | name = "WIFI_RSSI" 54 | result = ljm.eReadName(handle, name) 55 | print("\n%s : %f" % (name, result)) 56 | 57 | # Close handle 58 | ljm.close(handle) 59 | -------------------------------------------------------------------------------- /Examples/More/WiFi/write_wifi_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Demonstrates how to configure the WiFi settings on a LabJack. 3 | 4 | Relevant Documentation: 5 | 6 | LJM Library: 7 | LJM Library Installer: 8 | https://labjack.com/support/software/installers/ljm 9 | LJM Users Guide: 10 | https://labjack.com/support/software/api/ljm 11 | Opening and Closing: 12 | https://labjack.com/support/software/api/ljm/function-reference/opening-and-closing 13 | eWriteName: 14 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritename 15 | eWriteNames: 16 | https://labjack.com/support/software/api/ljm/function-reference/ljmewritenames 17 | IPToNumber: 18 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmiptonumber 19 | NumberToIP: 20 | https://labjack.com/support/software/api/ljm/function-reference/utility/ljmnumbertoip 21 | 22 | T-Series and I/O: 23 | Modbus Map: 24 | https://labjack.com/support/software/api/modbus/modbus-map 25 | WiFi: 26 | https://labjack.com/support/datasheets/t-series/wifi 27 | 28 | Note: 29 | Our Python interfaces throw exceptions when there are any issues with 30 | device communications that need addressed. Many of our examples will 31 | terminate immediately when an exception is thrown. The onus is on the API 32 | user to address the cause of any exceptions thrown, and add exception 33 | handling when appropriate. We create our own exception classes that are 34 | derived from the built-in Python Exception class and can be caught as such. 35 | For more information, see the implementation in our source code and the 36 | Python standard documentation. 37 | """ 38 | import sys 39 | 40 | from labjack import ljm 41 | 42 | 43 | # Open first found LabJack 44 | handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier 45 | #handle = ljm.openS("T8", "ANY", "ANY") # T8 device, Any connection, Any identifier 46 | #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier 47 | #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier 48 | 49 | info = ljm.getHandleInfo(handle) 50 | print("Opened a LabJack with Device type: %i, Connection type: %i,\n" 51 | "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % 52 | (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) 53 | 54 | if info[0] == ljm.constants.dtT4: 55 | print("\nThe LabJack T4 does not support WiFi.") 56 | sys.exit() 57 | 58 | # Setup and call eWriteNames to configure WiFi default settings on the LabJack. 59 | numFrames = 3 60 | names = ["WIFI_IP_DEFAULT", "WIFI_SUBNET_DEFAULT", 61 | "WIFI_GATEWAY_DEFAULT"] 62 | aValues = [ljm.ipToNumber("192.168.1.207"), ljm.ipToNumber("255.255.255.0"), 63 | ljm.ipToNumber("192.168.1.1")] 64 | ljm.eWriteNames(handle, numFrames, names, aValues) 65 | 66 | print("\nSet WiFi configuration:") 67 | for i in range(numFrames): 68 | print(" %s : %.0f - %s" % 69 | (names[i], aValues[i], ljm.numberToIP(aValues[i]))) 70 | 71 | # Setup and call eWriteString to configure the default WiFi SSID on the LabJack. 72 | name = "WIFI_SSID_DEFAULT" 73 | string = "LJOpen" 74 | ljm.eWriteNameString(handle, name, string) 75 | print(" %s : %s" % (name, string)) 76 | 77 | # Setup and call eWriteString to configure the default WiFi password on the 78 | # LabJack. 79 | name = "WIFI_PASSWORD_DEFAULT" 80 | string = "none" 81 | ljm.eWriteNameString(handle, name, string) 82 | print(" %s : %s" % (name, string)) 83 | 84 | # Setup and call eWriteName to apply the new WiFi configuration on the LabJack. 85 | name = "WIFI_APPLY_SETTINGS" 86 | value = 1 87 | ljm.eWriteName(handle, name, value) 88 | print(" %s : %.0f" % (name, value)) 89 | 90 | # Close handle 91 | ljm.close(handle) 92 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 LabJack Corporation 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.TXT: -------------------------------------------------------------------------------- 1 | labjack-ljm : LJM library Python wrapper for LabJack T4, T7 and T8 2 | 04/24/2025 3 | support@labjack.com 4 | 5 | 6 | The Python wrapper package, modules and examples for the cross-platform LJM 7 | library, which supports the LabJack T4, T7 and T8. 8 | 9 | 10 | Installation Requirements: 11 | 12 | * Windows, Mac OS X / macOS, or Linux 13 | * LJM library: https://labjack.com/support/software/installers/ljm 14 | * Python 2.6, 2.7 and 3.x. 15 | 16 | 17 | Installation: 18 | 19 | After fulfilling the requirements, open a terminal/console and use pip to 20 | install labjack-ljm for the first time: 21 | 22 | python -m pip install labjack-ljm 23 | 24 | To upgrade to a newer version use: 25 | 26 | python -m pip install labjack-ljm --upgrade 27 | 28 | On Linux and macOS, you can also install with pip like so: 29 | 30 | pip install labjack-ljm 31 | 32 | Alternatively, download the labjack-ljm distribution source, unzip the contents 33 | and go to its unzipped directory. To install, run the the following command 34 | (run with sudo on Linux and macOS): 35 | 36 | $ python setup.py install 37 | 38 | If using Conda, we suggest creating a skeleton package from our PyPi package, 39 | then install with Conda: 40 | conda skeleton pypi labjack-ljm 41 | conda-build labjack-ljm 42 | 43 | 44 | Distribution Name Change: 45 | 46 | The previous distribution name was LJMPython in versions v1.19 and older. 47 | Starting with version 1.20 and the releases on PyPi, the distribution name is 48 | labjack-ljm. The namespace, package and interface remain the same. 49 | 50 | 51 | Installation Troubleshooting: 52 | 53 | - If you have multiple versions of Python installed, make sure you install for 54 | the Python version you will be using. For example, on Linux if both 55 | Python 2.7 and 3.5 are installed, you can install to Python 3.5 with: 56 | 57 | $ python3.5 -m pip labjack-ljm install 58 | 59 | - On Windows, if you have Python installed and installation of labjack-ljm fails 60 | with an error of, or similar to: 61 | 62 | 'python' is not recognized as an internal or external command, operable 63 | program or batch file. 64 | 65 | The Python executable path may not have been added to the Windows user or 66 | system path. One way to add Python to the path is to run the Python Windows 67 | installer and in the "Customize Python" window click the "Add python.exe to 68 | Path" option towards the bottom and select "Will be installed on local hard 69 | drive". Afterwards, open a new terminal/console and retry labjack-ljm 70 | installation. 71 | 72 | - If you have LJMPython version 1.19 or older installed, and are updating to 73 | labjack-ljm v1.20 or newer, using pip for installation is recommended. 74 | 75 | If using setup.py for installation, afterwards check the labjack.ljm version 76 | number. 77 | 78 | from labjack import ljm 79 | print(ljm.__version__) 80 | 81 | If it is not the version you installed and still reports a previous version, 82 | go to your Python site-packeges directory. If you see a 83 | labjack_ljm--py.egg file ( is labjack-ljm version 84 | and is the Python version), delete the labjack directory. The egg 85 | file contains the labjack folder files zipped, and the labjack folder and its 86 | files are conflicting. 87 | 88 | 89 | Examples: 90 | 91 | Example code can be found in the Examples directory. 92 | 93 | 94 | Documentation: 95 | 96 | LJM Python documentation can be found in the docstrings of the source code. The 97 | source code files are located in the labjack/ljm directory. 98 | 99 | Alternatively, after installation in Python you can use the help function on a 100 | module for documentation. For example: 101 | 102 | $ python 103 | >>> from labjack import ljm 104 | >>> help(ljm.ljm) 105 | 106 | LJM library documentation can be found here: 107 | 108 | https://labjack.com/support/software/api/ljm 109 | 110 | T4, T7 and T8 documentation can be found here: 111 | 112 | https://labjack.com/support/datasheets/t-series 113 | 114 | 115 | License: 116 | 117 | All LJM Python modules and examples are licensed under MIT X11. The license can 118 | be found in the LICENSE.TXT file. 119 | -------------------------------------------------------------------------------- /labjack/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labjack/labjack-ljm-python/ddf4a3f0a08b1757d8473f466644f6362a70fe88/labjack/__init__.py -------------------------------------------------------------------------------- /labjack/ljm/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Package for cross-platform wrapper for the LJM library. 3 | 4 | """ 5 | 6 | from labjack.ljm.ljm import * 7 | 8 | 9 | __version__ = "1.23.0" 10 | -------------------------------------------------------------------------------- /labjack/ljm/constants.py: -------------------------------------------------------------------------------- 1 | """ 2 | LJM library constants. 3 | 4 | """ 5 | 6 | # Read/Write direction constants: 7 | READ = 0 8 | WRITE = 1 9 | 10 | # Data types: 11 | # Automatic endian conversion, if needed by the processor 12 | UINT16 = 0 13 | UINT32 = 1 14 | INT32 = 2 15 | FLOAT32 = 3 16 | 17 | # Advanced users data types: 18 | # Does not do any endianness conversion 19 | BYTE = 99 20 | STRING = 98 21 | STRING_MAX_SIZE = 49 22 | STRING_ALLOCATION_SIZE = 50 23 | 24 | # namesToAddresses sets this when a register name is not found 25 | INVALID_NAME_ADDRESS = -1 26 | MAX_NAME_SIZE = 256 27 | 28 | MAC_STRING_SIZE = 18 29 | IPv4_STRING_SIZE = 16 30 | 31 | BYTES_PER_REGISTER = 2 32 | 33 | # Device types: 34 | dtANY = 0 35 | dtT4 = 4 36 | dtT7 = 7 37 | dtT8 = 8 38 | dtDIGIT = 200 39 | dtTSERIES = 84 40 | 41 | # Connection types: 42 | ctANY = 0 43 | ctANY_TCP = ctANY 44 | 45 | ctUSB = 1 46 | 47 | ctTCP = 2 48 | ctNETWORK_TCP = ctTCP 49 | ctETHERNET = 3 50 | ctETHERNET_TCP = ctETHERNET 51 | ctWIFI = 4 52 | ctWIFI_TCP = ctWIFI 53 | 54 | # UDP 55 | ctANY_UDP = 11 56 | ctNETWORK_UDP = 5 57 | ctETHERNET_UDP = 6 58 | ctWIFI_UDP = 7 59 | 60 | # TCP or UDP 61 | ctNETWORK_ANY = 8 62 | ctETHERNET_ANY = 9 63 | ctWIFI_ANY = 10 64 | 65 | # Network constants: 66 | TCP_PORT = 502 67 | ETHERNET_UDP_PORT = 52362 68 | WIFI_UDP_PORT = 502 69 | NO_IP_ADDRESS = 0 70 | NO_PORT = 0 71 | 72 | # Identifier types: 73 | DEMO_MODE = "-2" 74 | idANY = 0 75 | 76 | # addressesToMBFB Constants 77 | DEFAULT_FEEDBACK_ALLOCATION_SIZE = 62 78 | USE_DEFAULT_MAXBYTESPERMBFB = 0 79 | 80 | # mbfbComm Constants 81 | DEFAULT_UNIT_ID = 1 82 | 83 | # listAll Constants 84 | LIST_ALL_SIZE = 128 85 | 86 | # Timeout Constants 87 | NO_TIMEOUT = 0 88 | DEFAULT_USB_SEND_RECEIVE_TIMEOUT_MS = 2600 89 | DEFAULT_ETHERNET_OPEN_TIMEOUT_MS = 1000 90 | DEFAULT_ETHERNET_SEND_RECEIVE_TIMEOUT_MS = 2600 91 | DEFAULT_WIFI_OPEN_TIMEOUT_MS = 1000 92 | DEFAULT_WIFI_SEND_RECEIVE_TIMEOUT_MS = 4000 93 | 94 | # Stream Constants 95 | DUMMY_VALUE = -9999 96 | SCAN_NOT_READ = -8888 97 | GND = 199 98 | 99 | # Thermocouple Type Constants 100 | ttB = 6001 101 | ttE = 6002 102 | ttJ = 6003 103 | ttK = 6004 104 | ttN = 6005 105 | ttR = 6006 106 | ttS = 6007 107 | ttT = 6008 108 | ttC = 6009 109 | 110 | # Config Parameters 111 | USB_SEND_RECEIVE_TIMEOUT_MS = "LJM_USB_SEND_RECEIVE_TIMEOUT_MS" 112 | ETHERNET_SEND_RECEIVE_TIMEOUT_MS = "LJM_ETHERNET_SEND_RECEIVE_TIMEOUT_MS" 113 | WIFI_SEND_RECEIVE_TIMEOUT_MS = "LJM_WIFI_SEND_RECEIVE_TIMEOUT_MS" 114 | SEND_RECEIVE_TIMEOUT_MS = "LJM_SEND_RECEIVE_TIMEOUT_MS" 115 | ETHERNET_OPEN_TIMEOUT_MS = "LJM_ETHERNET_OPEN_TIMEOUT_MS" 116 | WIFI_OPEN_TIMEOUT_MS = "LJM_WIFI_OPEN_TIMEOUT_MS" 117 | OPEN_TCP_DEVICE_TIMEOUT_MS = "LJM_OPEN_TCP_DEVICE_TIMEOUT_MS" 118 | 119 | DEBUG_LOG_MODE = "LJM_DEBUG_LOG_MODE" 120 | DEBUG_LOG_MODE_NEVER = 1 121 | DEBUG_LOG_MODE_CONTINUOUS = 2 122 | DEBUG_LOG_MODE_ON_ERROR = 3 123 | 124 | DEBUG_LOG_LEVEL = "LJM_DEBUG_LOG_LEVEL" 125 | STREAM_PACKET = 1 126 | TRACE = 2 127 | DEBUG = 4 128 | INFO = 6 129 | PACKET = 7 130 | WARNING = 8 131 | ERROR = 10 132 | FATAL = 12 133 | 134 | DEBUG_LOG_BUFFER_MAX_SIZE = "LJM_DEBUG_LOG_BUFFER_MAX_SIZE" 135 | DEBUG_LOG_SLEEP_TIME_MS = "LJM_DEBUG_LOG_SLEEP_TIME_MS" 136 | 137 | LIBRARY_VERSION = "LJM_LIBRARY_VERSION" 138 | 139 | ALLOWS_AUTO_MULTIPLE_FEEDBACKS = "LJM_ALLOWS_AUTO_MULTIPLE_FEEDBACKS" 140 | ALLOWS_AUTO_CONDENSE_ADDRESSES = "LJM_ALLOWS_AUTO_CONDENSE_ADDRESSES" 141 | 142 | AUTO_IPS_FILE = "LJM_AUTO_IPS_FILE" 143 | AUTO_IPS = "LJM_AUTO_IPS" 144 | 145 | AUTO_RECONNECT_STICKY_CONNECTION = "LJM_AUTO_RECONNECT_STICKY_CONNECTION" 146 | AUTO_RECONNECT_STICKY_SERIAL = "LJM_AUTO_RECONNECT_STICKY_SERIAL" 147 | AUTO_RECONNECT_WAIT_MS = "LJM_AUTO_RECONNECT_WAIT_MS" 148 | 149 | INTERVAL_CLOCK_TYPE = "LJM_INTERVAL_CLOCK_TYPE" 150 | INTERVAL_CLOCK_TYPE_STEADY = 1 151 | INTERVAL_CLOCK_TYPE_SYSTEM = 2 152 | 153 | MODBUS_MAP_CONSTANTS_FILE = "LJM_MODBUS_MAP_CONSTANTS_FILE" 154 | ERROR_CONSTANTS_FILE = "LJM_ERROR_CONSTANTS_FILE" 155 | DEBUG_LOG_FILE = "LJM_DEBUG_LOG_FILE" 156 | CONSTANTS_FILE = "LJM_CONSTANTS_FILE" 157 | DEBUG_LOG_FILE_MAX_SIZE = "LJM_DEBUG_LOG_FILE_MAX_SIZE" 158 | DEEP_SEARCH_FILE = "LJM_DEEP_SEARCH_FILE" 159 | SPECIFIC_IPS_FILE = "LJM_SPECIFIC_IPS_FILE" 160 | 161 | STREAM_AIN_BINARY = "LJM_STREAM_AIN_BINARY" 162 | STREAM_DIGITAL_AUTO_RECOVERY_ERROR_DETECTION_DISABLED = "LJM_STREAM_DIGITAL_AUTO_RECOVERY_ERROR_DETECTION_DISABLED" 163 | STREAM_SCANS_RETURN = "LJM_STREAM_SCANS_RETURN" 164 | STREAM_SCANS_RETURN_ALL = 1 165 | STREAM_SCANS_RETURN_ALL_OR_NONE = 2 166 | STREAM_SCANS_RETURN_AVAILABLE = 3 167 | 168 | STREAM_RECEIVE_TIMEOUT_MODE = "LJM_STREAM_RECEIVE_TIMEOUT_MODE" 169 | STREAM_RECEIVE_TIMEOUT_MODE_CALCULATED = 1 170 | STREAM_RECEIVE_TIMEOUT_MODE_MANUAL = 2 171 | 172 | STREAM_TCP_RECEIVE_BUFFER_SIZE = "LJM_STREAM_TCP_RECEIVE_BUFFER_SIZE" 173 | 174 | STREAM_THREADS_PRIORITY_MODE = "LJM_STREAM_THREADS_PRIORITY_MODE" 175 | STREAM_THREADS_PRIORITY_AUTO_ELEVATED = 1 176 | STREAM_THREADS_PRIORITY_UNALTERED = 2 177 | 178 | STREAM_PROCESS_PRIORITY_MODE = "LJM_STREAM_PROCESS_PRIORITY_MODE" 179 | STREAM_PROCESS_PRIORITY_ELEVATED = 1 180 | STREAM_PROCESS_PRIORITY_UNALTERED = 2 181 | 182 | STREAM_RECEIVE_TIMEOUT_MS = "LJM_STREAM_RECEIVE_TIMEOUT_MS" 183 | STREAM_TRANSFERS_PER_SECOND = "LJM_STREAM_TRANSFERS_PER_SECOND" 184 | 185 | STREAM_OUT_DEVICE_BUFFER_ALLOCATE_NUM_BYTES = "LJM_STREAM_OUT_DEVICE_BUFFER_ALLOCATE_NUM_BYTES" 186 | 187 | RETRY_ON_TRANSACTION_ID_MISMATCH = "LJM_RETRY_ON_TRANSACTION_ID_MISMATCH" 188 | 189 | OLD_FIRMWARE_CHECK = "LJM_OLD_FIRMWARE_CHECK" 190 | 191 | USE_TCP_INIT_FOR_T7_WIFI_TCP = "LJM_USE_TCP_INIT_FOR_T7_WIFI_TCP" 192 | 193 | ZERO_LENGTH_ARRAY_MODE = "LJM_ZERO_LENGTH_ARRAY_MODE" 194 | ZERO_LENGTH_ARRAY_ERROR = 1 195 | ZERO_LENGTH_ARRAY_IGNORE_OPERATION = 2 196 | 197 | DEFAULT_PORT = 502 # Deprecated - use TCP_PORT 198 | UDP_PORT = 52362 # Deprecated - ETHERNET_UDP_PORT or WIFI_UDP_PORT 199 | 200 | MAX_TCP_PACKET_NUM_BYTES_T7 = 1040 # Deprecated - Maximum packet size should be read from the getHandleInfo function 201 | MAX_USB_PACKET_NUM_BYTES = 64 # Deprecated - Maximum packet size should be read from the getHandleInfo function 202 | MAX_ETHERNET_PACKET_NUM_BYTES_T7 = 1040 # Deprecated - Maximum packet size should be read from the getHandleInfo function 203 | MAX_WIFI_PACKET_NUM_BYTES_T7 = 500 # Deprecated - Maximum packet size should be read from the getHandleInfo function 204 | 205 | SPECIAL_ADDRESSES_FILE = "LJM_SPECIAL_ADDRESSES_FILE" # Deprecated - use SPECIFIC_IPS_FILE instead 206 | SPECIAL_ADDRESSES_STATUS = "LJM_SPECIAL_ADDRESSES_STATUS" # Deprecated - use getSpecificIPsInfo function instead 207 | 208 | OPEN_MODE = "LJM_OPEN_MODE" # Deprecated 209 | KEEP_OPEN = 1 # Deprecated 210 | OPEN_CLOSE = 2 # Deprecated 211 | -------------------------------------------------------------------------------- /labjack/ljm/errorcodes.py: -------------------------------------------------------------------------------- 1 | """ 2 | LJM library error codes. 3 | 4 | """ 5 | 6 | # Success 7 | NOERROR = 0 8 | 9 | # Warnings: 10 | WARNINGS_BEGIN = 200 11 | WARNINGS_END = 399 12 | FRAMES_OMITTED_DUE_TO_PACKET_SIZE = 201 13 | 14 | DEBUG_LOG_FAILURE = 202 15 | USING_DEFAULT_CALIBRATION = 203 16 | 17 | DEBUG_LOG_FILE_NOT_OPEN = 204 18 | 19 | # Modbus Errors: 20 | MODBUS_ERRORS_BEGIN = 1200 21 | MODBUS_ERRORS_END = 1216 22 | MBE1_ILLEGAL_FUNCTION = 1201 23 | MBE2_ILLEGAL_DATA_ADDRESS = 1202 24 | MBE3_ILLEGAL_DATA_VALUE = 1203 25 | MBE4_SLAVE_DEVICE_FAILURE = 1204 26 | MBE5_ACKNOWLEDGE = 1205 27 | MBE6_SLAVE_DEVICE_BUSY = 1206 28 | MBE8_MEMORY_PARITY_ERROR = 1208 29 | MBE10_GATEWAY_PATH_UNAVAILABLE = 1210 30 | MBE11_GATEWAY_TARGET_NO_RESPONSE = 1211 31 | 32 | # Library Errors: 33 | LIBRARY_ERRORS_BEGIN = 1220 34 | LIBRARY_ERRORS_END = 1399 35 | 36 | UNKNOWN_ERROR = 1221 37 | INVALID_DEVICE_TYPE = 1222 38 | INVALID_HANDLE = 1223 39 | DEVICE_NOT_OPEN = 1224 40 | STREAM_NOT_INITIALIZED = 1225 41 | DEVICE_DISCONNECTED = 1226 42 | DEVICE_NOT_FOUND = 1227 43 | APERIODIC_STREAM_OUT_NOT_INITIALIZED = 1228 44 | DEVICE_ALREADY_OPEN = 1229 45 | DEVICE_CURRENTLY_CLAIMED_BY_ANOTHER_PROCESS = 1230 46 | CANNOT_CONNECT = 1231 47 | STREAM_OUT_INDEX_OUT_OF_RANGE = 1232 48 | SOCKET_LEVEL_ERROR = 1233 49 | SCAN_RATE_INCONSISTENT = 1234 50 | CANNOT_OPEN_DEVICE = 1236 51 | CANNOT_DISCONNECT = 1237 52 | WINSOCK_FAILURE = 1238 53 | RECONNECT_FAILED = 1239 54 | CONNECTION_HAS_YIELDED_RECONNECT_FAILED = 1240 55 | USB_FAILURE = 1241 56 | 57 | # LJM does not support U3, U6, UE9, or U12 devices 58 | U3_NOT_SUPPORTED_BY_LJM = 1243 59 | U6_NOT_SUPPORTED_BY_LJM = 1246 60 | UE9_NOT_SUPPORTED_BY_LJM = 1249 61 | 62 | INVALID_ADDRESS = 1250 63 | INVALID_CONNECTION_TYPE = 1251 64 | INVALID_DIRECTION = 1252 65 | INVALID_FUNCTION = 1253 66 | 67 | INVALID_NUM_REGISTERS = 1254 68 | INVALID_PARAMETER = 1255 69 | INVALID_PROTOCOL_ID = 1256 70 | INVALID_TRANSACTION_ID = 1257 71 | NUM_WRITES_LARGER_THAN_AVAILABLE_SPACE = 1258 72 | UNKNOWN_VALUE_TYPE = 1259 73 | MEMORY_ALLOCATION_FAILURE = 1260 74 | 75 | NO_COMMAND_BYTES_SENT = 1261 76 | 77 | INCORRECT_NUM_COMMAND_BYTES_SENT = 1262 78 | 79 | NO_RESPONSE_BYTES_RECEIVED = 1263 80 | 81 | INCORRECT_NUM_RESPONSE_BYTES_RECEIVED = 1264 82 | 83 | MIXED_FORMAT_IP_ADDRESS = 1265 84 | 85 | UNKNOWN_IDENTIFIER = 1266 86 | NOT_IMPLEMENTED = 1267 87 | INVALID_INDEX = 1268 88 | 89 | INVALID_LENGTH = 1269 90 | ERROR_BIT_SET = 1270 91 | 92 | INVALID_MAXBYTESPERMBFB = 1271 93 | 94 | NULL_POINTER = 1272 95 | 96 | NULL_OBJ = 1273 97 | 98 | RESERVED_NAME = 1274 99 | 100 | UNPARSABLE_DEVICE_TYPE = 1275 101 | 102 | UNPARSABLE_CONNECTION_TYPE = 1276 103 | 104 | UNPARSABLE_IDENTIFIER = 1277 105 | 106 | PACKET_SIZE_TOO_LARGE = 1278 107 | 108 | TRANSACTION_ID_ERR = 1279 109 | PROTOCOL_ID_ERR = 1280 110 | LENGTH_ERR = 1281 111 | UNIT_ID_ERR = 1282 112 | FUNCTION_ERR = 1283 113 | STARTING_REG_ERR = 1284 114 | NUM_REGS_ERR = 1285 115 | NUM_BYTES_ERR = 1286 116 | CONFIG_FILE_NOT_FOUND = 1289 117 | CONFIG_PARSING_ERROR = 1290 118 | INVALID_NUM_VALUES = 1291 119 | MODBUS_CONSTANTS_FILE_NOT_FOUND = 1292 120 | INVALID_MODBUS_CONSTANTS_FILE = 1293 121 | INVALID_NAME = 1294 122 | OVERSPECIFIED_PORT = 1296 123 | INTENT_NOT_READY = 1297 124 | ATTR_LOAD_COMM_FAILURE = 1298 125 | INVALID_CONFIG_NAME = 1299 126 | 127 | ERROR_RETRIEVAL_FAILURE = 1300 128 | LJM_BUFFER_FULL = 1301 129 | COULD_NOT_START_STREAM = 1302 130 | STREAM_NOT_RUNNING = 1303 131 | UNABLE_TO_STOP_STREAM = 1304 132 | INVALID_VALUE = 1305 133 | SYNCHRONIZATION_TIMEOUT = 1306 134 | OLD_FIRMWARE = 1307 135 | CANNOT_READ_OUT_ONLY_STREAM = 1308 136 | NO_SCANS_RETURNED = 1309 137 | TEMPERATURE_OUT_OF_RANGE = 1310 138 | VOLTAGE_OUT_OF_RANGE = 1311 139 | FUNCTION_DOES_NOT_SUPPORT_THIS_TYPE = 1312 140 | INVALID_INFO_HANDLE = 1313 141 | 142 | NO_DEVICES_FOUND = 1314 143 | 144 | AUTO_IPS_FILE_NOT_FOUND = 1316 145 | AUTO_IPS_FILE_INVALID = 1317 146 | 147 | INVALID_INTERVAL_HANDLE = 1318 148 | 149 | NAMED_MUTEX_PERMISSION_DENIED = 1319 150 | 151 | DIGITAL_AUTO_RECOVERY_ERROR_DETECTED = 1320 152 | NEGATIVE_RECEIVE_BUFFER_SIZE = 1321 153 | 154 | COULD_NOT_CLAIM_DEVICE = 1230 # Deprecated - use DEVICE_CURRENTLY_CLAIMED_BY_ANOTHER_PROCESS instead 155 | U3_CANNOT_BE_OPENED_BY_LJM = 1243 # Deprecated - use U3_NOT_SUPPORTED_BY_LJM instead 156 | U6_CANNOT_BE_OPENED_BY_LJM = 1246 # Deprecated - use U6_NOT_SUPPORTED_BY_LJM instead 157 | UE9_CANNOT_BE_OPENED_BY_LJM = 1249 # Deprecated- use UE9_NOT_SUPPORTED_BY_LJM instead 158 | INVALID_VALUE_TYPE = 1259 # Deprecated - use UNKNOWN_VALUE_TYPE instead 159 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | license_files=LICENSE.TXT 3 | 4 | [bdist_wheel] 5 | universal=1 6 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | CLASSIFIERS = [ 4 | 'Development Status :: 5 - Production/Stable', 5 | 'Environment :: Console', 6 | 'Intended Audience :: Developers', 7 | 'License :: OSI Approved :: MIT License', 8 | 'Operating System :: MacOS :: MacOS X', 9 | 'Operating System :: Microsoft :: Windows', 10 | 'Operating System :: POSIX :: Linux', 11 | 'Programming Language :: Python', 12 | 'Programming Language :: Python :: 2', 13 | 'Programming Language :: Python :: 2.6', 14 | 'Programming Language :: Python :: 2.7', 15 | 'Programming Language :: Python :: 3', 16 | 'Programming Language :: Python :: 3.3', 17 | 'Programming Language :: Python :: 3.4', 18 | 'Programming Language :: Python :: 3.5', 19 | 'Programming Language :: Python :: 3.6', 20 | 'Programming Language :: Python :: 3.7', 21 | 'Programming Language :: Python :: 3.8', 22 | 'Programming Language :: Python :: 3.9', 23 | 'Programming Language :: Python :: 3.10', 24 | 'Programming Language :: Python :: 3.11', 25 | 'Programming Language :: Python :: 3.12', 26 | 'Programming Language :: Python :: 3.13', 27 | 'Topic :: Software Development', 28 | 'Topic :: Software Development :: Embedded Systems', 29 | 'Topic :: System :: Hardware' 30 | ] 31 | 32 | setup(name="labjack-ljm", 33 | version='1.23.0', 34 | description='LJM library Python wrapper for LabJack T4, T7 and T8.', 35 | url='https://labjack.com/support/software/examples/ljm/python', 36 | author='LabJack Corporation', 37 | author_email="support@labjack.com", 38 | maintainer='LabJack Corporation', 39 | maintainer_email='support@labjack.com', 40 | classifiers=CLASSIFIERS, 41 | license='MIT X11', 42 | packages=['labjack', 'labjack.ljm'] 43 | ) 44 | --------------------------------------------------------------------------------