本文整理汇总了Python中psychopy.iohub.print2err函数的典型用法代码示例。如果您正苦于以下问题:Python print2err函数的具体用法?Python print2err怎么用?Python print2err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print2err函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getEventTable
def getEventTable(self,event_type):
if self.hdfFile:
klassTables=self.hdfFile.root.class_table_mapping
deviceEventTable=None
event_column=None
event_value=None
if isinstance(event_type,basestring):
if event_type.find('Event')>=0:
event_column='class_name'
event_value=event_type
else:
event_value=''
tokens=event_type.split('_')
for t in tokens:
event_value+=t[0].upper()+t[1:].lower()
event_value=event_type+'Event'
event_value='"%s"'%(event_value)
elif isinstance(event_type,(int,long)):
event_column='class_id'
event_value=event_type
else:
iohub.print2err("getEventTable error: event_type arguement must be a string or and int")
return None
result=[row.fetch_all_fields() for row in klassTables.where('({0} == {1}) & (class_type_id == 1)'.format(event_column,event_value))]
if len(result)!= 1:
iohub.print2err("event_type_id passed to getEventAttribute can only return one row from CLASS_MAPPINGS: ",len(result))
return None
tablePathString=result[0][3]
return self.hdfFile.getNode(tablePathString)
return None
示例2: getSerialRx
def getSerialRx(self):
try:
while self._serial_port.inWaiting()>= 2:
request_id = ord(self._serial_port.read(1))
if request_id < T3Request.REQ_COUNTER_START:
event_byte_count = ord(self._serial_port.read(1))
time_bytes = [ord(c) for c in self._serial_port.read(6)]
remaining_byte_count= event_byte_count-(len(time_bytes)+2)
remaining_bytes = []
if remaining_byte_count > 0:
remaining_bytes = [ord(c) for c in self._serial_port.read(remaining_byte_count)]
if request_id in EVENT_TYPE_2_CLASS:
event = EVENT_TYPE_2_CLASS[request_id](request_id, time_bytes, remaining_bytes)
self._rx_events.append(event)
else:
reply=T3Request._readRequestReply(self, request_id)
if reply:
if reply._type == T3Request.SYNC_TIME_BASE:
reply.syncWithT3Time()
else:
self._request_replies.append(reply)
else:
print2err("INVALID REQUEST ID in reply:", request_id)
except Exception as e:
print2err("ERROR During getSerialRx: ",e,". Has ioSync been disconnected?")
self.close()
示例3: shutdown
def shutdown(self):
try:
self._running=False
if Computer.system=='linux2':
if self._hookManager:
self._hookManager.cancel()
while len(self.deviceMonitors) > 0:
m=self.deviceMonitors.pop(0)
m.running=False
if self.eventBuffer:
self.clearEventBuffer()
try:
self.closeDataStoreFile()
except:
pass
while len(self.devices) > 0:
d=self.devices.pop(0)
try:
if d is not None:
d._close()
except:
pass
gevent.sleep()
except:
print2err("Error in ioSever.shutdown():")
printExceptionDetailsToStdErr()
示例4: __init__
def __init__(self, *args, **kwargs):
Device.__init__(self, *args, **kwargs['dconfig'])
self._serial = None
self.port = self.getConfiguration().get('port')
if self.port.lower() == 'auto':
pports = self.findPorts()
if pports:
self.port = pports[0]
if len(pports) > 1:
print2err("Warning: Serial device port configuration set to 'auto'.\nMultiple serial ports found:\n", pports, "\n** Using port ", self.port)
self.baud = self.getConfiguration().get('baud')
self._parser_config = self.getConfiguration().get('event_parser')
self._byte_diff_mode = self._parser_config.get('byte_diff')
if self._byte_diff_mode:
self._rx_buffer = None
else:
self._resetParserState()
self._rx_buffer = ''
self._event_count = 0
self._timeout = None
self._serial = None
self.setConnectionState(True)
示例5: _handleEvents
def _handleEvents(self, events):
# saves many events to pytables table at once.
# EVENTS MUST ALL BE OF SAME TYPE!!!!!
try:
#ioHub.print2err("_handleEvent: ",self.active_experiment_id,self.active_session_id)
if self.checkForExperimentAndSessionIDs(len(events)) is False:
return False
event=events[0]
etype=event[DeviceEvent.EVENT_TYPE_ID_INDEX]
#ioHub.print2err("etype: ",etype)
eventClass=EventConstants.getClass(etype)
etable=self.TABLES[eventClass.IOHUB_DATA_TABLE]
#ioHub.print2err("eventClass: etable",eventClass,etable)
np_events=[]
for event in events:
event[DeviceEvent.EVENT_EXPERIMENT_ID_INDEX]=self.active_experiment_id
event[DeviceEvent.EVENT_SESSION_ID_INDEX]=self.active_session_id
np_events.append(tuple(event))
np_array= N.array(np_events,dtype=eventClass.NUMPY_DTYPE)
#ioHub.print2err('np_array:',np_array)
etable.append(np_array)
self.bufferedFlush(len(np_events))
except ioHubError, e:
print2err(e)
示例6: _handleEvents
def _handleEvents(self, events):
try:
if self.checkForExperimentAndSessionIDs(len(events)) is False:
return False
event = events[0]
etype = event[DeviceEvent.EVENT_TYPE_ID_INDEX]
eventClass = EventConstants.getClass(etype)
etable = self.TABLES[eventClass.IOHUB_DATA_TABLE]
np_events = []
for event in events:
event[DeviceEvent.EVENT_EXPERIMENT_ID_INDEX] = self.active_experiment_id
event[DeviceEvent.EVENT_SESSION_ID_INDEX] = self.active_session_id
np_events.append(tuple(event))
np_array = np.array(np_events, dtype=eventClass.NUMPY_DTYPE)
#ioHub.print2err('np_array:',np_array)
etable.append(np_array)
self.bufferedFlush(len(np_events))
except ioHubError as e:
print2err(e)
except Exception:
printExceptionDetailsToStdErr()
示例7: initConditionVariableTable
def initConditionVariableTable(
self, experiment_id, session_id, np_dtype):
expcv_table = None
expcv_node = self.emrtFile.root.data_collection.condition_variables
exp_session = [('EXPERIMENT_ID','i4'),('SESSION_ID','i4')]
exp_session.extend(np_dtype)
np_dtype = []
for npctype in exp_session:
if isinstance(npctype[0], str):
nv = [str(npctype[0]),]
nv.extend(npctype[1:])
np_dtype.append(tuple(nv))
else:
np_dtype.append(npctype)
self._EXP_COND_DTYPE = np.dtype(np_dtype)
try:
expCondTableName = "EXP_CV_%d"%(experiment_id)
experimentConditionVariableTable = getattr(self.emrtFile.root.data_collection.condition_variables, _f_get_child)(expCondTableName)
self.TABLES['EXP_CV'] = experimentConditionVariableTable
except NoSuchNodeError as nsne:
try:
experimentConditionVariableTable = getattr(self.emrtFile, create_table)(self.emrtFile.root.data_collection.condition_variables, expCondTableName, self._EXP_COND_DTYPE, title='Condition Variable Values for Experiment ID %d' % (experiment_id))
self.TABLES['EXP_CV'] = experimentConditionVariableTable
self.emrtFile.flush()
except Exception:
printExceptionDetailsToStdErr()
return False
except Exception:
print2err(
'Error getting expcv_table for experiment %d, table name: %s' %
(experiment_id, expCondTableName))
printExceptionDetailsToStdErr()
return False
self._activeRunTimeConditionVariableTable = expcv_table
return True
示例8: __init__
def __init__(self, rootScriptPathDir, config=None):
self._session_id=None
self._experiment_id=None
self.log("Server Time Offset: {0}".format(Computer.globalClock.getLastResetTime()))
self._hookManager=None
self.emrt_file=None
self.config=config
self.devices=[]
self.deviceMonitors=[]
self.sessionInfoDict=None
self.experimentInfoList=None
self.filterLookupByInput={}
self.filterLookupByOutput={}
self.filterLookupByName={}
self._hookDevice=None
ioServer.eventBuffer=deque(maxlen=config.get('global_event_buffer',2048))
self._running=True
# start UDP service
self.udpService=udpServer(self,':%d'%config.get('udp_port',9000))
try:
# initial dataStore setup
if 'data_store' in config and psychopy.iohub._DATA_STORE_AVAILABLE:
experiment_datastore_config=config.get('data_store')
default_datastore_config_path=os.path.join(IO_HUB_DIRECTORY,'datastore','default_datastore.yaml')
#print2err('default_datastore_config_path: ',default_datastore_config_path)
_dslabel,default_datastore_config=load(file(default_datastore_config_path,'r'), Loader=Loader).popitem()
for default_key,default_value in default_datastore_config.iteritems():
if default_key not in experiment_datastore_config:
experiment_datastore_config[default_key]=default_value
if experiment_datastore_config.get('enable', True):
#print2err("Creating ioDataStore....")
resultsFilePath=rootScriptPathDir
self.createDataStoreFile(experiment_datastore_config.get('filename','events')+'.hdf5',resultsFilePath,'a',experiment_datastore_config)
#print2err("Created ioDataStore.")
except:
print2err("Error during ioDataStore creation....")
printExceptionDetailsToStdErr()
#built device list and config from initial yaml config settings
try:
for iodevice in config.get('monitor_devices',()):
for device_class_name,deviceConfig in iodevice.iteritems():
#print2err("======================================================")
#print2err("Started load process for: {0}".format(device_class_name))
self.createNewMonitoredDevice(device_class_name,deviceConfig)
except:
print2err("Error during device creation ....")
printExceptionDetailsToStdErr()
raise ioHubError("Error during device creation ....")
示例9: shutDown
def shutDown(self):
try:
self.disableHighPriority()
self.iohub.shutdown()
self._running=False
self.stop()
except:
print2err("Error in ioSever.shutdown():")
printExceptionDetailsToStdErr()
sys.exit(1)
示例10: _sendT3Request
def _sendT3Request(self,request):
try:
request.tx_time=getTime()
tx_count=self._serial_port.write(request.getTxByteArray())
self._serial_port.flush()
self._active_requests[request.getID()]=request
return tx_count
except Exception as e:
print2err("ERROR During sendT3Request: ",e,". Has ioSync been disconnected?")
self.close()
示例11: _run
def _run(self):
self._running=True
while self._sync(False) is False:
sleep(0.5)
self._sync(False)
while self._running is True:
sleep(self.initial_sync_interval)
r=self._sync()
if r is False:
print2err("SYNC FAILED: ioHubTimeGreenSyncManager {0}.".format(self._remote_address))
self._close()
示例12: __init__
def __init__(self,remote_address,sync_state_target):
try:
Greenlet.__init__(self)
self._sync_socket=None
self.initial_sync_interval=0.2
self._remote_address=remote_address
while self._sync_socket is None:
self._sync_socket=ioHubTimeSyncConnection(remote_address)
sleep(1)
self.sync_state_target=proxy(sync_state_target)
except Exception as e:
print2err("** Exception during ioHubTimeGreenSyncManager.__init__: ",self._remote_address)
printExceptionDetailsToStdErr()
示例13: handleGetEvents
def handleGetEvents(self,replyTo):
try:
currentEvents=list(self.iohub.eventBuffer)
self.iohub.eventBuffer.clear()
if len(currentEvents)>0:
currentEvents=sorted(currentEvents, key=itemgetter(DeviceEvent.EVENT_HUB_TIME_INDEX))
self.sendResponse(('GET_EVENTS_RESULT',currentEvents),replyTo)
else:
self.sendResponse(('GET_EVENTS_RESULT', None),replyTo)
return True
except Exception, e:
print2err("IOHUB_GET_EVENTS_ERROR")
printExceptionDetailsToStdErr()
self.sendResponse('IOHUB_GET_EVENTS_ERROR', replyTo)
return False
示例14: _handleEvent
def _handleEvent(self, event):
try:
if self.checkForExperimentAndSessionIDs(event) is False:
return False
etype = event[DeviceEvent.EVENT_TYPE_ID_INDEX]
eventClass = EventConstants.getClass(etype)
etable = self.TABLES[eventClass.IOHUB_DATA_TABLE]
event[DeviceEvent.EVENT_EXPERIMENT_ID_INDEX] = self.active_experiment_id
event[DeviceEvent.EVENT_SESSION_ID_INDEX] = self.active_session_id
np_array = np.array([tuple(event), ], dtype=eventClass.NUMPY_DTYPE)
etable.append(np_array)
self.bufferedFlush()
except Exception:
print2err("Error saving event: ", event)
printExceptionDetailsToStdErr()
示例15: findSyncs
def findSyncs(cls):
"""
Finds serial ports with an ioSync connected.
Code from StimSync python source and modified.
"""
import os
available = []
if os.name == "nt": # Windows
for i in range(1, 256):
try:
sport = "COM" + str(i)
s = serial.Serial(sport)
available.append(sport)
s.close()
except serial.SerialException:
pass
else: # Mac / Linux
from serial.tools import list_ports
available = [port[0] for port in list_ports.comports()]
# available = [s for s in available if ".us" in s]
if len(available) < 1:
print2err("Error: unable to find ioSync. Check Teensy 3 drivers.")
return []
# check each available port to see if it has an ioSync running on it
test_request_id = 170
tx = bytearray([T3Request.GET_USEC_TIME, test_request_id, 3])
iosync_ports = []
for p in available:
try:
sport = serial.Serial(p, 115200, timeout=1)
sport.flushInput()
sport.write(tx)
sport.flush()
obs = sport.read(8)
if ord(obs[0]) == test_request_id or ord(obs[1]) == 8:
iosync_ports.append(p)
p.close()
except Exception:
pass
return iosync_ports