def setConnectionState(self,enable): if enable is True: if MCU._mcu is None: serial_id=None if self.serial_port.upper().strip().startswith('COM'): serial_id=int(self.serial_port.strip()[3:]) else: serial_id= self.serial_port.strip() MCU._mcu = T3MC(serial_id) self._mcu._runTimeSync() MCU._last_sync_time=getTime() elif enable is False: if self._mcu: self._mcu.close() MCU._mcu=None return self.isConnected()
def setConnectionState(self, enable): if enable is True: if MCU._mcu is None: serial_id = None if self.serial_port.upper().strip().startswith('COM'): serial_id = int(self.serial_port.strip()[3:]) else: serial_id = self.serial_port.strip() MCU._mcu = T3MC(serial_id) self._mcu._runTimeSync() MCU._last_sync_time = getTime() elif enable is False: if self._mcu: self._mcu.close() MCU._mcu = None return self.isConnected()
def _poll(self): try: logged_time=getTime() if self.isConnected(): self._mcu.getSerialRx() if logged_time-self._last_sync_time>=self.time_sync_interval: self._mcu._runTimeSync() MCU._last_sync_time=logged_time if not self.isReportingEvents(): return False confidence_interval=logged_time-self._last_callback_time events=self._mcu.getRxEvents() for event in events: current_MCU_time=event.device_time#self.getSecTime() device_time=event.device_time if event.local_time is None: event.local_time=logged_time delay=logged_time-event.local_time#current_MCU_time-device_time # local_time is in iohub time space already, so delay does not # need to be used to adjust iohub time iohub_time=event.local_time elist=None if event.getTypeInt()==T3Event.DIGITAL_INPUT_EVENT: elist= [EventConstants.UNDEFINED,]*12 elist[4]=DigitalInputEvent.EVENT_TYPE_ID elist[-1]=event.getDigitalInputByte() elif event.getTypeInt()==T3Event.ANALOG_INPUT_EVENT: elist= [EventConstants.UNDEFINED,]*19 elist[4]=AnalogInputEvent.EVENT_TYPE_ID for i,v in enumerate(event.ain_channels): elist[(i+11)]=v if elist: elist[0]=0 elist[1]=0 elist[2]=0 elist[3]=Computer._getNextEventID() elist[5]=device_time elist[6]=logged_time elist[7]=iohub_time elist[8]=confidence_interval elist[9]=delay elist[10]=0 self._addNativeEventToBuffer(elist) replies = self._mcu.getRequestReplies(True) for reply in replies: rid=reply.getID() if rid in self._request_dict.keys(): self._response_dict[rid]=reply del self._request_dict[rid] self._last_callback_time=logged_time return True except Exception, e: print2err("--------------------------------") print2err("ERROR in MCU._poll: ",e) printExceptionDetailsToStdErr() print2err("---------------------")
def getDeviceTime(self): return T3Request.sync_state.local2RemoteTime(getTime())
def _poll(self): try: logged_time=getTime() if self.isConnected(): self._mcu.getSerialRx() if logged_time-self._last_sync_time>=self.time_sync_interval: self._mcu._runTimeSync() self._last_sync_time=logged_time if not self.isReportingEvents(): return False confidence_interval=logged_time-self._last_callback_time events = self._mcu.getRxEvents() for event in events: current_MCU_time = event.device_time#self.getSecTime() device_time = event.device_time if event.local_time is None: event.local_time=logged_time delay=logged_time-event.local_time#current_MCU_time-device_time # local_time is in iohub time space already, so delay does not # need to be used to adjust iohub time iohub_time=event.local_time elist = None if event.getTypeInt() == T3Event.ANALOG_INPUT_EVENT: elist = [EventConstants.UNDEFINED,]*19 elist[4] = AnalogInputEvent.EVENT_TYPE_ID for i, v in enumerate(event.ain_channels): elist[(i+11)]=v elif event.getTypeInt() == T3Event.DIGITAL_INPUT_EVENT: elist = [EventConstants.UNDEFINED,]*12 elist[4] = DigitalInputEvent.EVENT_TYPE_ID elist[-1] = event.getDigitalInputByte() elif event.getTypeInt() == T3Event.THRESHOLD_EVENT: elist = [EventConstants.UNDEFINED,]*19 elist[4] = ThresholdEvent.EVENT_TYPE_ID for i, v in enumerate(event.threshold_state_changed): elist[(i+11)] = v if elist: elist[0] = 0 elist[1] = 0 elist[2] = 0 elist[3] = Computer._getNextEventID() elist[5] = device_time elist[6] = logged_time elist[7] = iohub_time elist[8] = confidence_interval elist[9] = delay elist[10] = 0 self._addNativeEventToBuffer(elist) replies = self._mcu.getRequestReplies(True) for reply in replies: rid=reply.getID() if rid in self._request_dict.keys(): self._response_dict[rid]=reply del self._request_dict[rid] self._last_callback_time=logged_time return True except Exception, e: print2err("--------------------------------") print2err("ERROR in MCU._poll: ",e) printExceptionDetailsToStdErr() print2err("---------------------")
def _resetLocalState(self): self._request_dict.clear() self._response_dict.clear() self._last_sync_time = 0.0 self._mcu._runTimeSync() self._last_sync_time = getTime()