def connect(self):

        iscompleted = False

        nbattempts = 0

        while not(iscompleted) and nbattempts<1000:#while iscompleted is false and nb<1000   will be doing this constantly

            try:

                nbattempts = nbattempts +1

                #print ('Attempt nb ' + str(nbattempts))

                self.jack = u6.U6()

                iscompleted = True

            except:

                print('Pb with labjack initialisation nb '+ str(nbattempts))

                time.sleep(0.01)

        if not(iscompleted): #if iscompleted  equals false   which would give true he 

            raise IOError('Labjack could not connect')

    

		# the FIO0-FIO7 inputs are flexible, meaning they can be analog or digital, so ensure

		# they are all digital by sending a zero for the FIO Analog parameter

		# self.jack.configIO(FIOAnalog = 0)



		# now set all the channels to output, since each digital IO channel supports input and output

        for channel in BIOPAC_CHANNELS:

            #self.jack.getFeedback(u6.BitDirWrite(channel,DIGITAL_CHANNEL_DIRECTION_OUTPUT))

            self.sendMsg(u6.BitDirWrite(channel,DIGITAL_CHANNEL_DIRECTION_OUTPUT))

        for channel in EYETRACKER_CHANNELS:

            #self.jack.getFeedback(u6.BitDirWrite(channel,DIGITAL_CHANNEL_DIRECTION_OUTPUT))

            self.sendMsg(u6.BitDirWrite(channel,DIGITAL_CHANNEL_DIRECTION_OUTPUT))

        for channel in DIGITIMER_CHANNELS:

            #self.jack.getFeedback(u6.BitDirWrite(channel, DIGITAL_CHANNEL_DIRECTION_OUTPUT))

            self.sendMsg(u6.BitDirWrite(channel, DIGITAL_CHANNEL_DIRECTION_OUTPUT))
Exemple #2
0
def acquireStack(cam, nFrames, downscaleTuple, animal, outdir):
    """   Get an image stack from the camera.
     Args:
        cam: (TIS_CAM) initialized camera object
        nFrames: (int) number of frames to acquire
        sendCounter (bool) whether or not to send strobe signal
        downscaleTuple: (tuple) downscale factor in (z, x, y), e.g. (1, 2, 2) for 2x downscale
        animal: (str) animal ID, used for output naming
        outdir: (str) path to output directory

    Returns:
        stack: (np.ndarray) image stack in (z, x, y)
    """
    # setup the labjack
    dioPortNum = 0  # FIO0
    u6Obj = u6.U6()
    u6Obj.configU6()
    u6Obj.configIO()
    u6Obj.setDOState(dioPortNum, state=0)

    stack = []

    cam.StartLive(1)
    # Not using 191001: strobe code below.
    # if sendCounter:
    #     _set_and_check(cam.SetPropertyValue, 'GPIO', 'GP Out', 1)
    #     _set_and_check(cam.PropertyOnePush, 'GPIO', 'Write')
    t_start = time.time()
    for iF in np.arange(nFrames):
        pulseLengthTicks = int(1000/64)
        u6Obj.getFeedback(u6.BitDirWrite(dioPortNum, 1),
                          u6.BitStateWrite(dioPortNum, State=1),
                          u6.WaitShort(pulseLengthTicks),
                          u6.BitStateWrite(dioPortNum, State=0))
        cam.SnapImage()
        im = cam.GetImage()  # appears to have three identical(?) frames
        im = np.mean(im, axis=2).astype('int16')
        stack.append(im)  # averaging to one frame

    # Not using 191001: strobe code below.
    # if sendCounter:
    #     _set_and_check(cam.SetPropertyValue, 'GPIO', 'GP Out', 0)
    #     _set_and_check(cam.PropertyOnePush, 'GPIO', 'Write')

    cam.StopLive()

    print('Done. Downsizing and saving.')
    stack = np.r_[stack]
    stack = transform.downscale_local_mean(stack, downscaleTuple)
    stack = stack.astype('int16')

    timeStr = time.strftime("_%y%m%d_%H-%M-%S", time.localtime(t_start))
    outfile = os.path.join(outdir, '{}{}.tif'.format(animal, timeStr))
    tfl.imsave(outfile, stack)
    nFrames = stack.shape[0]

    print('Saved {} frames to {}'.format(nFrames, outfile))

    return stack
Exemple #3
0
 def ToggleOff(self, relay, name):
     if relay['key'].startswith('E'):
         IONumber = int(relay['key'][3:])+8
     elif relay['key'].startswith('C'):
         IONumber = int(relay['key'][3:])+16
     else:
         IONumber = int(relay['key'][3:])
     if not self.DevFlag:
         self.LJ.getFeedback(u6.BitDirWrite(int(IONumber), 0))
     relay['status'] = 'Off'
