def ReadRegister(self, name): with self.lock: if name not in self.driver.registers: raise LabJackException("%s not a register", LJD_NOT_A_VALID_REGISTER) type_info = self.driver._typeraw(name) print("Read: type_info for %s is %s" % (name, type_info)) if 'R' not in self.driver.registers[name]['readwrite']: raise LabJackException("Cannot read %s" % name, LJD_REGISTER_NOT_READABLE) if type_info in ["INT16", "INT32", "UINT16", "UINT32"]: value = int(ljm.eReadName(self.handle, name)) elif type_info in ["STRING"]: value = ljm.eReadNameString(self.handle, name) elif type_info in ["FLOAT32", "FLOAT64"]: value = ljm.eReadName(self.handle, name) else: raise LabJackException( "%s type unknown for %s" % (type_info, name), LJD_UNKNOWN_TYPE) info = self.driver.registers[name] if "constants" in info: if value in info["constants"]: value = info["constants"][value] return value
""" Demonstrates how to read the device name string from a LabJack. """ from labjack import ljm # Open first found LabJack handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # handle = ljm.openS("ANY", "ANY", "ANY") info = ljm.getHandleInfo(handle) print( "Opened a LabJack with Device type: %i, Connection type: %i,\n" "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]) ) # Call eReadNameString to read the name string from the LabJack. string = ljm.eReadNameString(handle, "DEVICE_NAME_DEFAULT") print("\nDevice name : %s" % string) # Close handle ljm.close(handle)
https://labjack.com/support/software/api/ljm/function-reference/ljmereadnamestring T-Series and I/O: Modbus Map: https://labjack.com/support/software/api/modbus/modbus-map Hardware Overview(Device Information Registers): https://labjack.com/support/datasheets/t-series/hardware-overview """ from labjack import ljm # Open first found LabJack handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier info = ljm.getHandleInfo(handle) print("Opened a LabJack with Device type: %i, Connection type: %i,\n" "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) # Call eReadNameString to read the name string from the LabJack. string = ljm.eReadNameString(handle, "DEVICE_NAME_DEFAULT") print("\nDevice name : %s" % string) # Close handle ljm.close(handle)
"Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) if info[0] == ljm.constants.dtT4: print("\nThe LabJack T4 does not support WiFi.") sys.exit() # Setup and call eReadNames to read WiFi configuration from the LabJack. names = [ "WIFI_IP", "WIFI_SUBNET", "WIFI_GATEWAY", "WIFI_DHCP_ENABLE", "WIFI_IP_DEFAULT", "WIFI_SUBNET_DEFAULT", "WIFI_GATEWAY_DEFAULT", "WIFI_DHCP_ENABLE_DEFAULT", "WIFI_STATUS" ] numFrames = len(names) results = ljm.eReadNames(handle, numFrames, names) print("\nWiFi configuration: ") for i in range(numFrames): if names[i] == "WIFI_STATUS" or names[i].startswith("WIFI_DHCP_ENABLE"): print(" %s : %.0f" % (names[i], results[i])) else: print(" %s : %.0f - %s" % (names[i], results[i], ljm.numberToIP(int(results[i])))) # Setup and call eReadNameString to read the WiFi SSID string from the LabJack. name = "WIFI_SSID" result = ljm.eReadNameString(handle, name) print(" %s : %s" % (name, result)) # Close handle ljm.close(handle)
#handle = ljm.openS("ANY", "ANY", "ANY") info = ljm.getHandleInfo(handle) print("Opened a LabJack with Device type: %i, Connection type: %i,\n" \ "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % \ (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) # Setup and call eReadNames to read WiFi configuration from the LabJack. names = ["WIFI_IP", "WIFI_SUBNET", "WIFI_GATEWAY", "WIFI_DHCP_ENABLE", "WIFI_IP_DEFAULT", "WIFI_SUBNET_DEFAULT", "WIFI_GATEWAY_DEFAULT", "WIFI_DHCP_ENABLE_DEFAULT", "WIFI_STATUS"] numFrames = len(names) results = ljm.eReadNames(handle, numFrames, names) print("\neWifi configuration: ") for i in range(numFrames): if names[i] == "WIFI_STATUS" or names[i].startswith("WIFI_DHCP_ENABLE"): print(" %s : %.0f" % (names[i], results[i])) else: print(" %s : %.0f - %s" % \ (names[i], results[i], ljm.numberToIP(int(results[i])))) # Setup and call eReadNameString to read the WiFi SSID string from the LabJack. name = "WIFI_SSID" result = ljm.eReadNameString(handle, name) print(" %s : %s" % (name, result)) # Close handle ljm.close(handle)
def __getName(self): name = ljm.eReadNameString(self.handle, "DEVICE_NAME_DEFAULT") return name