示例#1
0
    def set_cmd(self, *cmd):
        """
    Convert the tension value to a digital value and send it to the output.

    Note that once a value has been written, it will not be written again until
    it changes! This is meant to lower the communication and Labjack activity.
    It relies on the fact that these registers will not change between writes.
    (Which is true unless the card runs a lua script writing the same registers
    as the user).
    """
        #values = []
        #for val,chan in zip(cmd,self.out_chan_list):
        #  values.append(chan['gain']*val+chan['offset'])
        #ljm.eWriteAddresses(self.handle,len(self.write_addresses),
        #    self.write_addresses,self.write_types,values)
        addresses, types, values = [], [], []
        for i, (a, t, v, o, c) in enumerate(
                zip(self.write_addresses, self.write_types, cmd,
                    self.last_values, self.out_chan_list)):
            if v != o:
                new_v = c['gain'] * v + c['offset']
                if c['limits']:
                    new_v = clamp(new_v, c['limits'][0], c['limits'][1])
                self.last_values[i] = v
                addresses.append(a)
                types.append(t)
                values.append(new_v)
        if addresses:
            ljm.eWriteAddresses(self.handle, len(addresses), addresses, types,
                                values)
示例#2
0
 def open(self):
     self.handle = ljm.openS(self.device, self.connection, self.identifier)
     # ==== Writing initial config ====
     reg, types, values = [], [], []
     for c in self.in_chan_list + self.out_chan_list:
         # Turn (name,val) tuples to (addr,type,val)
         for i, t in enumerate(c.get('write_at_open', [])):
             if len(t) == 2:
                 c['write_at_open'][i] = ljm.nameToAddress(t[0]) + (t[1], )
         # Write everything we need
         for r, t, v in c.get('write_at_open', []):
             reg.append(r)
             types.append(t)
             values.append(v)
     if reg:
         ljm.eWriteAddresses(self.handle, len(reg), reg, types, values)
     # ==== Recap of the addresses to read/write ====
     self.read_addresses = [c['to_read'] for c in self.in_chan_list]
     self.read_types = [c['dtype'] for c in self.in_chan_list]
     self.write_addresses = [c['to_write'] for c in self.out_chan_list]
     self.write_types = [c['dtype'] for c in self.out_chan_list]
     self.last_values = [None] * len(self.write_addresses)
     # ==== Measuring zero to add to the offset (if asked to) ====
     if any([c.get("make_zero", False) for c in self.in_chan_list]):
         print("[Labjack] Please wait during offset evaluation...")
         off = self.eval_offset()
         names, values = [], []
         for i, c in enumerate(self.in_chan_list):
             if 'make_zero' in c and c['make_zero']:
                 names.append(c['name'] + '_EF_CONFIG_E')
                 values.append(c['offset'] + off[i])
         ljm.eWriteNames(self.handle, len(names), names, values)
  def set_cmd(self, *cmd):
    """
    Convert the tension value to a digital value and send it to the output.

    Note that once a value has been written, it will not be written again until
    it changes! This is meant to lower the communication and Labjack activity.
    It relies on the fact that these registers will not change between writes.
    (Which is true unless the card runs a lua script writing the same registers
    as the user).
    """
    #values = []
    #for val,chan in zip(cmd,self.out_chan_list):
    #  values.append(chan['gain']*val+chan['offset'])
    #ljm.eWriteAddresses(self.handle,len(self.write_addresses),
    #    self.write_addresses,self.write_types,values)
    addresses,types,values = [],[],[]
    for i,(a,t,v,o,c) in enumerate(zip(
        self.write_addresses,self.write_types,
        cmd,self.last_values,self.out_chan_list)):
      if v != o:
        new_v = c['gain']*v+c['offset']
        if c['limits']:
          new_v = clamp(new_v,c['limits'][0],c['limits'][1])
        self.last_values[i] = v
        addresses.append(a)
        types.append(t)
        values.append(new_v)
    if addresses:
      ljm.eWriteAddresses(self.handle,len(addresses),addresses,types,values)
 def open(self):
   self.handle = ljm.openS(self.device,self.connection,self.identifier)
   # ==== Writing initial config ====
   reg,types,values = [],[],[]
   for c in self.in_chan_list+self.out_chan_list:
     # Turn (name,val) tuples to (addr,type,val)
     for i,t in enumerate(c.get('write_at_open',[])):
       if len(t) == 2:
         c['write_at_open'][i] = ljm.nameToAddress(t[0])+(t[1],)
     # Write everything we need
     for r,t,v in c.get('write_at_open',[]):
       reg.append(r)
       types.append(t)
       values.append(v)
   if reg:
     ljm.eWriteAddresses(self.handle,len(reg),reg,types,values)
   # ==== Recap of the addresses to read/write ====
   self.read_addresses = [c['to_read'] for c in self.in_chan_list]
   self.read_types = [c['dtype'] for c in self.in_chan_list]
   self.write_addresses = [c['to_write'] for c in self.out_chan_list]
   self.write_types = [c['dtype'] for c in self.out_chan_list]
   self.last_values = [None]*len(self.write_addresses)
   # ==== Measuring zero to add to the offset (if asked to) ====
   if any([c.get("make_zero",False) for c in self.in_chan_list]):
     print("[Labjack] Please wait during offset evaluation...")
     off = self.eval_offset()
     names,values = [],[]
     for i,c in enumerate(self.in_chan_list):
       if 'make_zero' in c and c['make_zero']:
         names.append(c['name']+'_EF_CONFIG_E')
         values.append(c['offset']+off[i])
     ljm.eWriteNames(self.handle,len(names),names,values)
