def update_free_daq(self): device_list = mover_controller.MoverController.DEVICE_LIST if not self.free_daq_mode.get(): return if (self.daq_status == 'RUNNING' and self.ref.status and time.time() - self.last_free_daq_time > 30.0): # for i in range(10): now = str(datetime.datetime.now()) #[:19] utility.print_info(f'DAQ save field : {self.free_daq_nevent}') buf = f'{now} {self.free_daq_nevent:>6} ' for key, val in device_list.items(): buf += f'{self.mover_position_mon[key]:9.3f} ' for key in hall_probe.HallProbeController.CHANNEL_LIST: field = self.hallprobe.field[key][0] if 'mT' in self.hallprobe.field[key][1]: field *= 1e-3 buf += f'{field:13.8f} ' if USE_REF: buf += f'{self.ref.field:10.7f}' if USE_NMR: buf += f'{self.nmr.field:10.7f}' # utility.print_info(f'STP step#{step_manager.step_number} {buf}') buf += f'{self.temp.temp[0]:6.1f}' buf += f'{self.temp.temp[1]:6.1f}' self.output_file.write(buf + '\n') self.output_file.flush() self.free_daq_nevent += 1 self.last_free_daq_time = time.time()
def goto_center(self): for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if self.mover_enable[key].get(): center = float(param_manager.get(f'center_{key}')) if self.mover.go_to(val, center): utility.print_info( f'MVC ID = {val} go to center: {center}')
def reconnect_mover_driver(self): ''' reconnect mover driver ''' utility.print_info(f'MVC reconnect mover driver') self.mover = mover_controller.MoverController() if self.mover.device is None: utility.print_error( f'MVC failed to open: {self.mover.device_name}') self.mover_good = False self.mover_status = 'IDLE' for key, val in mover_controller.MoverController.DEVICE_LIST.items(): self.set_manual[key] = False
def manual_inching_up(self): ''' get manual inching up ''' self.config_disabled(self.binching_up) self.config_disabled(self.binching_dw) self.config_disabled(self.bservo_on) self.config_disabled(self.bservo_off) utility.print_info('MVC manual inching up from (' + f'{self.mover_position_set["x"]:9.1f},' + f'{self.mover_position_set["y"]:9.1f},' + f'{self.mover_position_set["z"]:9.1f})') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if self.mover_enable[key].get(): utility.print_info(f'MVC ID = {val} inching down ' + f'{self.manual_inching_e.get()} mm') self.mover.inching_up(val)
def start(self): name = (str(datetime.datetime.now())[:19].replace(':', '').replace( "-", '').replace(' ', '_')) utility.set_log_file((os.path.join(self.log_dir, name + '.log'))) utility.print_info('DAQ start') self.free_daq_nevent = 0 self.daq_status = 'RUNNING' self.config_disabled(self.bstart) self.config_normal(self.bstop) self.output_name = os.path.join(self.data_path, name + '.txt') utility.print_info(f'DAQ open file: {self.output_name}') self.output_file = open(self.output_name, 'w') self.output_file.write( f'#\n# {self.output_name}\n#\n# param = ' + f'{param_manager.get("param_file")}\n# step = ' + f'{param_manager.get("step_file")}\n# speed = ' + f'{self.get_speed()}\n#\n' + f'# date time step x y z Bx By Bz ' + ('REF ' if USE_REF else '') + ('NMR ' if USE_NMR else '') + 'Temp1 Temp2\n\n')
def stop(self): if self.daq_status == 'RUNNING': utility.print_info('DAQ stop') try: subprocess.Popen(['aplay', '-q', self.sound_file]) except FileNotFoundError: pass self.output_file.close() self.daq_status = 'IDLE' self.set_manual_inching(force=True) utility.print_info(f'DAQ close file: {self.output_name}') utility.close_log_file() self.config_disabled(self.bstop) if self.mover_status == 'MOVING' or self.mover_status == 'ERROR': utility.print_info('MVC stop') for key, val in mover_controller.MoverController.DEVICE_LIST.items( ): if self.mover_enable[key].get(): self.mover.stop(val)
def update_mover(self): self.mover_good = False self.mover_status = 'IDLE' if self.mover.device is None: self.mover_status = 'ERROR' # utility.print_error(f'MVC failed to update (device is None)') return count = self.n_enable() self.config_normal(self.menu1, 'Print mover parameter') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): continue if not self.set_manual[key]: self.set_manual[key] = self.mover.set_manual(val) if not self.set_manual[key]: self.mover_status = 'ERROR' # utility.print_warning(f'MVC failed to update (set manual)') return self.mover.device_info(val) self.mover.version(val) if self.set_manual[key]: utility.print_info(f'MVC ID = {val} initialized') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): continue o_status = self.mover.io_status(val) if o_status is None: self.mover_status = 'ERROR' utility.print_debug(f'MVC failed to update (io status)') return is_moving = (o_status >> 6) & 0x1 alarm_off = (o_status >> 15) & 0x1 if is_moving == 1 and self.mover_status != 'ERROR': self.mover_status = 'MOVING' if alarm_off == 0: self.mover_status = 'ERROR' alarm_status = dict() alarm_status_all = 0 for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): self.lalarm_status[key].config(text='Alarm N/A', fg='gray25') continue alarm_status[key] = self.mover.alarm_status(val) alarm_status_all += alarm_status[key] if alarm_status[key] == 0: self.lalarm_status[key].config(text='Alarm OFF', fg='blue') else: self.mover_status = 'ERROR' self.lalarm_status[key].config( text=f'Alarm #{alarm_status[key]}', fg='red') if alarm_status_all == 0: self.config_disabled(self.menu1, 'Alarm reset') else: self.config_normal(self.menu1, 'Alarm reset') # if count == 0: # self.mover_good = True # return servo_status_all = 0 self.zero_return_status_all = 0 for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): self.lservo_status[key].config(text='Servo N/A', fg='gray25') continue self.servo_status[key] = self.mover.servo_status(val) servo_status_all += self.servo_status[key] self.zero_return_status[key] = self.mover.zero_return_status(val) self.zero_return_status_all += self.zero_return_status[key] if self.servo_status[key] == 1: self.lservo_status[key].config(text=f'Servo ON', fg='green') elif self.servo_status[key] == 0: self.lservo_status[key].config(text=f'Servo OFF', fg='blue') pos_txt = f' {"mon":^8} {"set":^8} {"mag":^8}\n' for key, val in mover_controller.MoverController.DEVICE_LIST.items(): zero = ' ' if self.zero_return_status[key] == 1 else '*' if val is not None: #self.mover_enable[key].get(): vmon, vset = self.mover.get_position(val) center = float(param_manager.get(f'center_{key}')) if 'x' in key: vmag = vmon - center else: vmag = center - vmon self.mover_position_mon[key] = vmon self.mover_position_set[key] = vset if (abs(vmon - vset) > int(param_manager.get('position_dev')) and self.servo_status[key] == 1): self.mover_status = 'MOVING' if vmon != -999999. and vset != -999999.: pos_txt += ( f'{zero}{key.upper()} {vmon:9.1f}({vset:9.1f})' + f'{vmag:9.1f}\n') else: pos_txt += f'{zero}{key.upper()} {"-"*9}({"-"*9}){"-"*9}\n' else: pos_txt += f'{zero}{key.upper()} {"-"*9:9}({"-"*9:9}){"-"*9}\n' self.lmover_position.config(text=pos_txt) if not self.mover.check_limit(): self.mover_status = 'ERROR' if count == servo_status_all: self.config_disabled(self.bservo_on) # if count == zero_return_status_all and count > 0: if self.mover_status == 'MOVING': # or count != zero_return_status_all: # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.config_disabled(self.bservo_off) else: if count > 0: # self.config_normal(self.menu1, 'Zero return') if count == self.zero_return_status_all: self.config_normal(self.menu1, 'Go to center') self.config_normal(self.bservo_off) else: if alarm_status_all == 0: self.config_normal(self.bservo_on) else: self.config_disabled(self.bservo_on) if servo_status_all == 0: self.config_disabled(self.bservo_off) else: self.config_normal(self.bservo_off) # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.set_speed() self.set_manual_inching() if (alarm_status_all == 0 and #count == zero_return_status_all and self.mover_status != 'ERROR'): self.mover_good = True if (count == servo_status_all and count > 0 and self.mover_status != 'MOVING' and self.daq_status == 'IDLE'): self.config_normal(self.binching_up) self.config_normal(self.binching_dw) else: self.config_disabled(self.binching_up) self.config_disabled(self.binching_dw) else: self.config_disabled(self.binching_up) self.config_disabled(self.binching_dw) if self.mover_status == 'MOVING' or self.daq_status == 'RUNNING': self.config_disabled(self.bservo_on) self.config_disabled(self.bservo_off) # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.config_normal(self.bstop) self.config_disabled(self.speed_e) self.config_disabled(self.manual_inching_e) else: self.config_disabled(self.bstop) self.config_normal(self.speed_e) self.config_normal(self.manual_inching_e)
def reset_alarm(self): ''' send reset alarm command ''' utility.print_info(f'MVC reset alarm') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if self.mover_enable[key].get(): self.mover.reset_alarm(val)
def print_mover_parameter(self): ''' print all mover parameters ''' utility.print_info(f'MVC print mover parameter') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if self.mover_enable[key].get(): self.mover.print_parameter(val)