示例#1
0
    def __init__(self, logger):
        if platform.system() == 'Linux':
            ser_port = '/dev/ttyUSB0'
        else:
            ser_port = '/dev/cu.UC-232AC'
        self.serial = serial.serial_for_url(ser_port)
        self.channels = {
            'out': {
                1: 'dtr',
                2: 'rts'
            },
            'in': {
                1: 'dsr',
                2: 'cts'
            }
        }

        self.serial.dtr = False  # probe 1
        self.serial.rts = False  # place probe in position

        setattr(self.serial, self.channels['out'][1],
                False)  # read a byte from the hardware
        setattr(self.serial, self.channels['out'][2],
                False)  # read a byte from the hardware

        super(SerialProbe, self).__init__(logger)
        self.worker = GetHWPoller(0.001, self.poll_probe)
        self.interlock = False  # set to prohibit thread from accessing serial port
        self.worker.start()
示例#2
0
class SerialProbe(Probe):
    def __init__(self, logger):
        if platform.system() == 'Linux':
            ser_port = '/dev/ttyUSB0'
        else:
            ser_port = '/dev/cu.UC-232AC'
        self.serial = serial.serial_for_url(ser_port)
        self.channels = {'out': {1: 'dtr', 2: 'rts'},
                         'in': {1: 'dsr', 2: 'cts'}}

        self.serial.dtr = False  # probe 1
        self.serial.rts = False  # place probe in position

        setattr(self.serial, self.channels['out'][1], False)  # read a byte from the hardware
        setattr(self.serial, self.channels['out'][2], False)  # read a byte from the hardware

        super(SerialProbe, self).__init__(logger)
        self.worker = GetHWPoller(0.001, self.poll_probe)
        self.interlock = False  # set to prohibit thread from accessing serial port
        self.worker.start()

    def give_liquid(self, probe, duration=False, log=True):
        if not duration:
            duration = self.liquid_dur[probe]
        self.thread.submit(self.__pulse_out, probe, duration)
        if log:
            self.logger.log_liquid(probe)

    def poll_probe(self):
        if self.interlock:
            return "interlock"  # someone else is using serial port, wait till done!
        self.interlock = True  # set interlock so we won't be interrupted
        response1 = getattr(self.serial, self.channels['in'][1])  # read a byte from the hardware
        response2 = getattr(self.serial, self.channels['in'][2])  # read a byte from the hardware
        self.interlock = False
        if response1:
            if self.timer_probe1.elapsed_time() > 200:
                self.probe1_licked(1)
        if response2:
            if self.timer_probe2.elapsed_time() > 200:
                self.probe2_licked(2)

    def __pulse_out(self, probe, duration):
        while self.interlock:  # busy, wait for free, should timeout here
            print("waiting for interlock")
            sys.stdout.flush()
        print('reward!')
        self.interlock = True
        setattr(self.serial, self.channels['out'][probe], True)
        sleep(duration/1000)
        setattr(self.serial, self.channels['out'][probe], False)
        self.interlock = False

    def in_position(self):
        return self.ready

    def cleanup(self):
        self.worker.kill()
示例#3
0
 def __init__(self, logger):
     if platform.system() == 'Linux':
         ser_port = '/dev/ttyUSB0'
     else:
         ser_port = '/dev/cu.UC-232AC'
     self.serial = serial.serial_for_url(ser_port)
     self.serial.dtr = False  # probe 1
     self.serial.rts = False  # place probe in position
     super(SerialProbe, self).__init__(logger)
     self.worker = GetHWPoller(0.001, self.poll_probe)
     self.interlock = False  # set to prohibit thread from accessing serial port
     self.worker.start()