示例#5
0
def main(handle, numTC, numK):
    from labjack import ljm
    aAddresses = {}
    aDataTypes = {}
    aValues = {}
    # Setup AIN0-AIN10 for T-type TC
    # Set TC type
    aAddresses['AIN#_EF_INDEX'] = []  # [Set TC type address]
    aDataTypes['AIN#_EF_INDEX'] = []  # [Set TC type as int]
    aValues['AIN#_EF_INDEX'] = []  # [Set TC type, 24 for T-type]
    # Set negative channel
    aAddresses['AIN#_NEGATIVE_CH'] = [
    ]  # [Set TC negative channel for differential measurement]
    aDataTypes['AIN#_NEGATIVE_CH'] = [
    ]  # [Set TC negative channel type as int]
    aValues['AIN#_NEGATIVE_CH'] = []  # [Set TC negative channel, AIN(n+1)]
    TC_AINp = 48
    TC_AINn = TC_AINp + 8
    for i in range(numTC):
        aAddresses['AIN#_EF_INDEX'].append(9000 + 2 * (i + TC_AINp))
        aDataTypes['AIN#_EF_INDEX'].append(ljm.constants.UINT32)
        aValues['AIN#_EF_INDEX'].append(24)
        aAddresses['AIN#_NEGATIVE_CH'].append(41000 + i + TC_AINp)
        aDataTypes['AIN#_NEGATIVE_CH'].append(ljm.constants.UINT16)
        aValues['AIN#_NEGATIVE_CH'].append(i + TC_AINn)
    ljm.eWriteAddresses(handle, numTC, aAddresses['AIN#_EF_INDEX'],
                        aDataTypes['AIN#_EF_INDEX'], aValues['AIN#_EF_INDEX'])
    ljm.eWriteAddresses(handle, numTC, aAddresses['AIN#_NEGATIVE_CH'],
                        aDataTypes['AIN#_NEGATIVE_CH'],
                        aValues['AIN#_NEGATIVE_CH'])
    # Setup and call eReadAddresses to read values from the LabJack.
    aAddresses['TC'] = []  # [T-type temperature]
    aAddresses['Voltage_TC'] = []  # [T-type voltage]
    aAddresses['TEMPERATURE_DEVICE_K'] = []  # [Reference temperature sensors]
    aDataTypes['TC'] = [
    ]  # [Data types for temperature and voltage measurements]
    aDataTypes['TEMPERATURE_DEVICE_K'] = [
    ]  # [Data types for temperature and voltage measurements]
    # Loop over addresses
    for i in range(numTC):
        aAddresses['TC'].append(7000 + 2 * (i + TC_AINp))
        aAddresses['Voltage_TC'].append(7300 + 2 * (i + TC_AINp))
        aDataTypes['TC'].append(ljm.constants.FLOAT32)
    for i in range(numK):
        aAddresses['TEMPERATURE_DEVICE_K'].append(60050 + 2 * i)
        aDataTypes['TEMPERATURE_DEVICE_K'].append(ljm.constants.FLOAT32)
    return aAddresses, aDataTypes, aValues
