def start(self):
        """
        Name:MainWindow.start()
        Desc:Starts reading values from EI1050 probe
        """
        try:
            # Get device selection
            if len(LabJackPython.listAll(3)) > 0:
                self.device = u3.U3()
            elif len(LabJackPython.listAll(6)) > 0:
                self.device = u6.U6()
            else:
                self.device = ue9.UE9()

            self.serialDisplay.config(text=self.device.serialNumber)

            # Create and start the thread
            self.thread = ei1050.EI1050Reader(self.device, self.targetQueue)

            # Start scheduleing
            self.window.after(1000, self.updateLabels)
            self.thread.start()

            # Change button
            self.startButton.config(text="Stop", command=self.stop)
        except:
            showErrorWindow(sys.exc_info()[0], sys.exc_info()[1])
Exemplo n.º 2
0
def main():

    # Create an instance of the labjack
    try:
        lj_UE9 = ue9.UE9(ethernet=True, ipAddress="10.42.0.72")
    except:
        print "Failed to find or connect to the labjack."
        safe_exit()

    print "Connected to labjack device: \n{}".format(
        lj_UE9.getCalibrationData())

    AIN_test = 0

    while True:
        batman_is_a_jerk = raw_input(
            "Press any key to take a reading, 'q' to exit.\n")
        if batman_is_a_jerk == 'q':
            break
        value = lj_UE9.getAIN(AIN_test)
        mv = value * 100  # value is correct. 5000 is the reference voltage of 5 volts.
        time.sleep(0.1)
        print("here are some numbers: {} raw, {} degrees C.".format(value, mv))

    lj_UE9.close()
Exemplo n.º 3
0
    def loadDevice(self, deviceType):
        """
        Name: loadDevice(deviceType)
        Desc: loads the first device of device type
        """

        self.deviceType = deviceType

        # Determine which device to use
        if self.deviceType == LJTickDAC.U3:
            self.device = u3.U3()
        elif self.deviceType == LJTickDAC.U6:
            self.device = u6.U6()
        else:
            self.device = ue9.UE9()

        # Display serial number
        self.serialDisplay.config(text=self.device.serialNumber)

        # Configure pins if U3
        if self.deviceType == LJTickDAC.U3:
            self.device.configIO(
                FIOAnalog=15,
                TimerCounterPinOffset=8)  # Configures FIO0-2 as analog

        # Get the calibration constants
        self.getCalConstants()
Exemplo n.º 4
0
 def Reset_btn(self):
     #import ue9
     #import LabJackPython
     myUE9 = ue9.UE9(ethernet=True, ipAddress=self.ip)
     password = input("Reset Button Pressed Please Re-Enter Password: "******"password accepted restarting motor")
     else:
         print("invalid password")
Exemplo n.º 5
0
 def EmergencyStop(self):
     #import ue9
     #import LabJackPython
     myUE9 = ue9.UE9(ethernet=True, ipAddress=self.ip)
     fio_mask = 0b11111111
     fio_dir = 0b11111111
     fio_state = 0b11111001  #Pins 0 (1 to stop)
     results = myUE9.feedback(FIOMask=fio_mask,
                              FIODir=fio_dir,
                              FIOState=fio_state)
     print("EMERGENCY STOP PRESSED!")
Exemplo n.º 6
0
 def Reverse_btn(self):
     #import ue9
     #import LabJackPython
     myUE9 = ue9.UE9(ethernet=True, ipAddress=self.ip)
     fio_mask = 0b11111111
     fio_dir = 0b11111111
     fio_state = 0b11111100  #Pins 0,1,2 (001)
     results = myUE9.feedback(FIOMask=fio_mask,
                              FIODir=fio_dir,
                              FIOState=fio_state)
     print(bin(results["FIOState"]))
     print("Motor Rotating in Reverse")
