def __getLOFreq(self):
     rightBit = ljm.eReadName(self.handle, "EIO3")
     leftBit = ljm.eReadName(self.handle, "EIO4")
     
     setting = leftBit * 2 + rightBit
     freqName = self.LOConstantNames[setting]
     return freqName, setting
 def __getitem__(self,chan):
   """
   Allows reading of an input chan by calling lj[chan]
   """
   # Apply offsets and stuff if this is a channel we know
   try:
     return time(),ljm.eReadName(
         self.handle,self.in_chan_dict[chan]['to_read'])
   # Else: let the user access it directly
   except KeyError:
     return time(),ljm.eReadName(self.handle,chan)
 def open(self):
   self.handle = ljm.openS(self.device,self.connection,self.identifier)
   names,values = [],[]
   for c in self.chan_list:
     if "to_write" in c:
       for n,v in c['to_write']:
         names.append(c['name']+n)
         values.append(v)
   #names.append("STREAM_NUM_ADDRESSES");values.append(len(self.channels))
   names.append("STREAM_SCANRATE_HZ");values.append(self.scan_rate)
   names.append("STREAM_RESOLUTION_INDEX");values.append(self.resolution)
   ljm.eWriteNames(self.handle,len(names),names,values)
   scan_rate = ljm.eReadName(self.handle,"STREAM_SCANRATE_HZ")
   if scan_rate != self.scan_rate:
     print("[Labjack] Actual scan_rate:",scan_rate,"instead of",self.scan_rate)
     self.scan_rate = scan_rate
   if any([c.get("make_zero",False) for c in self.chan_list]):
     print("[Labjack] Please wait during offset evaluation...")
     off = self.eval_offset()
     names,values = [],[]
     for i,c in enumerate(self.chan_list):
       if 'make_zero' in c and c['make_zero']:
         c['offset'] += c['gain']*off[i]
   self.n = 0 # Number of data points (to rebuild time)
 def __getHIPow(self):
     pow = ljm.eReadName(self.handle, "AIN2")
     pow = 24 - 40 * pow
     return pow
 def __getHNoiseSel(self):
     sel = ljm.eReadName(self.handle, "EIO1")
     return sel
Exemple #6
0
def Digital_Ports_Read(handle,Port): 
    return ljm.eReadName(handle, Port)
 def _query(self, register):
     ''' Reads the specified register. '''
     return ljm.eReadName(self.handle, register)
 def __getHIPow(self):
     pow = ljm.eReadName(self.handle, "AIN2")
     pow = 24 - 40 * pow + AntennaLJ.pow_offset
     return pow
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 the AIN on the LabJack.
numFrames = 3
names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX"]
aValues = [199, 10, 0]
ljm.eWriteNames(handle, numFrames, names, aValues)

print("\nSet configuration:")
for i in range(numFrames):
    print("    %s : %f" % (names[i], aValues[i]))

# Setup and call eReadName to read an AIN from the LabJack.
name = "AIN0"
result = ljm.eReadName(handle, name)

print("\n%s reading : %f V" % (name, result))

# Close handle
ljm.close(handle)
 def __get24V(self):
     volt = ljm.eReadName(self.handle, "AIN4") * 3
     return volt