示例#6
0
def main(handle):
    from labjack import ljm
    aAddresses = {}
    aDataTypes = {}
    aValues = {}
    # Setup and call eReadAddresses to read values from the LabJack.
    aAddresses['FRG'] = []  # [Pheifer Full Range Gauge]
    aAddresses['Voltage_FRG'] = [] # [FRG voltage]
    aDataTypes['FRG'] = [] # [Data types for pressure and voltage measurements]
    ###########################################################################
    # AIN for FRG
    AINp = 8
    AINn = AINp+1
    # Converts the FRG Voltage to deg K
    VAL = [1,10/6,-10/6*6.8]
    #VAL = [1,1,0]
    TYPE = [1,3,3]
    REG = [9000,10200,10500]
    # Clear EF dictionary entries
    aAddresses['AIN#_EF_INDEX'] = []  # [Set EF type address]
    aDataTypes['AIN#_EF_INDEX'] = []  # [Set EF type as int]
    aValues['AIN#_EF_INDEX'] = []  # [Set EF type, 1 for offset/slope]
    # Initialize EF negative channel
    aAddresses['AIN#_NEGATIVE_CH'] = []  # [Set EF negative channel for differential measurement]
    aDataTypes['AIN#_NEGATIVE_CH'] = []  # [Set EF negative channel type as int]
    aValues['AIN#_NEGATIVE_CH'] = []  # [Set EF negative channel, AIN(n+8) with MUX80]
    # Write K EF parameters
    for i in range(len(VAL)):
        aAddresses['AIN#_EF_INDEX'].append(REG[i]+2*AINp)
        aDataTypes['AIN#_EF_INDEX'].append(TYPE[i])
        aValues['AIN#_EF_INDEX'].append(VAL[i])
    aAddresses['AIN#_NEGATIVE_CH'].append(41000+i+AINp)
    aDataTypes['AIN#_NEGATIVE_CH'].append(ljm.constants.UINT16)
    aValues['AIN#_NEGATIVE_CH'].append(i+AINn)
    ljm.eWriteAddresses(handle, len(aAddresses['AIN#_EF_INDEX']), aAddresses['AIN#_EF_INDEX'], aDataTypes['AIN#_EF_INDEX'], aValues['AIN#_EF_INDEX'])
    ljm.eWriteAddresses(handle, len(['AIN#_NEGATIVE_CH']), aAddresses['AIN#_NEGATIVE_CH'], aDataTypes['AIN#_NEGATIVE_CH'], aValues['AIN#_NEGATIVE_CH'])
    # Write address for EF value
    aAddresses['FRG'].append(7000+2*AINp)
    aAddresses['Voltage_FRG'].append(7300+2*AINp)
    aDataTypes['FRG'].append(ljm.constants.FLOAT32)
    return aAddresses, aDataTypes, aValues
示例#7
0
    def writeActuators(self):
        try:
            if self.ui.mainValveButton.isChecked():
                self.ui.mainValveButton.setIcon(self.openValveIcon)
                self.mainValveState = True
            else:
                self.ui.mainValveButton.setIcon(self.closedValveIcon)
                self.mainValveState = False

            if self.ui.ventValveButton.isChecked():
                self.ui.ventValveButton.setIcon(self.openValveIcon)
                self.ventValveState = True
            else:
                self.ui.ventValveButton.setIcon(self.closedValveIcon)
                self.ventValveState = False

            # ljm.eWriteAddress(self.handle, self.ventValveAddress, ljm.constants.UINT16, not self.ventValveState)
            ljm.eWriteAddresses(
                self.handle, len(self.actuatorsAddresses),
                self.actuatorsAddresses, self.actuatorsDataTypes,
                [not self.ventValveState, not self.mainValveState])
        finally:
            QtCore.QTimer.singleShot(self.actuatorsUpdateIntervalMs,
                                     self.writeActuators)