Exemplo n.º 7
0
    def Start_btn(self):

        #import ue9
        #import LabJackPython
        myUE9 = ue9.UE9(ethernet=True, ipAddress=self.ip)
        print("Motor Starting")
        fio_mask = 0b11111111
        fio_dir = 0b11111111
        fio_state = 0b11111110
        results = myUE9.feedback(FIOMask=fio_mask,
                                 FIODir=fio_dir,
                                 FIOState=fio_state)
        print(results["FIOState"])
Exemplo n.º 8
0
 def connectLabJack(self):
     try:
         self.myUE9 = ue9.UE9(ethernet=True,
                              ipAddress=self.ipEdiText.text())
         self.motorStateLabel.setText("OFF")
         self.startButton.setEnabled(True)
         self.directionPushButton.setEnabled(True)
         self.dutyCycleSlider.setEnabled(True)
         self.ipEdiText.setText(self.defaultIP)
         if not self.checking:  # if not checking inputs, start checking
             self.checkInputs()
     except:
         print("ERROR: LabJack not found")
Exemplo n.º 9
0
    def doorOpen(self, doorState=0):
        try:
            d = ue9.UE9()
        except:
            return False

        doorval = [60600, 58000]  #[closed, open]
        doorindex = int(int(doorState) > 0)
        d.timerCounter(UpdateConfig=True,
                       NumTimersEnabled=1,
                       TimerClockBase=4,
                       TimerClockDivisor=15,
                       Timer0Mode=0,
                       Timer0Value=doorval[doorindex])
        time.sleep(.5)
        d.timerCounter(UpdateConfig=True, NumTimersEnabled=0)
        d.close()
        del d
Exemplo n.º 10
0
    def getCredentials():
        global emergencyPressed
        global motorState
        global ipAddUE9
        global myUE9

        username = usernameBox.get()  # Get username from textbox
        password = passwordBox.get()  # Get password from textbox

        if username == "etd" and password == "123":
            direction["text"] = "Direction: RIGHT"
            state['text'] = "Motor: ON   "
            speedScale.set(50)  # Set Scale to 50 % when motor is turned ON

            ipAddUE9 = ue9IpBox.get()  # Get the Ip address from textbox

            myUE9 = ue9.UE9(
                ethernet=True,
                ipAddress=ue9IpBox.get())  # Connect to UE9 by its IP address

            # Right Direction
            myUE9.singleIO(1, 1, Dir=1, State=1)["FIO1 State"]
            myUE9.singleIO(1, 2, Dir=1, State=1)["FIO2 State"]
            myUE9.singleIO(1, 3, Dir=1, State=0)["FIO3 State"]

            # Set timer value to 50% by using 32768 in Timer0Value
            myUE9.timerCounter(TimerClockBase=1,
                               TimerClockDivisor=29,
                               Timer0Mode=0,
                               NumTimersEnabled=1,
                               UpdateConfig=1,
                               Timer0Value=32768)

            # Clear the logging elements
            credentials.destroy()
            usernameBox.destroy()
            passwordBox.destroy()
            login.destroy()
            invalid["fg"] = "#88324f"  # keep "Invalid" message hidden
            motorState = 1
            emergencyPressed = 0

        else:
            invalid["fg"] = "light red"  # Reveal "Invalid" message hidden
Exemplo n.º 11
0
    def PWM(self):
        #import ue9
        #import LabJackPython
        myUE9 = ue9.UE9(ethernet=True, ipAddress=self.ip)
        print("test")
        #DC = str(int((self.PWM_Slider.value()/65535)*100))

        #self.myUE9.timerCounter(TimerClockBase=1, TimerClockDivisor=1, Timer0Mode=0, NumTimersEnabled=1, UpdateConfig=1, Timer0Value=65535-10000)
        myUE9.timerCounter(TimerClockDivisor=1,
                           UpdateConfig=1,
                           NumTimersEnabled=1,
                           Counter0Enabled=False,
                           Counter1Enabled=True,
                           TimerClockBase=0,
                           ResetTimer0=False,
                           ResetTimer1=False,
                           ResetTimer2=False,
                           ResetTimer3=False,
                           ResetTimer4=False,
                           ResetTimer5=False,
                           ResetCounter0=False,
                           ResetCounter1=False,
                           Timer0Mode=0,
                           Timer0Value=self.PWM_Slider.value())
