def main(): global event_q event_q = queue.Queue(maxsize=10) # Here we import the ENV variables from docker olympus_env_settings = { "rate": int(environ['rate']), "samples_per_channel": int(environ['samples_per_channel']), "low_channel": int(environ['low_channel']), "high_channel": int(environ['high_channel']), "serial": environ['serial'], "db_path": environ['db_path'], "input_mode": environ['input_mode'], "range": environ['volts'] } # Instantiate the custom DAQ module daq = DAQ(olympus_env_settings, event_callback) try: # Configure the hardware with our ENV variables daq.configure_mode(olympus_env_settings['input_mode']) # Initialize the DAQ daq.initialize() # Start the background acquisition process daq.begin_acquisition() # Olympus Event Loop try: while True: # event_q holds the data coming in from the DAQ hardware if event_q.qsize() > 0: # Each iteration of the loop pulls the data off the FIFO data_sample = event_q.get_nowait() # Save the data from the FIFO save = Save(data_sample.formatted_buffer(), olympus_env_settings['db_path']) save.record() except KeyboardInterrupt: pass except Exception as e: print('\n', e) finally: # Stop the acquisition if it is still running. if daq.status.RUNNING: daq.ai_device.scan_stop() if daq.daq_device.is_connected(): daq.daq_device.disconnect() daq.daq_device.release()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Example data logger that saves DAQ data to a CSV file in real-time""" import csv from time import time from daq import DAQ d = DAQ() try: dataFile = open('data.csv', 'w+') # overwrite data file if it exists writer = csv.writer(dataFile, quoting=csv.QUOTE_ALL) writer.writerow(['date'] + d.source_labels) # table headers while True: # kill/interrupt script to end program data = [time()] + d.data() print(data) writer.writerow(data) finally: # close/release everything d.close() dataFile.close()
switch_type = self._setup['naming']['control'] return site_name + switch_type + target.get('location', '') + target['domain'] def _get_t1_dp_name(self, domain): site_name = self._site['site_name'] switch_type = self._setup['naming']['tier1'] t1_conf = self._site['tier1']['domains'][domain] return site_name + switch_type + t1_conf.get('location', '') + domain def _get_t2_dp_name(self, t2_conf): site_name = self._site['site_name'] switch_type = self._setup['naming']['tier2'] return site_name + switch_type + t2_conf.get('location', '') + t2_conf['domain'] def _make_vlans(self): return { self._setup['vlan']['name']: { 'description': self._setup['vlan']['description'], 'vid': self._site['vlan_id'] } } def _make_dps(self, domain): return {**self._make_t1_dps(domain), **self._make_t2_dps(domain)} if __name__ == '__main__': sys.exit(TopologyGenerator(DAQ(sys.argv)).process())
def main(): """ Main file to be executed for the vibration DAQ used for CUTE It imports the DAQ and Scope classes and modifies their behaviour using multiple threads This file handles path related things so that the script can be called and the appropriate configuration and log files are found. It parses command line arguments that can modify the DAQ and Scope functionality It creates the DAQ object, starts its run method in a seperate thread. Passes the DAQ object to the user_input function and starts that process in another thread. The Scope object is managed in the main thread as GUI components must be in the main thread. When the quit option is passed to the main thread all the threads join. """ #---------------- Path Related Things ----------------# #make the relavent full paths cwd = os.getcwd() daq_path = sys.path[0] data_path = os.path.join(daq_path, 'data') vib_path = os.path.join(data_path, 'vib') psd_path = os.path.join(data_path, 'psd') #create the paths if they dont already exist if not os.path.exists(data_path): os.mkdir(data_path) if not os.path.exists(vib_path): os.mkdir(vib_path) if not os.path.exists(psd_path): os.mkdir(psd_path) #---------------- Parse CLi Arguments ----------------# try: opts, args = getopt.getopt(sys.argv[1:], 'hsa:p:', ['help','scope','address=','port=']) except getopt.GetoptError: usage() sys.exit(2) #initialize default args address = '' port = '' scope_on = False scope = None #loop through all of the arguments for opt, arg in opts: #help option if opt in ('-h','--help'): usage() sys.exit(0) #address option elif opt in ('-a','--address'): address = arg #port option elif opt in ('-p','--port'): try: port = int(arg) except: raise #scope functionality option elif opt in ('-s','--scope'): scope_on = True #----------------- Setup the Logger -----------------# #create logger logger = logging.getLogger('vib_daq') logger.setLevel(logging.DEBUG) #create file handler log_file = os.path.join(daq_path,'vib_daq.log') fh = logging.FileHandler(log_file) fh.setLevel(logging.DEBUG) #create stream handler ch = logging.StreamHandler() ch.setLevel(logging.ERROR) #create formatter formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') #add formatter to the handlers fh.setFormatter(formatter) ch.setFormatter(formatter) #add handlers to the logger logger.addHandler(fh) logger.addHandler(ch) #----------------- Read Config File -----------------# #set up config parser config = configparser.ConfigParser() config.optionxform = str #preserve case on import cfg_file = os.path.join(daq_path,'vib_daq.cfg') config.read(cfg_file) #conversion parameters convert = None if 'convert' in config.sections(): convert = {key:config['convert'].getfloat(key) for key in config['convert']} #network parameters if not address: address = config['network'].get('IPv4') if not port: port = config['network'].getint('Port') #----------------- Start the DAQ -----------------# #create queue for the scope q = queue.Queue() #create DAQ instance daq = DAQ(address, port, q, scope_on=scope_on, convert=convert) #create daq thread so console input can be received without blocking daq_thread = threading.Thread(target=daq.run) inpt_thread = threading.Thread(target=user_input,args=(daq,)) #start the threads daq_thread.start() inpt_thread.start() #----------------- Control Scope -----------------# while daq.take_data: if daq.scope_on: if scope is None: #create the scope scope = Scope(daq.fs, daq.n_frames) if not q.empty(): traces = q.get() scope.draw(traces) else: if scope is not None: scope.close() scope = None #----------------- Join Threads -----------------# #wait for the process to complete, blocks the main process inpt_thread.join() daq_thread.join() #----------------- Clean Up Files -----------------# #loop through the files in the daq directory, moving csv files with the correct formatting to the data directory files = os.listdir(cwd) for f in files: if f.startswith('vib_') and f.endswith('.csv'): src = os.path.join(cwd,f) dst = os.path.join(vib_path,f) os.rename(src,dst) elif f.startswith('psd_') and f.endswith('.csv'): src = os.path.join(cwd,f) dst = os.path.join(psd_path,f) os.rename(src,dst)
def initialize_daq(self): rotations_per_second = 150 facets_per_rotation = 10 points_per_second = 500000 """ This logic assumes we can get away with an integer number of triggers per write; if we end up using a mirror with an odd number of sides, or if the mirror isn't perfectly regular, we might have to always use an integer number of rotations per write, not an integer number of triggers per write. """ triggers_per_rotation = 2 triggers_per_second = triggers_per_rotation * rotations_per_second points_per_trigger = points_per_second * (1.0 / triggers_per_second) facets_per_second = rotations_per_second * facets_per_rotation points_per_facet = points_per_second * (1.0 / facets_per_second) print print "Desired points per rotation:", print points_per_trigger * triggers_per_rotation print "Desired points per facet:", points_per_facet points_per_facet = int(round(points_per_facet)) points_per_trigger = int(points_per_facet * facets_per_rotation * (1.0 / triggers_per_rotation)) print "Actual points per rotation:", print points_per_trigger * triggers_per_rotation print "Actual points per facet:", (points_per_trigger * triggers_per_rotation * (1.0 / facets_per_rotation)) print print "Desired rotations per second:", rotations_per_second rotations_per_second = ( points_per_second * (1.0 / (points_per_trigger * triggers_per_rotation))) print "Actual rotations per second:", rotations_per_second print points_per_write = points_per_second // 3 print "Desired write length:", points_per_write rotations_per_write = points_per_write * 1.0 / (points_per_trigger * triggers_per_rotation) rotations_per_write = int(round(rotations_per_write)) points_per_write = (points_per_trigger * triggers_per_rotation * rotations_per_write) print "Actual write length:", points_per_write print "Rotations per write:", rotations_per_write triggers_per_write = triggers_per_rotation * rotations_per_write print "Triggers per write:", triggers_per_write print self.daq = DAQ(rate=points_per_second, write_length=points_per_write) wheel_signal = np.zeros(self.daq.write_length, dtype=np.float64) for i in range(triggers_per_write): start = i * points_per_trigger stop = start + points_per_trigger // 2 wheel_signal[start:stop] = 6 wheel_brake_signal = np.zeros(self.daq.write_length, dtype=np.float64) laser_signal = np.zeros(self.daq.write_length, dtype=np.float64) laser_duration = 1 print "Laser duration:", laser_duration * 1.0 / points_per_second, print "seconds" ##Positive is up laser_lag = 65 for i in range(rotations_per_write): for n in range(1): start = (i * points_per_trigger * triggers_per_rotation + n * points_per_facet + laser_lag) stop = start + laser_duration laser_signal[start:stop] = 10 voltage = np.zeros_like(self.daq.voltage) voltage[:, 0] = wheel_signal voltage[:, 1] = wheel_brake_signal voltage[:, 2] = 5 #focusing objective voltage[:, 3] = 0 #murrrcle voltage[:, 6] = laser_signal voltage[:, 7] = laser_signal self.daq.set_voltage(voltage) self.seconds_per_write = self.daq.write_length * 1.0 / self.daq.rate print "Seconds per write:", self.seconds_per_write TIMER_ID = 100 self.daq_timer = wx.Timer(self.panel, TIMER_ID) self.daq_timer.Start(round(self.seconds_per_write * 1000 * 0.95)) wx.EVT_TIMER(self.panel, TIMER_ID, self.on_daq_timer) self.last_daq_time = 0 self.daq.scan()
print "Actual rotations per second:", rotations_per_second print points_per_write = points_per_second // 10 print "Desired write length:", points_per_write rotations_per_write = points_per_write * 1.0 / (points_per_trigger * triggers_per_rotation) rotations_per_write = int(round(rotations_per_write)) points_per_write = (points_per_trigger * triggers_per_rotation * rotations_per_write) print "Actual write length:", points_per_write print "Rotations per write:", rotations_per_write triggers_per_write = triggers_per_rotation * rotations_per_write print "Triggers per write:", triggers_per_write print daq = DAQ(rate=points_per_second, write_length=points_per_write) wheel_signal = np.zeros(daq.write_length, dtype=np.float64) for i in range(triggers_per_write): start = i * points_per_trigger stop = start + points_per_trigger // 2 wheel_signal[start:stop] = 6 wheel_brake_signal = np.zeros(daq.write_length, dtype=np.float64) laser_signal = np.zeros(daq.write_length, dtype=np.float64) laser_duration = 1 print "Laser duration:", laser_duration * 1.0 / points_per_second, "seconds" ##Positive is up laser_lag = 65 for i in range(rotations_per_write): for n in range(1):