示例#8
0
def main(handle):
    from labjack import ljm
    aAddresses = {}
    aDataTypes = {}
    aValues = {}
    # Setup AIN for EF
    # Set EF type
    aAddresses['AIN#_EF_INDEX'] = []  # [Set EF type address]
    aDataTypes['AIN#_EF_INDEX'] = []  # [Set EF type as int]
    aValues['AIN#_EF_INDEX'] = []  # [Set EF type, 0 for None]
    AINp = 0
    for i in range(numRES):
        aAddresses['AIN#_EF_INDEX'].append(9000+2*(i+AINp))
        aDataTypes['AIN#_EF_INDEX'].append(ljm.constants.UINT32)
        aValues['AIN#_EF_INDEX'].append(0)
    ljm.eWriteAddresses(handle, numRES, aAddresses['AIN#_EF_INDEX'], aDataTypes['AIN#_EF_INDEX'], aValues['AIN#_EF_INDEX'])
    # Setup and call eReadAddresses to read values from the LabJack.
    aAddresses['RES'] = []  # [Fill level]
    aDataTypes['RES'] = [] # [Data types for temperature and voltage measurements]
    # Loop over addresses
    for i in range(numRES):
        aAddresses['RES'].append(2*(i+AINp))
        aDataTypes['RES'].append(ljm.constants.FLOAT32)
    return aAddresses, aDataTypes, aValues
