### High-Speed Data Acquisition with eStreamStart, eStreamRead, eStreamStop Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Configures and runs continuous high-speed data streaming from analog inputs. This function is ideal for waveform capture and signal analysis, providing consistent sample rates. It requires configuring stream channels, scan rate, and device-specific settings before starting and stopping the stream. ```python from labjack import ljm from datetime import datetime handle = ljm.openS("ANY", "ANY", "ANY") try: info = ljm.getHandleInfo(handle) device_type = info[0] # Configure stream channels scan_list_names = ["AIN0", "AIN1"] num_addresses = len(scan_list_names) # Convert names to addresses for stream scan_list = ljm.namesToAddresses(num_addresses, scan_list_names)[0] # Stream parameters scan_rate = 1000 # 1000 scans per second scans_per_read = 500 # Read 500 scans at a time # Configure analog input settings before streaming if device_type == ljm.constants.dtT4: # T4 configuration ljm.eWriteNames(handle, 2, ["STREAM_SETTLING_US", "STREAM_RESOLUTION_INDEX"], [0, 0]) else: # T7/T8 configuration ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 0) # Disable triggered stream ljm.eWriteName(handle, "STREAM_CLOCK_SOURCE", 0) # Internal clock ljm.eWriteNames(handle, 3, ["AIN0_RANGE", "AIN1_RANGE", "STREAM_RESOLUTION_INDEX"], [10.0, 10.0, 0]) # +/-10V range # Start stream actual_scan_rate = ljm.eStreamStart(handle, scans_per_read, num_addresses, scan_list, scan_rate) print(f"Stream started at {actual_scan_rate:.0f} Hz") # Read stream data total_scans = 0 start_time = datetime.now() for i in range(10): # Read 10 batches # Returns (data, device_backlog, ljm_backlog) ret = ljm.eStreamRead(handle) data = ret[0] device_backlog = ret[1] ljm_backlog = ret[2] scans = len(data) // num_addresses total_scans += scans # Get first sample of each channel ain0_first = data[0] ain1_first = data[1] print(f"Read {i+1}: {scans} scans, AIN0={ain0_first:.4f}V, " f"AIN1={ain1_first:.4f}V, Backlog: {device_backlog}/{ljm_backlog}") elapsed = (datetime.now() - start_time).total_seconds() print(f"\nTotal: {total_scans} scans in {elapsed:.2f}s = " f"{total_scans/elapsed:.0f} scans/sec") except ljm.LJMError as e: print(f"Stream error: {e.errorString}") finally: # Always stop stream before closing try: ljm.eStreamStop(handle) print("Stream stopped") except ljm.LJMError: pass ljm.close(handle) ``` -------------------------------- ### Open Device Connection with String Parameters (Python) Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Opens a connection to a LabJack device using string parameters for device type, connection type, and identifier (serial number, IP address, or device name). Returns a handle for subsequent operations. Requires the 'labjack' library. ```python from labjack import ljm # Open any available LabJack device handle = ljm.openS("ANY", "ANY", "ANY") # Open a specific device type handle = ljm.openS("T7", "ANY", "ANY") # T7 only, any connection handle = ljm.openS("T4", "USB", "ANY") # T4 via USB only handle = ljm.openS("T8", "ETHERNET", "ANY") # T8 via Ethernet only # Open by serial number handle = ljm.openS("ANY", "ANY", "470012345") # Open by IP address handle = ljm.openS("ANY", "TCP", "192.168.1.100") # Open by device name handle = ljm.openS("ANY", "ANY", "MyLabJack") # Get device information info = ljm.getHandleInfo(handle) print(f"Device type: {info[0]}") # 7 for T7, 4 for T4, 8 for T8 print(f"Connection type: {info[1]}") # 1 for USB, 2 for TCP print(f"Serial number: {info[2]}") # e.g., 470012345 print(f"IP address: {ljm.numberToIP(info[3])}") # e.g., 192.168.1.100 print(f"Port: {info[4]}") # e.g., 502 print(f"Max bytes per MB: {info[5]}") # Max packet size # Always close the handle when done ljm.close(handle) ``` -------------------------------- ### Open Device Connection with Integer Constants (Python) Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Opens a connection to a LabJack device using integer constants for device type and connection type. Requires the 'labjack' library. ```python from labjack import ljm # Open any device, any connection handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Open T7 via USB handle = ljm.open(ljm.constants.dtT7, ljm.constants.ctUSB, "ANY") # Open T4 via Ethernet handle = ljm.open(ljm.constants.dtT4, ljm.constants.ctETHERNET, "ANY") # Open T8 via WiFi by serial number handle = ljm.open(ljm.constants.dtT8, ljm.constants.ctWIFI, "470012345") # Close when done ljm.close(handle) # Close all open handles ljm.closeAll() ``` -------------------------------- ### Configure LabJack LJM Library Settings Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Shows how to configure various LabJack LJM library settings using `readLibraryConfigS` and `writeLibraryConfigS`. This includes setting timeouts, enabling debug logging, and configuring stream behavior. It also demonstrates loading configuration from a file. ```python from labjack import ljm # Read current library version version = ljm.readLibraryConfigS("LJM_LIBRARY_VERSION") print(f"LJM Library version: {version}") # Configure USB timeout (milliseconds) ljm.writeLibraryConfigS("LJM_USB_SEND_RECEIVE_TIMEOUT_MS", 5000) print("USB timeout set to 5000 ms") # Configure Ethernet timeout ljm.writeLibraryConfigS("LJM_ETHERNET_SEND_RECEIVE_TIMEOUT_MS", 10000) print("Ethernet timeout set to 10000 ms") # Enable debug logging ljm.writeLibraryConfigS("LJM_DEBUG_LOG_MODE", ljm.constants.DEBUG_LOG_MODE_CONTINUOUS) ljm.writeLibraryConfigS("LJM_DEBUG_LOG_LEVEL", ljm.constants.WARNING) # Read debug log file path log_file = ljm.readLibraryConfigStringS("LJM_DEBUG_LOG_FILE") print(f"Debug log file: {log_file}") # Configure stream settings ljm.writeLibraryConfigS("LJM_STREAM_SCANS_RETURN", ljm.constants.STREAM_SCANS_RETURN_ALL_OR_NONE) ljm.writeLibraryConfigS("LJM_STREAM_RECEIVE_TIMEOUT_MS", 3000) # Load configuration from file ljm.loadConfigurationFile("default") # Load default configuration ``` -------------------------------- ### Scan for LabJack Devices (Python) Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Scans for connected LabJack devices on the system using any connection type. Returns information including device type, connection type, serial number, and IP address. Requires the 'labjack' library. ```python from labjack import ljm # Scan for all LabJack devices on any connection type info = ljm.listAllS("ANY", "ANY") # info tuple: (numFound, aDeviceTypes, aConnectionTypes, aSerialNumbers, aIPAddresses) num_found = info[0] print(f"Found {num_found} LabJack device(s)") # Device type constants for reference DEVICE_TYPES = { ljm.constants.dtT4: "T4", ljm.constants.dtT7: "T7", ljm.constants.dtT8: "T8", ljm.constants.dtDIGIT: "Digit" } CONN_TYPES = { ljm.constants.ctUSB: "USB", ljm.constants.ctTCP: "TCP", ljm.constants.ctETHERNET: "Ethernet", ljm.constants.ctWIFI: "WiFi" } # Display each found device for i in range(num_found): device_type = DEVICE_TYPES.get(info[1][i], str(info[1][i])) conn_type = CONN_TYPES.get(info[2][i], str(info[2][i])) serial = info[3][i] ip = ljm.numberToIP(info[4][i]) print(f" {device_type} via {conn_type}, Serial: {serial}, IP: {ip}") # Expected output: # Found 2 LabJack device(s) # T7 via USB, Serial: 470012345, IP: 0.0.0.0 # T7 via Ethernet, Serial: 470012346, IP: 192.168.1.100 ``` -------------------------------- ### Convert IP Addresses to Numbers and Vice Versa Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Provides functions to convert between string and integer representations of IP addresses and MAC addresses. This is useful for network configuration and identification tasks within the LabJack ecosystem. It handles both IPv4 and MAC address formats. ```python from labjack import ljm # Convert integer to IP string ip_number = 3232235876 # 192.168.1.100 as integer ip_string = ljm.numberToIP(ip_number) print(f"IP: {ip_string}") # Expected output: IP: 192.168.1.100 # Convert IP string to integer ip_string = "10.0.0.1" ip_number = ljm.ipToNumber(ip_string) print(f"IP number: {ip_number}") # Expected output: IP number: 167772161 # Convert MAC address mac_number = 0x001122334455 mac_string = ljm.numberToMAC(mac_number) print(f"MAC: {mac_string}") # Expected output: MAC: 00:11:22:33:44:55 mac_string = "AA:BB:CC:DD:EE:FF" mac_number = ljm.macToNumber(mac_string) print(f"MAC number: {mac_number}") ``` -------------------------------- ### Handle LabJack LJM Errors Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Demonstrates how to catch and handle LJMError exceptions, which are raised for device communication issues. The exception object provides detailed information including error codes, descriptive messages, and the address associated with the error, aiding in debugging. ```python from labjack import ljm try: # Attempt to open a device that doesn't exist handle = ljm.openS("T7", "USB", "999999999") except ljm.LJMError as e: print(f"Error code: {e.errorCode}") print(f"Error string: {e.errorString}") print(f"Error address: {e.errorAddress}") # Expected output: # Error code: 1227 # Error string: LJME_DEVICE_NOT_FOUND # Error address: None ``` -------------------------------- ### eWriteNames - Write Multiple Registers Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Writes multiple values to device registers in a single, efficient call. ```APIDOC ## eWriteNames - Write Multiple Registers ### Description Writes multiple values to device registers in a single call. ### Method `eWriteNames` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Set multiple DAC outputs at once names = ["DAC0", "DAC1"] values = [2.5, 1.0] ljm.eWriteNames(handle, len(names), names, values) print("DAC0=2.5V, DAC1=1.0V set successfully") # Set multiple digital outputs names = ["FIO0", "FIO1", "FIO2", "FIO3"] values = [1, 0, 1, 0] # HIGH, LOW, HIGH, LOW ljm.eWriteNames(handle, len(names), names, values) print("Digital outputs configured") # Configure multiple analog input settings names = ["AIN0_RANGE", "AIN1_RANGE", "AIN0_RESOLUTION_INDEX", "AIN1_RESOLUTION_INDEX"] values = [10.0, 10.0, 8, 8] # +/-10V range, resolution index 8 ljm.eWriteNames(handle, len(names), names, values) print("AIN configuration complete") except ljm.LJMError as e: print(f"Error at address {e.errorAddress}: {e.errorString}") finally: ljm.close(handle) ``` ### Response #### Success Response (200) Indicates the write operation was successful. Typically returns no specific data, but exceptions are raised on failure. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Handle LabJack Address-Specific Errors Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Demonstrates how to handle address-specific LabJack errors when reading multiple registers. It uses a try-except block to catch `ljm.LJMError` and prints the error address and string, indicating which register caused the issue. ```python from labjack import ljm # Example with address-specific error handle = ljm.openS("ANY", "ANY", "ANY") try: # Try to read invalid register names = ["AIN0", "INVALID_REGISTER", "AIN1"] values = ljm.eReadNames(handle, len(names), names) except ljm.LJMError as e: print(f"Error at index {e.errorAddress}: {e.errorString}") # Error address indicates which name in the list caused the error finally: ljm.close(handle) ``` -------------------------------- ### eReadNames - Read Multiple Registers Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Reads multiple values from device registers in a single call, offering improved efficiency over multiple individual read operations. ```APIDOC ## eReadNames - Read Multiple Registers ### Description Reads multiple values from device registers in a single call, which is more efficient than multiple individual reads. ### Method `eReadNames` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Read multiple analog inputs at once names = ["AIN0", "AIN1", "AIN2", "AIN3"] num_frames = len(names) values = ljm.eReadNames(handle, num_frames, names) for name, value in zip(names, values): print(f"{name}: {value:.4f} V") # Read mixed register types names = ["AIN0", "FIO0", "SERIAL_NUMBER", "TEMPERATURE_DEVICE_K"] values = ljm.eReadNames(handle, len(names), names) print(f"Analog voltage: {values[0]:.4f} V") print(f"Digital state: {int(values[1])}") print(f"Serial: {int(values[2])}") print(f"Temperature: {values[3] - 273.15:.1f} C") except ljm.LJMError as e: print(f"Error at address {e.errorAddress}: {e.errorString}") finally: ljm.close(handle) ``` ### Response #### Success Response (200) - **values** (list of floats or ints) - A list containing the values read from the specified registers, in the same order as the input names. #### Response Example ```json { "values": [ 1.2345, 0.5678, 2.3456, 0.1234 ] } ``` ``` -------------------------------- ### Convert Register Names to Addresses Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Translates LabJack register names (e.g., 'AIN0') into their corresponding Modbus addresses and data types. This utility is essential for configuring and reading from LabJack devices programmatically. It supports converting single names or lists of names. ```python from labjack import ljm # Convert single name to address address, data_type = ljm.nameToAddress("AIN0") print(f"AIN0: address={address}, type={data_type}") # Expected output: AIN0: address=0, type=3 (FLOAT32) address, data_type = ljm.nameToAddress("FIO_STATE") print(f"FIO_STATE: address={address}, type={data_type}") # Expected output: FIO_STATE: address=2500, type=1 (UINT32) # Convert multiple names to addresses names = ["AIN0", "AIN1", "DAC0", "FIO_STATE"] addresses, types = ljm.namesToAddresses(len(names), names) print(f"Addresses: {addresses}") print(f"Data types: {types}") # Expected output: # Addresses: [0, 2, 1000, 2500] # Data types: [3, 3, 3, 1] # Data type constants # ljm.constants.UINT16 = 0 # ljm.constants.UINT32 = 1 # ljm.constants.INT32 = 2 # ljm.constants.FLOAT32 = 3 ``` -------------------------------- ### Write Multiple Registers by Name using eWriteNames in Python Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Writes multiple values to LabJack device registers in a single call, offering improved efficiency. This function requires an active device handle, the number of registers, a list of register names, and a corresponding list of values to write. Error handling for LJM errors is included. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Set multiple DAC outputs at once names = ["DAC0", "DAC1"] values = [2.5, 1.0] ljm.eWriteNames(handle, len(names), names, values) print("DAC0=2.5V, DAC1=1.0V set successfully") # Set multiple digital outputs names = ["FIO0", "FIO1", "FIO2", "FIO3"] values = [1, 0, 1, 0] # HIGH, LOW, HIGH, LOW ljm.eWriteNames(handle, len(names), names, values) print("Digital outputs configured") # Configure multiple analog input settings names = ["AIN0_RANGE", "AIN1_RANGE", "AIN0_RESOLUTION_INDEX", "AIN1_RESOLUTION_INDEX"] values = [10.0, 10.0, 8, 8] # +/-10V range, resolution index 8 ljm.eWriteNames(handle, len(names), names, values) print("AIN configuration complete") except ljm.LJMError as e: print(f"Error at address {e.errorAddress}: {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Perform Burst Mode Streaming Capture Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Captures a fixed number of samples in burst mode, returning all data at once. This function is useful for high-speed data acquisition where a specific sample count is required. It requires an active LabJack handle and configuration of scan list, rate, and number of scans. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Configure stream channels scan_list_names = ["AIN0", "AIN1"] num_addresses = len(scan_list_names) scan_list = ljm.namesToAddresses(num_addresses, scan_list_names)[0] # Burst parameters scan_rate = 10000 # 10 kHz sample rate num_scans = 1000 # Capture 1000 scans # Perform burst capture (blocking call) actual_rate, data = ljm.streamBurst(handle, num_addresses, scan_list, scan_rate, num_scans) print(f"Captured {num_scans} scans at {actual_rate:.0f} Hz") print(f"Total samples: {len(data)} ({len(data)//num_addresses} scans x {num_addresses} channels)") # Extract channel data ain0_data = data[0::2] # Every other sample starting at 0 ain1_data = data[1::2] # Every other sample starting at 1 print(f"AIN0 range: {min(ain0_data):.4f}V to {max(ain0_data):.4f}V") print(f"AIN1 range: {min(ain1_data):.4f}V to {max(ain1_data):.4f}V") except ljm.LJMError as e: print(f"Burst error: {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Read Multiple Registers by Name using eReadNames in Python Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Reads multiple values from LabJack device registers in a single call, improving efficiency over individual reads. This function takes an active device handle, the number of registers to read, and a list of register names. It returns a list of corresponding values. Error handling for LJM errors is included. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Read multiple analog inputs at once names = ["AIN0", "AIN1", "AIN2", "AIN3"] num_frames = len(names) values = ljm.eReadNames(handle, num_frames, names) for name, value in zip(names, values): print(f"{name}: {value:.4f} V") # Expected output: # AIN0: 1.2345 V # AIN1: 0.5678 V # AIN2: 2.3456 V # AIN3: 0.1234 V # Read mixed register types names = ["AIN0", "FIO0", "SERIAL_NUMBER", "TEMPERATURE_DEVICE_K"] values = ljm.eReadNames(handle, len(names), names) print(f"Analog voltage: {values[0]:.4f} V") print(f"Digital state: {int(values[1])}") print(f"Serial: {int(values[2])}") print(f"Temperature: {values[3] - 273.15:.1f} C") except ljm.LJMError as e: print(f"Error at address {e.errorAddress}: {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Read Single Register by Name using eReadName in Python Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Reads a single value from a LabJack device register using its name. This function is commonly used for reading analog inputs, digital states, and device information. It requires an active device handle and the register name as input, returning the register's value. Error handling for LJM errors is included. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Read analog input AIN0 (returns voltage) voltage = ljm.eReadName(handle, "AIN0") print(f"AIN0 voltage: {voltage:.4f} V") # Expected output: AIN0 voltage: 1.2345 V # Read device serial number serial = ljm.eReadName(handle, "SERIAL_NUMBER") print(f"Serial Number: {int(serial)}") # Expected output: Serial Number: 470012345 # Read digital input state (0 or 1) dio_state = ljm.eReadName(handle, "FIO0") print(f"FIO0 state: {int(dio_state)}") # Expected output: FIO0 state: 1 # Read device temperature (internal sensor) temp_k = ljm.eReadName(handle, "TEMPERATURE_DEVICE_K") temp_c = temp_k - 273.15 print(f"Device temperature: {temp_c:.1f} C") # Expected output: Device temperature: 32.5 C # Read firmware version firmware = ljm.eReadName(handle, "FIRMWARE_VERSION") print(f"Firmware version: {firmware}") # Expected output: Firmware version: 1.0298 except ljm.LJMError as e: print(f"LJM Error: {e.errorCode} - {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### I2C/SPI Byte-Level Read/Write with eWriteNameByteArray and eReadNameByteArray Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Performs byte-level read and write operations for protocols like I2C, SPI, and EEPROM access. This function requires configuring I2C settings such as SDA/SCL pins, speed, and slave address before executing read or write commands. It returns read data as a byte array and accepts data to write as a list of integers. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Configure I2C settings ljm.eWriteName(handle, "I2C_SDA_DIONUM", 1) # SDA on FIO1 ljm.eWriteName(handle, "I2C_SCL_DIONUM", 0) # SCL on FIO0 ljm.eWriteName(handle, "I2C_SPEED_THROTTLE", 65516) # ~100 kHz ljm.eWriteName(handle, "I2C_OPTIONS", 0) ljm.eWriteName(handle, "I2C_SLAVE_ADDRESS", 80) # EEPROM address 0x50 # Read 4 bytes from EEPROM address 0 ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 1) ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 4) # Write memory address pointer ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", 1, [0]) # Address 0 ljm.eWriteName(handle, "I2C_GO", 1) # Execute I2C transaction # Read the response bytes data = ljm.eReadNameByteArray(handle, "I2C_DATA_RX", 4) print(f"EEPROM bytes [0-3]: {[int(b) for b in data]}") # Expected output: EEPROM bytes [0-3]: [72, 101, 108, 108] # Write 4 bytes to EEPROM ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 5) ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 0) # Byte 0 = memory address, Bytes 1-4 = data to write write_data = [0, 65, 66, 67, 68] # Address 0, then 'A', 'B', 'C', 'D' ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", 5, write_data) ljm.eWriteName(handle, "I2C_GO", 1) print("Wrote bytes to EEPROM") except ljm.LJMError as e: print(f"LJM Error: {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Write Single Register by Name using eWriteName in Python Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Writes a single value to a LabJack device register using its name. This function is used for setting analog outputs, digital states, and configuration registers. It requires an active device handle, the register name, and the value to write. Error handling for LJM errors is included. ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Set DAC0 output to 2.5V ljm.eWriteName(handle, "DAC0", 2.5) print("DAC0 set to 2.5 V") # Set DAC1 output to 0V ljm.eWriteName(handle, "DAC1", 0.0) print("DAC1 set to 0.0 V") # Set digital output FIO0 high (1) ljm.eWriteName(handle, "FIO0", 1) print("FIO0 set HIGH") # Set digital output FIO1 low (0) ljm.eWriteName(handle, "FIO1", 0) print("FIO1 set LOW") # Configure AIN0 range to +/-10V (T7/T8) ljm.eWriteName(handle, "AIN0_RANGE", 10.0) print("AIN0 range set to +/-10V") # Configure AIN0 resolution index (0-12, higher = more resolution) ljm.eWriteName(handle, "AIN0_RESOLUTION_INDEX", 8) print("AIN0 resolution index set to 8") except ljm.LJMError as e: print(f"LJM Error: {e.errorCode} - {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Convert Thermocouple Voltage to Temperature Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Calculates the temperature from a thermocouple voltage reading, incorporating cold junction compensation. This function requires the thermocouple type, the voltage reading, and the cold junction temperature in Kelvin. It supports various thermocouple types (e.g., Type K, J, T). ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Read cold junction temperature (internal sensor) cj_temp_k = ljm.eReadName(handle, "TEMPERATURE_DEVICE_K") # Read thermocouple voltage on AIN0 (in volts) tc_volts = ljm.eReadName(handle, "AIN0") # Convert to temperature using Type K thermocouple constants tc_temp_k = ljm.tcVoltsToTemp(ljm.constants.ttK, tc_volts, cj_temp_k) tc_temp_c = tc_temp_k - 273.15 print(f"Cold junction: {cj_temp_k - 273.15:.1f} C") print(f"TC voltage: {tc_volts * 1000:.3f} mV") print(f"TC temperature: {tc_temp_c:.1f} C") # Thermocouple type constants # ljm.constants.ttB = B-type # ljm.constants.ttE = E-type # ljm.constants.ttJ = J-type # ljm.constants.ttK = K-type # ljm.constants.ttN = N-type # ljm.constants.ttR = R-type # ljm.constants.ttS = S-type # ljm.constants.ttT = T-type # ljm.constants.ttC = C-type except ljm.LJMError as e: print(f"Error: {e.errorString}") finally: ljm.close(handle) ``` -------------------------------- ### Convert LabJack Error Code to String Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Converts a LabJack error code into a human-readable error string using the `ljm.errorToString()` function. This is useful for debugging and providing informative error messages to users. ```python from labjack import ljm # Convert error code to string error_string = ljm.errorToString(1227) print(f"Error 1227: {error_string}") # Expected output: Error 1227: LJME_DEVICE_NOT_FOUND ``` -------------------------------- ### eReadName - Read Single Register by Name Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Reads a single value from a device register using its name. This is commonly used for reading analog inputs, digital states, and device information. ```APIDOC ## eReadName - Read Single Register by Name ### Description Reads a single value from a device register using the register name. This is the most common method for reading analog inputs, digital states, and device information. ### Method `eReadName` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Read analog input AIN0 (returns voltage) voltage = ljm.eReadName(handle, "AIN0") print(f"AIN0 voltage: {voltage:.4f} V") # Read device serial number serial = ljm.eReadName(handle, "SERIAL_NUMBER") print(f"Serial Number: {int(serial)}") # Read digital input state (0 or 1) dio_state = ljm.eReadName(handle, "FIO0") print(f"FIO0 state: {int(dio_state)}") # Read device temperature (internal sensor) temp_k = ljm.eReadName(handle, "TEMPERATURE_DEVICE_K") temp_c = temp_k - 273.15 print(f"Device temperature: {temp_c:.1f} C") # Read firmware version firmware = ljm.eReadName(handle, "FIRMWARE_VERSION") print(f"Firmware version: {firmware}") except ljm.LJMError as e: print(f"LJM Error: {e.errorCode} - {e.errorString}") finally: ljm.close(handle) ``` ### Response #### Success Response (200) - **value** (float or int) - The value read from the specified register. #### Response Example ```json { "value": 1.2345 } ``` ``` -------------------------------- ### eWriteName - Write Single Register by Name Source: https://context7.com/labjack/labjack-ljm-python/llms.txt Writes a single value to a device register using its name. This function is used for setting analog outputs, digital states, and configuration registers. ```APIDOC ## eWriteName - Write Single Register by Name ### Description Writes a single value to a device register using the register name. Used for setting analog outputs, digital states, and configuration registers. ### Method `eWriteName` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") try: # Set DAC0 output to 2.5V ljm.eWriteName(handle, "DAC0", 2.5) print("DAC0 set to 2.5 V") # Set DAC1 output to 0V ljm.eWriteName(handle, "DAC1", 0.0) print("DAC1 set to 0.0 V") # Set digital output FIO0 high (1) ljm.eWriteName(handle, "FIO0", 1) print("FIO0 set HIGH") # Set digital output FIO1 low (0) ljm.eWriteName(handle, "FIO1", 0) print("FIO1 set LOW") # Configure AIN0 range to +/-10V (T7/T8) ljm.eWriteName(handle, "AIN0_RANGE", 10.0) print("AIN0 range set to +/-10V") # Configure AIN0 resolution index (0-12, higher = more resolution) ljm.eWriteName(handle, "AIN0_RESOLUTION_INDEX", 8) print("AIN0 resolution index set to 8") except ljm.LJMError as e: print(f"LJM Error: {e.errorCode} - {e.errorString}") finally: ljm.close(handle) ``` ### Response #### Success Response (200) Indicates the write operation was successful. Typically returns no specific data, but exceptions are raised on failure. #### Response Example ```json { "status": "success" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.