Exemplo n.º 12
0
            if cumList[i] < 0:
                pass
            if tnew < 0:
                cumList[i] = tnew
            else:
                cumList[i] += tnew / n_per_int
        return cumList


# seconds per integration
sPerInt = 10.
# minutes per file
mPerFile = 60.
outDir = '/home/obs/TMON/Temperatures/'

d = ue9.UE9()

while True:
    fileName = '%stemp.%7.5f.txt' % (outDir, getJD())
    print 'Writing to %s' % fileName
    f = open(fileName, 'w')
    file_start_time = time()
    while (time() - file_start_time < mPerFile * 60.):
        Ts = None
        int_start_time = time()
        while (time() - int_start_time < sPerInt):
            try:
                try:
                    Ts = aggData(Ts, d, list_of_registers)
                except (TypeError):
                    Ts = readTemps(d, list_of_registers)
Exemplo n.º 13
0
  AutoCS = True, DisableDirConfig = False, SPIMode = 'A', SPIClockFactor = 0,
  CSPINNum = 4 (FIO4), CLKPinNum = 5 (FIO5), MISOPinNum = 6 (FIO6),
  MOSIPinNum = 7 (FIO7)

Note the CSPINNum, CLKPinNum, MISOPinNum, and MOSIPinNum pin numbers and make
your connections accordingly.
"""
import os
import time

#By default the example uses a UE9. Uncomment the U6 or U3 section if that is
#your device and then comment out the UE9 section.

import ue9
d = ue9.UE9()  #Open first found UE9 over USB
'''
import u6
d = u6.U6() #Open first found U6 over USB
'''
'''
import u3
d = u3.U3() #Open first found U3 over USB
d.configIO(FIOAnalog = 0x0F) #For this example FIO4-7 need to be digital IO
'''


#convert takes in the 11-bit response and converts it into an integer
def convert(byte1, byte2):
    ans = 0
    i = 128
Exemplo n.º 14
0
timeQ.append(time.time())

#Hz
updateFreq = 10

updatePer = 1/float(updateFreq)

#ohms
SHUNT_RESISTOR = 226.8

#V
ERROR_CUTOFF = 0.852 

# Open the U9 DAQ
try: 
    d = ue9.UE9()
    print "connected via USB"
except: 
    d = ue9.UE9(ethernet=True, ipAddress="192.168.125.209")
    print "connected over ethernet"

#turn on laser sensor
#d.writeRegister(FIO2_1402_INTYPE, 1)
d.writeRegister(FIO2_1402_POWER, 0)



def sensorDoor(daq, doorstate=0):
    doorval = [62050,60000]

    doorindex = int((doorstate>0))
Exemplo n.º 15
0
    def __init__(self, devType=None, encoderAttached=False):
        """
        Name: DAC10.__init__(devType = None, encoderAttached = False)
        
        Args: devType, set to 3 to force use of U3, 6 for U6, 9 for UE9.
              encoderAttached, set to True if your motor has a quadrature 
              encoder output and you want to use it. Note: This requires the 
              use of the EIOs so a CB15 is required. Also, the U3 only has two
              timers and is therefore incapable of doing both the PWM to the 
              DCA and Quadrature.
        
        Desc: Makes a new instance of the DCA10 class.
        
        Examples:
        
        To open the first found device, without an encoder:
        >>> import dca10
        >>> d = dca10.DCA10()
        
        To open the first found U6, without an encoder:
        >>> import dca10
        >>> d = dca10.DCA10(devType = 6)
        
        To open the first found UE9, with an encoder:
        >>> import dca10
        >>> d = dca10.DCA10(devType = 6, encoderAttached = True)
        """

        self.device = None
        self.encoderAttached = encoderAttached
        self.directionLine = None
        self.enableLine = None
        self.currentLine = None

        self.enableState = 1
        self.directionState = 1

        if devType is None:
            if len(LabJackPython.listAll(3)) != 0:
                self.device = u3.U3()
            elif len(LabJackPython.listAll(6)) != 0:
                self.device = u6.U6()
            elif len(LabJackPython.listAll(9)) != 0:
                self.device = ue9.UE9()
            else:
                raise NoDevicesConnectedException(
                    "Couldn't find any connected devices. Please connect a LabJack and try again."
                )
        elif devType == 3:
            self.device = u3.U3()
        elif devType == 6:
            self.device = u6.U6()
        elif devType == 9:
            self.device = ue9.UE9()
        else:
            raise InvalidConfigurationException(
                "Invalid device type submitted. Got %s expected 3, 6, or 9." %
                devType)

        if self.device.devType == 3 and self.encoderAttached:
            raise InvalidConfigurationException(
                "The U3 does not have enough timers to support an encoder.")

        if self.device.devType == 3:
            self.directionLine = 5
            self.enableLine = 6
            self.currentLine = 0
        else:
            if self.encoderAttached:
                self.directionLine = 9
                self.enableLine = 8
            else:
                self.directionLine = 1
                self.enableLine = 2
            self.currentLine = 0

        # Make sure all the pins are digital, and enable a timer.
        if self.device.devType == 3:
            self.device.writeRegister(50590, 1)

        if self.device.devType == 9:
            self.device.writeRegister(7000, 1)
        else:
            self.device.writeRegister(7000, 2)

        self.device.writeRegister(7002, 1)

        # Set the Timer for PWM and Duty Cycle of 0%
        if self.encoderAttached:
            self.device.writeRegister(50501, 3)
            self.device.writeRegister(7100, [8, 0, 8, 0, 0, 65535])
        else:
            self.device.writeRegister(50500, 0)
            self.device.writeRegister(50501, 1)
            self.device.writeRegister(7100, [0, 65535])

        # Set the direction and enable lines to output.
        # Don't have to do this because modbus will take care of direction.
        #self.device.writeRegister(6100 + self.enableLine, 1)
        #self.device.writeRegister(6100 + self.directionLine, 1)

        # Set the direction and enable lines high.
        self.device.writeRegister(6000 + self.enableLine, 1)
        self.device.writeRegister(6000 + self.directionLine, 1)
Exemplo n.º 16
0
turnLeft.bind("<Button-1>", dirLeft)
turnRight.bind("<Button-1>", dirRight)

# GUI Functionalities

# Global Variables
global timer_Value
global confirmation  # Popup window response
global motorState
global fio_state
global myUE9

confirmation = 1
motorState = 0
emergencyPressed = 0

myUE9 = ue9.UE9(ethernet=True,
                ipAddress="10.32.89.101")  # Connect to UE9 by its IP address

# Note of FIO pins used on UE9 (FIO-6 = Sensor, FIO-5 = Reset, FIO-4 = Stop, FIOFIO-3 = pinIn1, FIO-2 = pinIn2, FIO-0 = Speed)

myWindow.after(100, pushButtonCheck
               )  # Call pushButtonCheck method as soon as the mainloop starts.

myWindow.mainloop(
)  # Keep the window form in a loop so it will be open until the X button is press

#Reset the UE9 pins back to OFF after the X button is press
myUE9.singleIO(1, 2, Dir=1, State=0)["FIO2 State"]
myUE9.singleIO(1, 3, Dir=1, State=0)["FIO3 State"]
Exemplo n.º 17
0
 def connection(self):
     self.myUE9 = ue9.UE9(ethernet=True, ipAddress=self.labjackip.text())
     print(self.labjackip.text())
Exemplo n.º 18
0
def readDistance(jQ, active, verbose=False):
    try:

        #Iout, into SHUNT_RESISTOR for voltage conversion
        AIN0_1402_MEASUREMENT = 0

        #Switch output for error state from 1402
        AIN1_1402_ERROR = 1

        #set HIGH to turn off 1402, LOW to turn on sensor
        FIO4_1402_POWER = 6002

        #Read EIO,FIO,MIO,and CIO which have the sync signal encoded
        EIO_FIO = 193
        MIO_CIO = 194

        #ohms
        SHUNT_RESISTOR = 226.8
        #Volts
        ERROR_CUTOFF = 0.9

        try:
            d = ue9.UE9()
            if verbose: print 'connected to labjack locally over USB'
        except:
            print "ue9 failed to instantiate"
            sys.exit()
            #d = ue9.UE9(ethernet=True, ipAddress="192.168.125.209")
            #if verbose: print 'connected to labjack over ethernet'

        # For applying the proper calibration to readings.
        d.getCalibrationData()

        #print "configuring UE9 stream"
        d.streamConfig(NumChannels=4,
                       ChannelNumbers=[
                           AIN0_1402_MEASUREMENT, AIN1_1402_ERROR, EIO_FIO,
                           MIO_CIO
                       ],
                       ChannelOptions=[0, 0, 0, 0],
                       SettlingTime=0,
                       Resolution=12,
                       SampleFrequency=1500)

        pbs = 2100
        starting = True

        #open blast doors
        sensorDoor(d, 1)

        #turn on sensor
        d.writeRegister(FIO4_1402_POWER, 0)

        d.streamStart()

        missed = 0
        dataCount = 0
        byteCount = 0

        for r in d.streamData():
            if r is not None:
                if not active.value: break

                if r['errors'] != 0:
                    print "Error: %s ; " % r['errors']

                if r['numPackets'] != d.packetsPerRequest:
                    print "----- UNDERFLOW : %s : " % r['numPackets']

                if r['missed'] != 0:
                    missed += r['missed']
                    print "+++ Missed ", r['missed']

                if starting: bunchcount = len(r['AIN193'])
                c = numpy.zeros(bunchcount)

                for i in xrange(bunchcount):
                    bs = int((bin(r['AIN193'][i][1])[3:] +
                              (bin(r['AIN194'][i][0])[2:]).zfill(4)), 2)
                    if ((bs <> pbs) & (not starting)):
                        val = volt2distance(r['AIN0'][i], SHUNT_RESISTOR)
                        err = int((r['AIN1'][i] > ERROR_CUTOFF) | (val < 0))
                        jQ.put([bs, val, err])

                    pbs = bs
                    if starting: starting = False
            else:
                # Got no data back from our read.
                # This only happens if your stream isn't faster than the
                # the USB read timeout, ~1 sec.
                print "No data", datetime.now()
    except:
        print 'exception in jackDistance', sys.exc_info()[0]
    finally:
        d.streamStop()
        d.writeRegister(FIO4_1402_POWER, 1)
        sensorDoor(d, 0)
        d.close()
        if verbose: print "labjack cleanup complete."
Exemplo n.º 19
0
	return '%s\t%s'%(get_jd(),get_temps())

#Define Sampling and writing rates.

SperSamp = 0.5 #Seconds per sample
SperInt  = 10  #Seconds per integration
MperFile = 59.5   #Minutes per file

OutDir = '/home/obs/TempData' 

#Write the files.

NperFile = int( 60.* MperFile / SperInt )
NperInt = int(SperInt / SperSamp)
	
d = ue9.UE9(ethernet=True,ipAddress=ipAddress)
print d.commConfig()
Filename = '%s/temp.%s.txt'%(OutDir,str(get_jd()))
print 'Writing to %s'%Filename
f = open(Filename,'w')
i_int = 0
while i_int < NperFile:
	i_samp = 0
	jd,t1,t2 = 0.,0.,0.
	while i_samp < NperInt:
		try:	
			_jd,_t1,_t2 = get_Tstring().split('\t')
			jd += float(_jd)
			t1 += float(_t1)
			t2 += float(_t2)
			i_samp += 1