示例#9
0
"""

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 eWriteAddresses to write values to the LabJack.
numFrames = 2
aAddresses = [1000, 55110]  # [DAC0, TEST_UINT16]
aDataTypes = [ljm.constants.FLOAT32, ljm.constants.UINT16]
aValues = [2.5, 12345]  # [write 2.5 V, write 12345]
ljm.eWriteAddresses(handle, numFrames, aAddresses, aDataTypes, aValues)

print("\neWriteAddresses: ")
for i in range(numFrames):
    print("    Address - %i, data type - %i, value : %f" % (aAddresses[i], aDataTypes[i], aValues[i]))

# Close handle
ljm.close(handle)
示例#10
0
def main(handle):
    from labjack import ljm
    aAddresses = {}
    aDataTypes = {}
    aValues = {}
    # Setup and call eReadAddresses to read values from the LabJack.
    aAddresses['TC'] = []  # [T-type temperature]
    aAddresses['Voltage_TC'] = []  # [T-type voltage]
    aAddresses['K'] = []  # [Reference temperature sensors]
    aDataTypes['TC'] = [
    ]  # [Data types for temperature and voltage measurements]
    aDataTypes['K'] = [
    ]  # [Data types for temperature and voltage measurements]
    ###########################################################################
    # AIN for LM34
    AINk = 13
    # Converts the LM34 Voltage to deg K
    VAL = [1, 100 * 5 / 9, 273.15 - 32 * 5 / 9]
    TYPE = [1, 3, 3]
    REG = [9000, 10200, 10500]
    # Clear EF dictionary entries
    aAddresses['AIN#_EF_INDEX'] = []  # [Set EF type address]
    aDataTypes['AIN#_EF_INDEX'] = []  # [Set EF type as int]
    aValues['AIN#_EF_INDEX'] = []  # [Set EF type, 1 for offset/slope]
    # Write K EF parameters
    for i in range(len(VAL)):
        aAddresses['AIN#_EF_INDEX'].append(REG[i] + 2 * AINk)
        aDataTypes['AIN#_EF_INDEX'].append(TYPE[i])
        aValues['AIN#_EF_INDEX'].append(VAL[i])
    ljm.eWriteAddresses(handle, len(aAddresses['AIN#_EF_INDEX']),
                        aAddresses['AIN#_EF_INDEX'],
                        aDataTypes['AIN#_EF_INDEX'], aValues['AIN#_EF_INDEX'])
    # Write address for EF value
    aAddresses['K'].append(7000 + 2 * AINk)
    aDataTypes['K'].append(ljm.constants.FLOAT32)
    # Write address for LJ thermistor
    for i in range(refLJ):
        aAddresses['K'].append(60050 + 2 * i)
        aDataTypes['K'].append(ljm.constants.FLOAT32)
    ###########################################################################
    # Setup AIN for T-type TC
    # TC registry value
    AINp = 0
    AINn = AINp + 1
    # Alter CJC param
    REG[0] = 9600
    VAL[0] = 2 * AINk
    # Initialize EF dictionary
    aAddresses['AIN#_EF_INDEX'] = []  # [Set EF type address for TC]
    aDataTypes['AIN#_EF_INDEX'] = []  # [Set EF type as int]
    aValues['AIN#_EF_INDEX'] = []  # [Set EF type, 24 for T-type]
    # Initialize EF negative channel
    aAddresses['AIN#_NEGATIVE_CH'] = [
    ]  # [Set EF negative channel for differential measurement]
    aDataTypes['AIN#_NEGATIVE_CH'] = [
    ]  # [Set EF negative channel type as int]
    aValues['AIN#_NEGATIVE_CH'] = [
    ]  # [Set EF negative channel, AIN(n+8) with MUX80]
    # Write TC EF parameters
    for i in range(numTC):
        aAddresses['AIN#_EF_INDEX'].append(9000 + 2 * (2 * i + AINp))
        aDataTypes['AIN#_EF_INDEX'].append(ljm.constants.UINT32)
        aValues['AIN#_EF_INDEX'].append(24)
        # Write CJC EF parameters
        for j in range(len(VAL)):
            aAddresses['AIN#_EF_INDEX'].append(REG[j] + 2 * (2 * i + AINp))
            aDataTypes['AIN#_EF_INDEX'].append(TYPE[j])
            aValues['AIN#_EF_INDEX'].append(VAL[j])
#        aAddresses['AIN#_EF_INDEX'].append(9600+2*(i+AINp))
#        aDataTypes['AIN#_EF_INDEX'].append(ljm.constants.UINT32)
#        aValues['AIN#_EF_INDEX'].append(7000+2*AINk)
        aAddresses['AIN#_NEGATIVE_CH'].append(41000 + 2 * i + AINp)
        aDataTypes['AIN#_NEGATIVE_CH'].append(ljm.constants.UINT16)
        aValues['AIN#_NEGATIVE_CH'].append(2 * i + AINn)
    ljm.eWriteAddresses(handle, len(aAddresses['AIN#_EF_INDEX']),
                        aAddresses['AIN#_EF_INDEX'],
                        aDataTypes['AIN#_EF_INDEX'], aValues['AIN#_EF_INDEX'])
    ljm.eWriteAddresses(handle, len(['AIN#_NEGATIVE_CH']),
                        aAddresses['AIN#_NEGATIVE_CH'],
                        aDataTypes['AIN#_NEGATIVE_CH'],
                        aValues['AIN#_NEGATIVE_CH'])
    # Loop over addresses
    # Thermocouple addresses
    for i in range(numTC):
        aAddresses['TC'].append(7000 + 2 * (2 * i + AINp))
        aAddresses['Voltage_TC'].append(7300 + 2 * (2 * i + AINp))
        aDataTypes['TC'].append(ljm.constants.FLOAT32)
    return aAddresses, aDataTypes, aValues
示例#11
0
"""
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 eWriteAddresses to write values to the LabJack.
numFrames = 2
aAddresses = [1000, 55110]  # [DAC0, TEST_UINT16]
aDataTypes = [ljm.constants.FLOAT32, ljm.constants.UINT16]
aValues = [2.5, 12345]  # [write 2.5 V, write 12345]
ljm.eWriteAddresses(handle, numFrames, aAddresses, aDataTypes, aValues)

print("\neWriteAddresses: ")
for i in range(numFrames):
    print("    Address - %i, data type - %i, value : %f" %
          (aAddresses[i], aDataTypes[i], aValues[i]))

# Close handle
ljm.close(handle)