Exemple #11
0
    def lifeSensorSample(self):
        global motorEnable, lifeTestMotorDirection, motorEnabled, lifeTestActive
        lifeTestActive = True
        actionFlag = False
        actionTaken = False

        sessionData = []  # Generate empty list for local session data
        cutOffForce = int(self.ui.forceCutOffEdit.text())

        while lifeTestActive:
            timeStamp = datetime.datetime.now().strftime("%H:%M:%S")
            V1 = ljm.eReadName(handle,
                               pressureVoltage)  # Sample analog pressure input
            LV1 = ljm.eReadName(handle,
                                loadVoltage)  # Sample analog load cell input
            P1 = 61.121 * V1 - 43.622
            load = LV1 * 1  #UPDATE NEEDED TO LOAD CELL
            prox1Low = ljm.eReadName(handle,
                                     px1Low)  #read proximity sensor low
            prox1High = ljm.eReadName(handle,
                                      px1High)  #read proximity sensor low

            #sessionData.append(self.sampleSensorData())  # sample data and write to session list
            #self.plotSessionData2(sessionData)

            print("Action Flag: " + str(actionFlag))
            print("Prox Val: " + str(prox1High))

            # Check first proximity sensor
            if prox1High > 3 and not actionTaken:
                print("Prox1 flagged, motor stopped)")
                self.ui.proxLifeRadio1.setStyleSheet(redProxStyle)
                motorEnabled = False  #shut down motor
                motorEnable = 5  #shut down motor
                ljm.eWriteName(handle, "DAC" + str(motorEnablePin),
                               motorEnable)  # 5V high to disable motor
                ljm.eWriteName(handle, "DIO" + str(motorPWM) + "_EF_ENABLE",
                               0)  # Disable the EF system

                #start timer to give a stop delay
                print("five second dwell....")
                time.sleep(5)
                print("toggling motor direction")
                self.lifeCycleToggle()  #Toggle the motor direction and RPM
                print("New Motor Direction: " + str(lifeTestMotorDirection))
                print("")

                actionTaken = True  #action has been taken based off of sensor flag
                motorEnabled = True  #set indicator to true
                motorEnable = 0  #set global variable to allow motor to be durned on
                ljm.eWriteName(handle, "DAC" + str(motorEnablePin),
                               motorEnable)  # Ov low to enable motor
                self.ui.proxLifeRadio1.setStyleSheet(yellowProxStyle)

            elif prox1High > 3 and actionTaken:  #condition where sensor is still flagging but action has been taken
                timeVal = 0
                timeout = 10
                print("Timeout starting for " + str(timeout) + " seconds")
                time.sleep(timeout)
                prox1High = ljm.eReadName(handle, px1High)

                if prox1High > 3:  #see if sensor resets, if not, shut it down
                    print("No sensor reset, shutting down permanently)")
                    motorEnable = 5  # shut down motor
                    ljm.eWriteName(handle, "DAC" + str(motorEnablePin),
                                   motorEnable)  # 5V high to disable motor
                    ljm.eWriteName(handle,
                                   "DIO" + str(motorPWM) + "_EF_ENABLE",
                                   0)  # Disable the EF system
                    lifeTestActive = False
                    while True:
                        self.ui.proxLifeRadio1.setStyleSheet(yellowProxStyle)
                        time.sleep(.25)
                        self.ui.proxLifeRadio1.setStyleSheet(redProxStyle)
                        time.sleep(.25)

                else:  #sensor reset, all clear
                    actionTaken = False
                    self.ui.proxLifeRadio1.setStyleSheet(greenProxStyle)

            elif prox1High < 3:
                self.ui.proxLifeRadio1.setStyleSheet(greenProxStyle)
                actionTaken = False

            #check load cell
            # if load >= cutOffForce:
            #     print("Max Load Exceeded")
            #     self.lifeTestSuspend()
            #     print("Suspending life cycle test")
            #     motorEnabled = False
            #     lifeTestActive = False
            #     motorEnable = 5
            #     ljm.eWriteName(handle, "DAC" + str(motorEnablePin), motorEnable)  # 0V high to disable
            #     ljm.eWriteName(handle, "DIO" + str(motorPWM) + "_EF_ENABLE", 0)  # Disable the EF system

            print("Life Test Running")
            self.ui.pressureLifeLCD.display(P1)  # display data on GUI
            self.ui.loadLifeLCD.display(load)
            time.sleep(0.1)
Exemple #12
0
    handle, "I2C_SLAVE_ADDRESS", 40
)  # Slave Address of the I2C chip = 40 (0x28)

# Initial read of 4 bytes. We need a single I2C
# transmission that the sensor docs apparently say should happen from master?
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.
numBytes = 1
aBytes = [1]  # Byte 0: Memory pointer = 0
ljm.eWriteNameByteArray(handle, "I2C_DATA_TX", numBytes, aBytes)