Exemple #4
0
    def __init__(self, device, autoUpdate=True, enablePinNum=-1, dataPinNum = -1, clockPinNum = -1, shtOptions = 0xc0):
        self.device = device
        self.autoUpdate = autoUpdate
        self.dataPinNum = dataPinNum
        self.clockPinNum = clockPinNum
        self.shtOptions = shtOptions
        self.enablePinNum = enablePinNum
        self.curState = { 'StatusReg' : None, 'StatusCRC' : None, 'Temperature' : None, 'TemperatureCRC' : None, 'Humidity' : None, 'HumidityCRC' : None }

        # Determine device type
        if self.device.__class__.__name__ == EI1050.U3_STRING: self.deviceType = EI1050.U3
        elif self.device.__class__.__name__ == EI1050.U6_STRING: self.deviceType = EI1050.U6
        elif self.device.__class__.__name__ == EI1050.UE9_STRING: self.deviceType = EI1050.UE9
        else:
            raise TypeError('Invalid device passed. Can not get default values.')

        # If not specified otherwise, use class default for the data pin number
        if self.enablePinNum == -1:
            if self.deviceType == EI1050.U3: self.enablePinNum = EI1050.U3_DEFAULT_ENABLE_PIN_NUM
            elif self.deviceType == EI1050.U6: self.enablePinNum = EI1050.U6_DEFAULT_ENABLE_PIN_NUM
            elif self.deviceType == EI1050.UE9: self.enablePinNum = EI1050.UE9_DEFAULT_ENABLE_PIN_NUM
            else:
                raise TypeError('Invalid device passed. Can not get default values.')

        # If not specified otherwise, use class default for the data pin number
        if self.dataPinNum == -1:
            if self.deviceType == EI1050.U3: self.dataPinNum = EI1050.U3_DEFAULT_DATA_PIN_NUM
            elif self.deviceType == EI1050.U6: self.dataPinNum = EI1050.U6_DEFAULT_DATA_PIN_NUM
            elif self.deviceType == EI1050.UE9: self.dataPinNum = EI1050.UE9_DEFAULT_DATA_PIN_NUM
            else:
                raise TypeError('Invalid device passed. Can not get default values.')

        # If not specified otherwise, use class default for the clock pin number
        if self.clockPinNum == -1:
            if self.deviceType == EI1050.U3: self.clockPinNum = EI1050.U3_DEFAULT_CLOCK_PIN_NUM
            elif self.deviceType == EI1050.U6: self.clockPinNum = EI1050.U6_DEFAULT_CLOCK_PIN_NUM
            elif self.deviceType == EI1050.UE9: self.clockPinNum = EI1050.UE9_DEFAULT_CLOCK_PIN_NUM
            else:
                raise TypeError('Invalid device passed. Can not get default values.')

        # Set U3 pins
        if self.deviceType == EI1050.U3:
            self.device.configIO(FIOAnalog = EI1050.FIO_PIN_STATE)
        
        # Set to write out
        if self.deviceType == EI1050.U3: self.device.getFeedback(u3.BitDirWrite(self.enablePinNum,1))
        elif self.deviceType == EI1050.U6: self.device.getFeedback(u6.BitDirWrite(self.enablePinNum,1))
Exemple #5
0
    def __init__(self):
        super().__init__()
        self.grid_rowconfigure(0, w=1)
        self.grid_columnconfigure(0, w=1)
        self.grid_columnconfigure(1, w=1)

        self.Dict = {
                'AIN0' : 'Failure',
                'AIN1' : 'Low Speed',
                'AIN2' : 'Frequency',
                'AIN3' : 'Supply Current',
                'AIN4' : 'Driving Frequency',
                'FIO3' : 'Error Reset',
                'FIO4' : 'On/Off',
                'FIO5' : 'Low Speed Activate',
                'FIO6' : 'Enable Override',
                'DAC0' : 'Direction',
                'FIO0' : 'Frequency Driver',
                'FIO1' : 'Timer Stop',
                'AIN5' : 'Inner Limit Switch',
                'AIN6' : 'Outer Limit Switch',
                }

        s = ttk.Style()
        s.configure('.', font=('Times', 18))
        s.configure('Header.TLabel', font=('Times', 24))

        self.DevFlag = False
        try:
            self.LJ = u6.U6()
            self.LJ.getCalibrationData()
            for i in range(20):
                self.LJ.getFeedback(u6.BitDirWrite(i, 0)) # output
            self.LJ.configTimerClock(TimerClockBase=3, TimerClockDivisor=2)
            self.LJ.configIO(NumberTimersEnabled=2)
        except:
            self.DevFlag = True
            print('Dev')

        self.turbo = TurboController(self)
        self.turbo.grid(row=0, column=0, sticky='news')

        self.stepper = StepperController(self)
        self.stepper.grid(row=0, column=1, sticky='news')
Exemple #6
0
	def set_dio_dir(self, channel, state):
		"""sets DIO direction. 0=Input, 1=Output"""
		channel = self._check_dio_channel_input(channel)
		cmd = u6.BitDirWrite(channel, state)
		self.d.getFeedback(cmd)
Exemple #7
0
#! /usr/bin/python
import u6
import time
import numpy

d           = u6.U6() # open LabJack U6

d.getCalibrationData() # get calibration info for U6
runtime=[]
for i in range(0,2):
	d.getFeedback(u6.BitDirWrite(0,1))
	d.getFeedback(u6.BitDirWrite(1,0))

	t1 = time.time()

	d.getFeedback(u6.BitStateWrite(0,1))

	#ain = d.getAIN(0)
	d.getFeedback(u6.BitStateRead(1))

	runtime.append(time.time()-t1)

print numpy.mean(runtime)