def select_channels(self, channels): '''Sets the channels on which to receive event/continuous data. Parameters ---------- channels : array_like A sorted list of channels on which you want to receive data. ''' if not self._init: raise ValueError( "Please open the interface to Central/nPlay first.") buffer_parameter = {'absolute': True} # want absolute timestamps # ability to select desired channels not yet implemented in cbpy # range_parameter = dict() # range_parameter['begin_channel'] = channels[0] # range_parameter['end_channel'] = channels[-1] print('calling cbpy.trial_config in cerelink.select_channels()') result, reset = cbpy.trial_config(buffer_parameter=buffer_parameter) print('cbpy.trial_config result:', result) print('cbpy.trial_config reset:', reset) print('')
def _do_cbsdk_config(self, instance=0, reset=True, buffer_parameter=None, range_parameter=None, get_events=False, get_continuous=False, get_comments=False): """ :param instance: :param reset: True to clear buffer and start acquisition, False to stop acquisition :param buffer_parameter - (optional) dictionary with following keys (all optional) 'double': boolean, if specified, the data is in double precision format 'absolute': boolean, if specified event timing is absolute (new polling will not reset time for events) 'continuous_length': set the number of continuous data to be cached 'event_length': set the number of events to be cached 'comment_length': set number of comments to be cached 'tracking_length': set the number of video tracking events to be cached :param range_parameter - (optional) dictionary with following keys (all optional) 'begin_channel': integer, channel to start polling if certain value seen 'begin_mask': integer, channel mask to start polling if certain value seen 'begin_value': value to start polling 'end_channel': channel to end polling if certain value seen 'end_mask': channel mask to end polling if certain value seen 'end_value': value to end polling :param 'get_events': If False, equivalent of setting buffer_parameter['event_length'] to 0 :param 'get_continuous': If False, equivalent of setting buffer_parameter['continuous_length'] to 0 :param 'get_comments': If False, equivalent of setting buffer_parameter['comment_length'] to 0 :return: """ if buffer_parameter is None: buffer_parameter = {} if range_parameter is None: range_parameter = {} if self.is_connected: cbpy.trial_config(instance=instance, reset=reset, buffer_parameter=buffer_parameter, range_parameter=range_parameter, noevent=int(not get_events), nocontinuous=int(not get_continuous), nocomment=int(not get_comments))
def start(self): """ Tell the device to begin streaming data. You should call ``read()`` soon after this. """ buffer_parameter = {'double': True} result, _ = cbpy.trial_config(reset=True, buffer_parameter=buffer_parameter) err_msg = "Trial configuration was not set successfully." self._check_result(result, RuntimeError, err_msg) self.cache_ = np.zeros((len(self.channels), 0))
def stop_data(self): '''Stop the buffering of data.''' if not self._init: raise ValueError("Please open the interface to Central/nPlay first.") print 'calling cbpy.trial_config in cerelink.stop()' result, reset = cbpy.trial_config(reset=False) print 'cbpy.trial_config result:', result print 'cbpy.trial_config reset:', reset print '' self.streaming = False
def select_channels(self, channels): '''Sets the channels on which to receive event/continuous data. Parameters ---------- channels : array_like A sorted list of channels on which you want to receive data. ''' if not self._init: raise ValueError("Please open the interface to Central/nPlay first.") buffer_parameter = {'absolute': True} # want absolute timestamps # ability to select desired channels not yet implemented in cbpy # range_parameter = dict() # range_parameter['begin_channel'] = channels[0] # range_parameter['end_channel'] = channels[-1] print 'calling cbpy.trial_config in cerelink.select_channels()' result, reset = cbpy.trial_config(buffer_parameter=buffer_parameter) print 'cbpy.trial_config result:', result print 'cbpy.trial_config reset:', reset print ''
conn_params = cbpy.defaultConParams() cbpy.open(parameter=conn_params) print("Creating LSL Outlet") outlet_info = pylsl.StreamInfo(name=STREAM_NAME, type=TYPE, channel_count=len(CHANNEL_NAMES), nominal_srate=pylsl.IRREGULAR_RATE, channel_format=CHAN_FORMAT, source_id=SOURCE_ID) outlet_info.desc().append_child_value("manufacturer", "Blackrock") channels = outlet_info.desc().append_child("channels") for c in CHANNEL_NAMES: channels.append_child("channel").append_child_value("label", c) outlet = pylsl.StreamOutlet(outlet_info) print("Sending timestamps...") try: start_time = pylsl.local_clock() n_samples = 0 target_isi = 1 / SYNC_RATE while True: while (pylsl.local_clock() - start_time) < (n_samples * target_isi): time.sleep(0.1/SYNC_RATE) cbpy.trial_config(reset=True, noevent=True, nocontinuous=True, nocomment=True) res, ts = cbpy.time() lsl_stamp = pylsl.local_clock() outlet.push_sample([int(ts)], timestamp=lsl_stamp) n_samples += 1 except KeyboardInterrupt: print("Terminating...") del outlet cbpy.close()
print 'Using OS X settings for cbpy' parameters['client-addr'] = '255.255.255.255' else: # linux print 'Using linux settings for cbpy' parameters['client-addr'] = '192.168.137.255' parameters['receive-buffer-size'] = 8388608 result, return_dict = cbpy.open(connection='default', parameter=parameters) print 'result:', result print 'connection:', return_dict['connection'] print 'instrument:', return_dict['instrument'] print '' buffer_parameter = {'absolute': True} result, reset = cbpy.trial_config(buffer_parameter=buffer_parameter) print 'result:', result print 'reset:', reset print '' n_secs = 20 loop_time = 0.1 n_itrs = int(n_secs / loop_time) last_nsp_time = 0 for itr in range(n_itrs): t_start = time.time() print '-' * 79 print '\nitr %d of %d:' % (itr+1, n_itrs) print ''
if sys.platform == 'darwin': # OS X print 'Using OS X settings for cbpy' parameters['client-addr'] = '255.255.255.255' else: # linux print 'Using linux settings for cbpy' parameters['client-addr'] = '192.168.137.255' parameters['receive-buffer-size'] = 8388608 result, return_dict = cbpy.open(connection='default', parameter=parameters) print 'result:', result print 'connection:', return_dict['connection'] print 'instrument:', return_dict['instrument'] print '' buffer_parameter = {'absolute': True} result, reset = cbpy.trial_config(buffer_parameter=buffer_parameter) print 'result:', result print 'reset:', reset print '' n_secs = 5 loop_time = 0.1 n_itrs = int(n_secs / loop_time) for itr in range(n_itrs): t_start = time.time() print '\nitr %d of %d:' % (itr + 1, n_itrs) # print 'calling cbpy.trial_event()' # result, trial = cbpy.trial_event(reset=True) # result, nsp_time = cbpy.time()
# Make sure the CereLink project folder is not on the path, # otherwise it will attempt to import cerebus from there, instead of the installed python package. from cerebus import cbpy res, con_info = cbpy.open(parameter=cbpy.defaultConParams()) res, reset = cbpy.trial_config( reset=True, buffer_parameter={'absolute': True}, range_parameter={}, noevent=1, nocontinuous=0, nocomment=1 ) try: while True: result, data, t_0 = cbpy.trial_continuous(reset=True) if len(data) > 0: print(data) except KeyboardInterrupt: cbpy.close()
result, return_dict = cbpy.open(connection='default', parameter=parameters) print 'result:', result print 'connection:', return_dict['connection'] print 'instrument:', return_dict['instrument'] print '' range_parameter = dict() range_parameter['begin_channel'] = 0 #5 range_parameter['end_channel'] = 0 #8 buffer_parameter = dict() buffer_parameter['absolute'] = True # result, reset = cbpy.trial_config(range_parameter=range_parameter) # works # result, reset = cbpy.trial_config(buffer_parameter=buffer_parameter) # doesn't work result, reset = cbpy.trial_config(range_parameter=range_parameter, buffer_parameter=buffer_parameter) # works # result, reset = cbpy.trial_config() print 'result:', result print 'reset:', reset print '' n_secs = 10 loop_time = 0.1 n_itrs = int(n_secs / loop_time) f = open('data.txt', 'w') for itr in range(n_itrs): t_start = time.time() f.write('\nitr %d of %d:\n' % (itr + 1, n_itrs))