ljm.eWriteName(handle, "I2C_GO", 1)  # Do the I2C communications.

ack = ljm.eReadName(handle, "I2C_ACKS")
print("Ack %i\n" % ack)

# Read the RX bytes.
numBytes = 4
# aBytes[0] to aBytes[3] will contain the data
aBytes = [0] * 4
aBytes = ljm.eReadNameByteArray(handle, "I2C_DATA_RX", numBytes)

print("\nRead User Memory [0-3] = %s" % " ".join([("%.0f" % val) for val in aBytes]))

ack = ljm.eReadName(handle, "I2C_ACKS")
print("Ack %i\n" % ack)

# Close handles
# ljm.cleanInterval(interval_handle)
Exemple #13
0
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_SIZE", 512)
ljm.eWriteName(handle, "STREAM_OUT0_ENABLE", 1)

# Write values to the stream-out buffer
ljm.eWriteName(handle, "STREAM_OUT0_LOOP_SIZE", 6)
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 0.0)  # 0.0 V
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 1.0)  # 1.0 V
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 2.0)  # 2.0 V
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 3.0)  # 3.0 V
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 4.0)  # 4.0 V
ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_F32", 5.0)  # 5.0 V

ljm.eWriteName(handle, "STREAM_OUT0_SET_LOOP", 1)

print("STREAM_OUT0_BUFFER_STATUS = %f" %
      (ljm.eReadName(handle, "STREAM_OUT0_BUFFER_STATUS")))

# Stream Configuration
POS_IN_NAMES = ["AIN0", "AIN1"]
NUM_IN_CHANNELS = len(POS_IN_NAMES)

TOTAL_NUM_CHANNELS = NUM_IN_CHANNELS + NUM_OUT_CHANNELS

# Add positive channels to scan list
aScanList = ljm.namesToAddresses(NUM_IN_CHANNELS, POS_IN_NAMES)[0]
scanRate = 2000
scansPerRead = 60

# Add the scan list outputs to the end of the scan list.
# STREAM_OUT0 = 4800, STREAM_OUT1 = 4801, etc.
aScanList.extend([4800])  # STREAM_OUT0
Exemple #14
0
minSumSignal = 3.0

sumSignal = []

# analog input to read from the labjack
analogInputName = 'AIN1'


try:
    for i in range(len(Bx)):
        if i % 2:
            for j in range(len(By)):
                xyz.field_cart(Bx[i],By[j],xyz.zCoil.largeCoilField) #,handle)
                #time.sleep(0.1)
                result = float(ljm.eReadName(handle,analogInputName))
                if result > minSumSignal:
                    sumSignal.append([Bx[i],By[j]])
        else:

            for j in range(len(By)):
                xyz.field_cart(Bx[i],By[-(j+1)],xyz.zCoil.largeCoilField) #, handle)
                #time.sleep(0.1)
                result = float(ljm.eReadName(handle,analogInputName))
                if result > minSumSignal:
                    sumSignal.append([Bx[i],By[-(j+1)]])

except KeyboardInterrupt:
    print('\n')
    xyz.closePorts(handle)
    print('closed all the ports')
import sys
import time

from labjack import ljm

# Open first found LabJack
handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctUSB, "ANY")
#handle = ljm.openS("ANY", "USB", "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]))

# Ensure that a lua script is running on the T7. If not, end the python script.
if (ljm.eReadName(handle, "LUA_RUN") != 1):
    print("There is no Lua script running on the device.")
    print("Please use Kipling to begin a Lua script on the device.")
    sys.exit()

# Load the calibration consants for the BMP180 from USER_RAM Registers.
calAddrNames = [
    "USER_RAM11_F32", "USER_RAM12_F32", "USER_RAM13_F32", "USER_RAM14_F32",
    "USER_RAM15_F32", "USER_RAM16_F32", "USER_RAM17_F32", "USER_RAM18_F32",
    "USER_RAM19_F32", "USER_RAM20_F32", "USER_RAM21_F32"
]

