def print_device_info(handle): 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\n" % \ (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]) )
def displayDeviceInfo(functionName, info): print("\n%s found %i LabJacks:\n" % (functionName, info[0])) fmt = ''.join(["{%i:<18}" % i for i in range(0, 4)]) print(fmt.format("Device Type", "Connection Type", "Serial Number", \ "IP Address")) for i in range(info[0]): print(fmt.format(DEVICE_TYPES.setdefault(info[1][i], str(info[1][i])), \ CONN_TYPES.setdefault(info[2][i], str(info[2][i])), \ str(info[3][i]), \ ljm.numberToIP(info[4][i])))
def Init(): # Open first found LabJack handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") #handle = ljm.openS("ANY", "ANY", "ANY") #A2D setup 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 eWriteNames to configure AINs on the LabJack. numFrames = 3 names = ["AIN_ALL_NEGATIVE_CH", "AIN_ALL_RANGE", "AIN_ALL_RESOLUTION_INDEX"] aValues = [199, 10, 1] ljm.eWriteNames(handle, numFrames, names, aValues) #return handle, Info return handle
import time import sys from datetime import datetime MAX_REQUESTS = 5 # The number of eStreamRead calls that will be performed. # Open first found LabJack handle = ljm.openS("ANY", "ANY", "ANY") # handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "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 Stream Out OUT_NAMES = ["FIO_STATE", "DAC0"] NUM_OUT_CHANNELS = len(OUT_NAMES) outAddress = ljm.nameToAddress(OUT_NAMES[0])[0] # Allocate memory for the stream-out buffer ljm.eWriteName(handle, "STREAM_OUT2_TARGET", outAddress) ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_SIZE", 512) ljm.eWriteName(handle, "STREAM_OUT2_ENABLE", 1) # Write values to the stream-out buffer ljm.eWriteName(handle, "STREAM_OUT2_LOOP_SIZE", 8)
""" Demonstrates how to configure the WiFi settings on 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])) # Setup and call eWriteNames to configure WiFi default settings on the LabJack. numFrames = 3 names = ["WIFI_IP_DEFAULT", "WIFI_SUBNET_DEFAULT", "WIFI_GATEWAY_DEFAULT"] aValues = [ljm.ipToNumber("192.168.1.207"), ljm.ipToNumber("255.255.255.0"), ljm.ipToNumber("192.168.1.1")] ljm.eWriteNames(handle, numFrames, names, aValues) print("\nSet WiFi configuration:") for i in range(numFrames): print(" %s : %.0f - %s" % \ (names[i], aValues[i], ljm.numberToIP(aValues[i]))) # Setup and call eWriteString to configure the default WiFi SSID on the LabJack.
""" Demonstrates how to read the WiFi configuration 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])) # 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]))))
def getDetails(self): info = self.Handle.getHandleInfo(self.Handle.handle) return "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])
names = ["DIO0_EF_VALUE_A"] values = [time2clock(time_us)] class DAC(): def __init__(self,device,channel): self.lj = device self.ch = str(channel) def set_v(self,value): """value """ name = ["DAC" + self.ch] self.lj.write(name,[value]) if __name__ == "__main__": import time lj = LabJack() 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" % \ (lj.info[0], lj.info[1], lj.info[2], ljm.numberToIP(lj.info[3]), lj.info[4], lj.info[5])) #out0 = LJChannel(lj,0) dac = DAC(lj,0) dac.set_v(3) time.sleep(3) dac.set_v(0)
import time import logging import sys from datetime import datetime MAX_REQUESTS = 5 # The number of eStreamRead calls that will be performed. print "Here.. " # Open first found T7 LabJack #handle = ljm.openS("T7", "USB", "ANY") handle = ljm.openS("T7", "ETHERNET", "142.90.151.7") print "He.. " 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 eWriteNames to configure AINs on the LabJack. numChannels = 32 numFrames = numChannels * 3 # Generate lists with channel number pairings which # match the MUX80 data sheet for Differential readings pChan = range(48, 56) + range(64, 72) + range(80, 88) + range(96, 104) nChan = range(56, 64) + range(72, 80) + range(88, 96) + range(104, 112) #List of analog input names ChanNames = [] for p in pChan: ChanNames = ChanNames + ["AIN%d" % p] # Stream Configuration
Demonstrates how to read the ethernet configuration settings from a LabJack. """ 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])) # Setup and call eReadNames to read ethernet configuration from the LabJack. names = [ "ETHERNET_IP", "ETHERNET_SUBNET", "ETHERNET_GATEWAY", "ETHERNET_IP_DEFAULT", "ETHERNET_SUBNET_DEFAULT", "ETHERNET_GATEWAY_DEFAULT", "ETHERNET_DHCP_ENABLE", "ETHERNET_DHCP_ENABLE_DEFAULT" ] numFrames = len(names) results = ljm.eReadNames(handle, numFrames, names) print("\nEthernet configuration:") for i in range(numFrames): if names[i].startswith("ETHERNET_DHCP_ENABLE"): print(" %s : %.0f" % (names[i], results[i]))
Demonstrates how to set ethernet configuration settings on a LabJack. """ 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])) # Setup and call eWriteNames to set the ethernet configuration on the LabJack. numFrames = 4 names = [ "ETHERNET_IP_DEFAULT", "ETHERNET_SUBNET_DEFAULT", "ETHERNET_GATEWAY_DEFAULT", "ETHERNET_DHCP_ENABLE_DEFAULT" ] values = [ ljm.ipToNumber("192.168.1.207"), ljm.ipToNumber("255.255.255.0"), ljm.ipToNumber("192.168.1.1"), 1 ] ljm.eWriteNames(handle, numFrames, names, values) print("\nSet ethernet configuration:")