def eNamesIteration(handle, numFrames, names, aWrites, aNumValues, aValues, results): # Function for timit.Timer. Performs a eNames call to do LabJack operations. # Takes eNames parameters and a list for results which will be filled. del results[:] r = ljm.eNames(handle, numFrames, names, aWrites, aNumValues, aValues) results.extend(r)
def get_data(self): a_values = [0] * LEN_VALS a_values = ljm.eNames(self.lj_handle, NUM_FRAMES, A_NAMES, A_WRITES, A_NUM_VALS, a_values) self.monitor_points['ant_el'] = convert_encoder(a_values[0]) self.monitor_points['foc_temp'] = 50 * a_values[1] - 25 self.monitor_points['lna_a_current'] = 100 * a_values[2] self.monitor_points['rf_a_power'] = 28.571 * a_values[3] - 90 self.monitor_points['laser_a_voltage'] = a_values[4] self.monitor_points['feb_a_current'] = 1000 * a_values[5] self.monitor_points['feb_a_temp'] = 50 * a_values[6] - 25 self.monitor_points['lna_b_current'] = 1000 * a_values[7] self.monitor_points['rf_b_power'] = 28.571 * a_values[8] - 90 self.monitor_points['laser_b_voltage'] = a_values[9] self.monitor_points['feb_b_current'] = 100 * a_values[10] self.monitor_points['feb_b_temp'] = 50 * a_values[11] - 25 self.monitor_points['psu_voltage'] = a_values[12] self.monitor_points['lj_temp'] = a_values[14] - ABSOLUTE_ZERO dig_val = int(a_values[15]) self.monitor_points['drive_state'] = (dig_val >> 8) & 0b11 self.monitor_points['nd1'] = ~(dig_val >> 20) & 0b01 self.monitor_points['nd2'] = ~(dig_val >> 21) & 0b01 self.monitor_points['brake'] = (dig_val >> 16) & 0b01 self.monitor_points['plus_limit'] = (dig_val >> 17) & 0b01 self.monitor_points['minus_limit'] = (dig_val >> 18) & 0b01 self.monitor_points['fan_err'] = (dig_val >> 22) & 0b01 ts = float("{:.6f}".format(Time.now().mjd)) self.mp_q.post((ts, "ant{}".format(self.ant_num), self.monitor_points)) return self.monitor_points
def _get_data(self): """Read data from LJ T7 and insert into monitor point dictionary. Values are read from the current LabJack T7 in a single operation through the ljm driver. These are converted into the appropriate data types in the relevant units and put in the one-second cadence monitor point dictionary. """ a_values = [0] * self.LEN_VALS a_values = ljm.eNames(self.lj_handle, self.NUM_FRAMES, self.A_NAMES, self.A_WRITES, self.A_NUM_VALS, a_values) time_stamp = float("{:.8f}".format(Time.now().mjd)) self.monitor_points['time'] = float(time_stamp) self.monitor_points['ant_el'] = a_values[17] self.monitor_points['ant_cmd_el'] = a_values[16] self.monitor_points['ant_el_err'] = a_values[18] self.monitor_points['focus_temp'] = 100 * a_values[0] - 50 self.monitor_points['motor_temp'] = 100 * a_values[1] - 50 self.monitor_points['laser_volts_a'] = a_values[2] self.monitor_points['rf_pwr_a'] = 28.571 * a_values[3] - 90 self.monitor_points['feb_current_a'] = 1000 * a_values[4] self.monitor_points['lna_current_a'] = 100 * a_values[5] self.monitor_points['feb_temp_a'] = 100 * a_values[6] - 50 self.monitor_points['lna_current_b'] = 100 * a_values[7] self.monitor_points['rf_pwr_b'] = 28.571 * a_values[8] - 90 self.monitor_points['laser_volts_b'] = a_values[9] self.monitor_points['feb_current_b'] = 0.1000 * a_values[10] self.monitor_points['feb_temp_b'] = 100 * a_values[11] - 50 self.monitor_points['psu_volt'] = a_values[12] self.monitor_points['spare'] = a_values[13] self.monitor_points['lj_temp'] = a_values[14] - self.ABSOLUTE_ZERO dig_val = int(a_values[15]) self.monitor_points['emergency_off'] = bool((dig_val >> 8) & 0b01) self.monitor_points['drive_cmd'] = (dig_val >> 9) & 0b11 self.monitor_points['drive_act'] = (dig_val >> 14) & 0b11 self.monitor_points['drive_state'] = int(a_values[20]) self.monitor_points['brake_on'] = 1 - bool(((dig_val >> 13) & 0b01)) self.monitor_points['at_north_lim'] = bool(1 - ((dig_val >> 20) & 0b01)) self.monitor_points['at_south_lim'] = bool(1 - ((dig_val >> 21) & 0b01)) self.monitor_points['fan_err'] = bool((dig_val >> 22) & 0b01) self.monitor_points['noise_a_on'] = bool(1 - ((dig_val >> 11) & 0b01)) self.monitor_points['noise_b_on'] = bool(1 - ((dig_val >> 12) & 0b01)) return self.monitor_points
UINT16 = ljm.constants.UINT16 UINT32 = ljm.constants.UINT32 # Setup and call eNames to write/read values to/from the LabJack. # Write 2.5V to DAC0, # write 12345 to TEST_UINT16, # read TEST_UINT16, # read serial number, # read product ID, # and read firmware version. numFrames = 6 aNames = [ 'DAC0', 'TEST_UINT16', 'TEST_UINT16', 'SERIAL_NUMBER', 'PRODUCT_ID', 'FIRMWARE_VERSION' ] aWrites = [WRITE, WRITE, READ, READ, READ, READ] aNumValues = [1, 1, 1, 1, 1, 1] aValues = [2.5, 12345, 0, 0, 0, 0] results = ljm.eNames(handle, numFrames, aNames, aWrites, aNumValues, aValues) print("\neNames results: ") start = 0 for i in range(numFrames): end = start + aNumValues[i] print(" Name - %16s, write - %i, values %s" % (aNames[i], aWrites[i], results[start:end])) start = end # Close handle ljm.close(handle)
ljm.eWriteName(handle, "I2C_SLAVE_ADDRESS", 80) # Slave Address of the I2C chip = 80 (0x50) # Initial read of EEPROM bytes 0-3 in the user memory area. We need a single I2C # transmission that writes the chip's memory pointer and then reads the data. ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 1) # Set the number of bytes to transmit ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 4) # Set the number of bytes to receive # Set the TX bytes. We are sending 1 byte for the address. aNames = ["I2C_DATA_TX"] aWrites = [ljm.constants.WRITE] # Indicates we are writing the values. aNumValues = [1] # The number of bytes aValues = [0] # Byte 0: Memory pointer = 0 ljm.eNames(handle, len(aNames), aNames, aWrites, aNumValues, aValues) ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. # Read the RX bytes. aNames = ["I2C_DATA_RX"] aWrites = [ljm.constants.READ] # Indicates we are reading the values. aNumValues = [4] # The number of bytes # aValues[0] to aValues[3] will contain the data aValues = [0] * 4 aValues = ljm.eNames(handle, len(aNames), aNames, aWrites, aNumValues, aValues) print("\nRead User Memory [0-3] = %s" % \ " ".join([("%.0f"%val) for val in aValues])) # Write EEPROM bytes 0-3 in the user memory area, using the page write
ljm.eWriteName(handle, "I2C_OPTIONS", 0) # Options = 0 ljm.eWriteName(handle, "I2C_SLAVE_ADDRESS", 80) # Slave Address of the I2C chip = 80 (0x50) # Initial read of EEPROM bytes 0-3 in the user memory area. We need a single I2C # transmission that writes the chip's memory pointer and then reads the data. ljm.eWriteName(handle, "I2C_NUM_BYTES_TX", 1) # Set the number of bytes to transmit ljm.eWriteName(handle, "I2C_NUM_BYTES_RX", 4) # Set the number of bytes to receive # Set the TX bytes. We are sending 1 byte for the address. aNames = ["I2C_DATA_TX"] aWrites = [ljm.constants.WRITE] # Indicates we are writing the values. aNumValues = [1] # The number of bytes aValues = [0] # Byte 0: Memory pointer = 0 ljm.eNames(handle, len(aNames), aNames, aWrites, aNumValues, aValues) ljm.eWriteName(handle, "I2C_GO", 1) # Do the I2C communications. # Read the RX bytes. aNames = ["I2C_DATA_RX"] aWrites = [ljm.constants.READ] # Indicates we are reading the values. aNumValues = [4] # The number of bytes # aValues[0] to aValues[3] will contain the data aValues = [0]*4 aValues = ljm.eNames(handle, len(aNames), aNames, aWrites, aNumValues, aValues) print("\nRead User Memory [0-3] = %s" % \ " ".join([("%.0f"%val) for val in aValues]))
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 eNames to write/read values to/from the LabJack. numFrames = 3 names = ["DAC0", "TEST_UINT16", "TEST_UINT16"] aWrites = [ljm.constants.WRITE, ljm.constants.WRITE, ljm.constants.READ] aNumValues = [1, 1, 1] aValues = [2.5, 12345, 0] # [write 2.5 V, write 12345, read] results = ljm.eNames(handle, numFrames, names, aWrites, aNumValues, aValues) print("\neNames results: ") start = 0 for i in range(numFrames): end = start + aNumValues[i] print(" Name - %s, write - %i, values %s" % \ (names[i], aWrites[i], results[start:end])) start = end # Close handle ljm.close(handle)
for i in range(numFrames): print(" %s = %0.0f" % (aNames[i], aValues[i])) # Write(TX)/Read(RX) 4 bytes numBytes = 4; ljm.eWriteName(handle, "SPI_NUM_BYTES", numBytes) # Write the bytes dataWrite = [] dataWrite.extend([randrange(0, 256) for _ in range(numBytes)]) aNames = ["SPI_DATA_TX"] aWrites = [ljm.constants.WRITE] aNumValues = [numBytes]; dataWrite = ljm.eNames(handle, 1, aNames, aWrites, aNumValues, dataWrite) ljm.eWriteName(handle, "SPI_GO", 1) # Do the SPI communications # Display the bytes written print(""); for i in range(numBytes): print("dataWrite[%i] = %0.0f" % (i, dataWrite[i])) # Read the bytes dataRead = [0]*numBytes aNames = ["SPI_DATA_RX"] aWrites = [ljm.constants.READ] aNumValues = [numBytes]; dataRead = ljm.eNames(handle, 1, aNames, aWrites, aNumValues, dataRead)
print("SPI Configuration:") for i in range(numFrames): print(" %s = %0.0f" % (aNames[i], aValues[i])) # Write(TX)/Read(RX) 4 bytes numBytes = 4 ljm.eWriteName(handle, "SPI_NUM_BYTES", numBytes) # Write the bytes dataWrite = [] dataWrite.extend([randrange(0, 256) for _ in range(numBytes)]) aNames = ["SPI_DATA_TX"] aWrites = [ljm.constants.WRITE] aNumValues = [numBytes] dataWrite = ljm.eNames(handle, 1, aNames, aWrites, aNumValues, dataWrite) ljm.eWriteName(handle, "SPI_GO", 1) # Do the SPI communications # Display the bytes written print("") for i in range(numBytes): print("dataWrite[%i] = %0.0f" % (i, dataWrite[i])) # Read the bytes dataRead = [0] * numBytes aNames = ["SPI_DATA_RX"] aWrites = [ljm.constants.READ] aNumValues = [numBytes] dataRead = ljm.eNames(handle, 1, aNames, aWrites, aNumValues, dataRead) ljm.eWriteName(handle, "SPI_GO", 1)