calConst = ljm.eReadNames(handle, 11, calAddrNames)
ac1 = calConst[0]
ac2 = calConst[1]
ac3 = calConst[2]
"""
Demonstrates reading a single analog input (AIN) 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 eReadName to read from a AIN on the LabJack.
name = "AIN0"
result = ljm.eReadName(handle, name)

print("\n%s reading : %f V" % (name, result))

# Close handle
ljm.close(handle)
 def __getLJTemp(self):
     temp = ljm.eReadName(self.handle, "TEMPERATURE_DEVICE_K")
     return temp
 def __getS5V(self):
     volt = ljm.eReadName(self.handle, "AIN8")
     return volt
 def __getLJAirTemp(self):
     temp = ljm.eReadName(self.handle, "TEMPERATURE_AIR_K")
     return temp
Exemple #20
0
def printRegisterValue(handle, register_name):
    value = ljm.eReadName(handle, register_name)
    print("%s = %f" % (register_name, value))
 def __get12V(self):
     volt = ljm.eReadName(self.handle, "AIN6") * 2
     return volt
##############
steps = 1000
Bx = np.linspace(xAppliedMinField, xAppliedMaxField, 40)
By = np.linspace(yAppliedMinField, yAppliedMaxField, 1000)
Bz = np.linspace(56.0, 62.0, 200)

minSumSignal = 3.0

sumSignal = []

for i in range(len(Bx)):
    if i % 2:
        for j in range(len(By)):
            field_cart(Bx[i],By[j])
            #time.sleep(0.1)
            result = float(ljm.eReadName(handle,analogInputName))
            if result > minSumSignal:
                sumSignal.append([Bx[i],By[j]])
    else:
        
        for j in range(len(By)):
            field_cart(Bx[i],By[-(j+1)])
            #time.sleep(0.1)
            result = float(ljm.eReadName(handle,analogInputName))
            if result > minSumSignal:
                sumSignal.append([Bx[i],By[-(j+1)]])

# close the labjack connection    
ljm.close(handle)   

# close the powersupply conections
 def __getSerial(self):
     serial = ljm.eReadName(self.handle, "SERIAL_NUMBER")
     return serial
Exemple #24
0
def print_register_value(handle, register_name):
    value = ljm.eReadName(handle, register_name)
    print("%s = %f" % (register_name, value))
 def __getHITemp(self):
     temp = ljm.eReadName(self.handle, "AIN12")
     temp = 478 * temp - 267
     return temp
gpios = []
#iterate over all GPIOs
for i in xrange(8):
    gpios.append(True)
    #just to save copiable code, loop over I/O 0 or 1
    for val in xrange(2):
        #VERY IMPORTANT always reset LJ to low out to avoid driving LJ and Gumstix simultaneously
        DIO = "FIO%i" % i
        ljm.eWriteName(lj, DIO, 0)
        #configure GPIO to output
        ser.write('echo out > /gpio/boardio%i/direction\r' % (i+1))
        sleep(1)
        ser.write('echo %i > /gpio/boardio%i/value\r' % (val, i+1))
        sleep(1)
        #read value on LJ
        ljread = int(ljm.eReadName(lj, DIO))
        print 'LJRead on GPIO %i expecting %i got %i' % (i, val, ljread)
        if ljread != val:
            gpios[i] = False
        ser.write('echo in > /gpio/boardio%i/direction\r' % (i+1))
        #configure LJ to output
        ljm.eWriteName(lj, DIO, val)
        sleep(1)
        #read value on gumstix
        ser.write('cat /gpio/boardio%i/value\r' % (i+1))
        gtread = gt.expect(ser, ['0', '1'], 5)
        print 'GTRead on GPIO %i expecting %i got %i' % (i, val, gtread)
        if gtread != val:
            gpios[i] = False
#pass if all passed
success = True
    (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]))

# Configure the PWM output and counter.
aNames = ["DIO_EF_CLOCK0_DIVISOR", "DIO_EF_CLOCK0_ROLL_VALUE",
          "DIO_EF_CLOCK0_ENABLE", "DIO0_EF_INDEX",
          "DIO0_EF_VALUE_A", "DIO0_EF_ENABLE",
          "DIO18_EF_INDEX", "DIO18_EF_ENABLE"]
aValues = [1, 8000,
           1, 0,
           2000, 1,
           7, 1]
numFrames = len(aNames)
results = ljm.eWriteNames(handle, numFrames, aNames, aValues)

# Wait 1 second.
time.sleep(1.0)

# Read from the counter.
value = ljm.eReadName(handle, "DIO18_EF_READ_A")

print("\nCounter = %f" % (value))

# Turn off PWM output and counter
aNames = ["DIO_EF_CLOCK0_ENABLE", "DIO0_EF_ENABLE"]
aValues = [0, 0]
numFrames = len(aNames)
results = ljm.eWriteNames(handle, numFrames, aNames, aValues)

# Close handle
ljm.close(handle)
 def __getNSStatus(self):
     status = ljm.eReadName(self.handle, "EIO0")
     return status
Exemple #29
0
ljm.eWriteName(handle, "STREAM_OUT2_ENABLE", 1)

# Write values to the stream-out buffer
ljm.eWriteName(handle, "STREAM_OUT2_LOOP_SIZE", 8)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 110)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 100)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 110)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 100)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 110)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 100)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 111)
ljm.eWriteName(handle, "STREAM_OUT2_BUFFER_U16", 100)
# ljm.eWriteName(handle, "STREAM_OUT0_BUFFER_U16", 00)


print("STREAM_OUT0_BUFFER_STATUS = %f" % (ljm.eReadName(handle, "STREAM_OUT0_BUFFER_STATUS")))

# For DAC1
outAddress = ljm.nameToAddress(OUT_NAMES[1])[0]

# Allocate memory for the stream-out buffer
ljm.eWriteName(handle, "STREAM_OUT1_TARGET", outAddress)
ljm.eWriteName(handle, "STREAM_OUT1_BUFFER_SIZE", 512)
ljm.eWriteName(handle, "STREAM_OUT1_ENABLE", 1)

# Write values to the stream-out buffer
ljm.eWriteName(handle, "STREAM_OUT1_LOOP_SIZE", 6)
ljm.eWriteName(handle, "STREAM_OUT1_BUFFER_F32", 0.0)  # 0.0 V
ljm.eWriteName(handle, "STREAM_OUT1_BUFFER_F32", 1.0)  # 1.0 V
ljm.eWriteName(handle, "STREAM_OUT1_BUFFER_F32", 2.0)  # 2.0 V
ljm.eWriteName(handle, "STREAM_OUT1_BUFFER_F32", 3.0)  # 3.0 V
Exemple #30
0
               DIO_DUTY_CYCLE)  # Configure duty cycle to be: 50%
ljm.eWriteName(handle, "DIO0_EF_ENABLE",
               1)  # Enable the EF system, PWM wave is now being outputted

# Configure EF Channel Registers for digital input check:
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 0)
ljm.eWriteName(handle, "DIO1_EF_INDEX", 5)
ljm.eWriteName(handle, "DIO1_EF_OPTIONS", 0)
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 1)

# Hard code direction high
ljm.eWriteName(handle, "DIO3", 1)

# Test the function and write outputs to terminal
while True:
    highTime = ljm.eReadName(handle, "DIO1_EF_READ_A_F")
    lowTime = ljm.eReadName(handle, "DIO1_EF_READ_B_F")
    #print("High Time (s): " + str(highTime))
    #print("Low Time (s(): " + str(lowTime))
    total = highTime + lowTime
    time.sleep(2)
    if total > 0:
        recordFreq = 1 / total
        duty = (highTime / total) * 100
        RPM = 60 * (recordFreq / stepSize)
        print("PWM Frequency (Hz): " + str(recordFreq))
        print("Duty Cycle (%): " + str(duty))
        print("Target RPM: " + str(RPM))
        print(" ")

ljm.close(handle)