def connect_motors(self): "connect to epics motors" for name, data in self.config.items(): name = normalize_pvname(name) desc = data['desc'] self.motors[desc] = Motor(name=name) self.scale[desc] = data['scale']
def __init__(self): super().__init__() # self.init_ui() # def init_ui(self): self.b = QtWidgets.QPushButton('Push me') self.l = QtWidgets.QLabel('I have not been clicked yet') self.m = Motor('16test:m9') h_box = QtWidgets.QHBoxLayout() h_box.addStretch() h_box.addWidget(self.l) h_box.addStretch() v_box = QtWidgets.QVBoxLayout() v_box.addWidget(self.b) v_box.addLayout(h_box) self.setLayout(v_box) self.setWindowTitle('PyQt5 Lesson 5') self.b.clicked.connect(self.btn_click) self.show()
def __init__(self, parent=None, args=[]): super(RockingCurve, self).__init__(parent=parent, args=args) self.ui.btnStart.clicked.connect(self.start_rc) self.ui.btnStop.clicked.connect(self.stop) #self.ui.pushButton.clicked.connect(self.tmp) self.m = Motor("IOC:m1") #self.d = [PV("IOC:m1.RBV"), PV("417:aiExample")] self.d = [BL09BNCT("X09B1:EH:NCT")]
def __init__(self, parent=None, args=[]): super(XAFS, self).__init__(parent=parent, args=args) self.ui.btnStart.clicked.connect(self.start) self.ui.btnStop.clicked.connect(self.stop) self.ui.btnPara.clicked.connect(self.set_parameter) self.m = Motor("IOC:m1") self.d = [PV("IOC:m1.RBV"), PV("417:aiExample")] self.energy_pv = [PV("X09B1:XAFS:Energy" + str(i)) for i in range(8)] self.step_pv = [PV("X09B1:XAFS:Step" + str(i)) for i in range(7)] self.itime_pv = [PV("X09B1:XAFS:ITime" + str(i)) for i in range(7)]
def checkEpicsMotorNr(self, name): i = 1 while True: try: m = Motor(name + str(i)) print('Epics Motor {} '.format(name + str(i))) i += 1 except: break
def read_config(self, configfile=None, get_dir=False): "open/read ini config file" if get_dir: ret = SelectWorkdir(self) if ret is None: self.Destroy() os.chdir(ret) self.cnf = StageConfig(configfile) self.config = self.cnf.config gui = self.config['gui'] self.workdir_file = gui.get('workdir_file', 'sampleviewer_workdir.txt') self.iconfile = gui.get('icon_file', '') self.autosave_file = gui.get('autosave_file', 'SampleStage_autosave.ini') self.v_move = gui.get('verify_move', True) self.v_erase = gui.get('verify_erase', True) self.v_replace = gui.get('verify_overwrite', True) self.center_with_fine_stages = gui.get('center_with_fine_stages', False) self.SetTitle(gui.get('title', 'Microscope')) cam = self.config['camera'] self.imgdir = cam.get('image_folder', 'Sample_Images') self.cam_type = cam.get('type', 'fly2').lower() self.cam_fly2id = cam.get('fly2_id', 0) self.cam_id = cam.get('cam_id', 0) self.cam_adpref = cam.get('ad_prefix', '') self.cam_adform = cam.get('ad_format', 'JPEG') self.cam_weburl = cam.get('web_url', 'http://164.54.160.115/jpg/2/image.jpg') self.get_cam_calib() try: pref = self.imgdir.split('_')[0] except: pref = 'Sample' self.htmllog = '%sStage.html' % pref if not os.path.exists(self.imgdir): os.makedirs(self.imgdir) if not os.path.exists(self.htmllog): self.begin_htmllog() self.config = self.cnf.config self.stages = OrderedDict() for mname, data in self.config.get('stages', {}).items(): mot = Motor(name=mname) if data['prec'] is None: data['prec'] = mot.precision if data['desc'] is None: data['desc'] = mot.description if data['maxstep'] is None: data['maxstep'] = (mot.high_limit - mot.low_limit) / 2.10 self.stages[mname] = data
def connect_motors(self): "connect to epics motors" self.motors = {} self.sign = {None: 1} for pvname, val in self.config['stages'].items(): pvname = pvname.strip() label = val['label'] self.motors[label] = Motor(name=pvname) self.sign[label] = val['sign'] for mname in self.motorwids: self.motorwids[mname].SelectMotor(self.motors[mname])
def connectMotor(self, name, axis): """ Connect with the epics PV using the prefix name and axis number of PV. """ while True: try: print("Epics Motor Name: {}".format(str(name) + str(axis))) motorHW = Motor(str(name) + str(axis)) deviceType = motorHW.get('device_type', as_string=True) if deviceType == 'asynMotor': print("Epics Motor {} Connected ".format(motorHW)) return motorHW break except epics.motor.MotorException: print("MotorException, check the Epics Motor. ") raise
def check_motor_state(self, motorName): """check a epics motor state""" list_result = { 1: "DIRECTION: last raw direction; (0:Negative, 1:Positive)", 2: "DONE: motion is complete.", 3: "PLUS_LS: plus limit switch has been hit.", 4: "HOMELS: state of the home limit switch. ", 5: "Unused", 6: "POSITION: closed-loop position control is enabled. ", 7: "SLIP_STALL: Slip/Stall detected (eg. fatal following error", 8: "HOME: if at home position. ", 9: "DIRECTION: last raw direction; (0:Negative, 1:Positive)", 10: "PROBLEM: driver stopped polling, or hardware problem ", 11: "MOVING: non-zero velocity present. ", 12: "GAIN_SUPPORT: motor supports closed-loop position control. ", 13: "DIRECTION: last raw direction; (0:Negative, 1:Positive", 14: "MINUS_LS: minus limit switch has been hit. ", 15: "HOMED: the motor has been homed." } epics_motor = Motor(str(motorName)) stateID = epics_motor.get("MSTA") self.output("Epics motor {} state: {}".format(motorName, stateID)) stateID_binary_conversion = bin(int(stateID)) #self.output(str(stateID_binary_conversion)) state_conversion = str(stateID_binary_conversion)[2:] #self.output(str(state_conversion)) state_converse = state_conversion[::-1] #self.output(state_converse) list_state1 = [] count = 0 for each_char in state_converse: count += 1 self.output('Bit {}: {} >>> {}'.format(count, each_char, list_result[count])) if each_char == str(1): list_state1.append(count) #self.output(list_state1) self.output("\nProblem Diagnosis:\n ") if list_state1: for i in list_state1: self.output("Bit {}: 1 >>> {} ".format(i, list_result[i])) else: self.output("None")
def __init__(self, parent=None, motors=None, *args, **kwds): wx.Frame.__init__(self, parent, wx.ID_ANY, '', wx.DefaultPosition, wx.Size(-1, -1), **kwds) self.SetTitle(" Epics Motors Page") self.Bind(wx.EVT_CLOSE, self.onClose) self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False)) self.xtimer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.onTimer, self.xtimer) self.createSbar() self.createMenus() motorlist = None if motors is not None: motorlist = [Motor(mname) for mname in motors] self.buildFrame(motors=motorlist) self.xtimer.Start(250)
def init_connect(self, pvname, is_motor=False): """try to connect epics PV, executing action(wid=wid, pvname=pvname, pv=pv) """ if pvname is None or len(pvname) < 1: return if '.' not in pvname: pvname = '%s.VAL' % pvname pvname = str(pvname) if pvname in self.pvs: return self.pvs[pvname] = epics.get_pv(pvname, form='native') self.in_progress[pvname] = (None, None, time.time()) # print(" init_connect ", pvname, self.pvs[pvname]) if is_motor: idot = pvname.find('.') basname = pvname[:idot] x = Motor(basname)
from shutter import Shutter from epics import Motor # diffractometer/sample stage motors phi = Motor('34idc:mxv:c1:m1') chi = Motor('34idc:mxv:c1:m2') th = Motor('34idc:aero:c0:m1') xm = Motor('34idc:mxv:c1:m5') ym = Motor('34idc:mxv:c1:m6') zm = Motor('34idc:mxv:c0:m1') gam = Motor('34idc:m4k:c1:m5') delta = Motor('34idc:m4k:c1:m6') # fast-shutter shttr = Shutter('34idc:softGlue:OR-1_IN2_Signal')
def init_general_PVs(params): '''Initialize epics PV objects. ''' global_PVs = {} log.info('Creating PV objects.') # shutter pv's global_PVs['ShutterA_Open'] = PV('7bma1:rShtrA:Open') global_PVs['ShutterA_Close'] = PV('7bma1:rShtrA:Close') global_PVs['ShutterA_Move_Status'] = PV('PB:07BM:STA_A_FES_CLSD_PL.VAL') # Experimment Info global_PVs['Sample_Name'] = PV('7bmb1:ExpInfo:SampleName') global_PVs['Sample_Description'] = PV( '7bmb1:ExpInfo:SampleDescription.VAL') global_PVs['User_Badge'] = PV('7bmb1:ExpInfo:UserBadge.VAL') global_PVs['User_Email'] = PV('7bmb1:ExpInfo:UserEmail.VAL') global_PVs['User_Institution'] = PV('7bmb1:ExpInfo:UserInstitution.VAL') global_PVs['Proposal_Number'] = PV('7bmb1:ExpInfo:ProposalNumber.VAL') global_PVs['Proposal_Title'] = PV('7bmb1:ExpInfo:ProposalTitle.VAL') global_PVs['User_Info_Update'] = PV('7bmb1:ExpInfo:UserInfoUpdate.VAL') global_PVs['Lens_Magnification'] = PV('7bmb1:ExpInfo:LensMagFloat.VAL') global_PVs['Scintillator_Type'] = PV('7bmb1:ExpInfo:ScintillatorType.VAL') global_PVs['Scintillator_Thickness'] = PV( '7bmb1:ExpInfo:ScintillatorThickness.VAL') global_PVs['Camera_IOC_Prefix'] = PV('7bmb1:ExpInfo:CameraIOCPrefix.VAL') global_PVs['PixelSizeMicrons'] = PV('7bmb1:ExpInfo:PixelSizeum.VAL') global_PVs['Filters'] = PV('7bmb1:ExpInfo:Filters.VAL') global_PVs['File_Name'] = PV('7bmb1:ExpInfo:FileName.VAL') global_PVs['Station'] = PV('7bmb1:ExpInfo:Station.VAL') global_PVs['Remote_Data_Trasfer'] = PV( '7bmb1:ExpInfo:RemoteDataTrasfer.VAL') global_PVs['Remote_Analysis_Dir'] = PV( '7bmb1:ExpInfo:RemoteAnalysisDir.VAL') global_PVs['User_Last_Name'] = PV('7bmb1:ExpInfo:UserLastName.VAL') global_PVs['Experiment_Year_Month'] = PV( '7bmb1:ExpInfo:ExperimentYearMonth.VAL') global_PVs['Use_Furnace'] = PV('7bmb1:ExpInfo:UseFurnace.VAL') global_PVs['White_Field_Motion'] = PV('7bmb1:ExpInfo:WhiteFieldMotion.VAL') global_PVs['Num_White_Images'] = PV('7bmb1:ExpInfo:NumWhiteImages.VAL') global_PVs['Bright_Exp_Time'] = PV('7bmb1:ExpInfo:BrightExposureTime.VAL') global_PVs['Sample_Detector_Distance'] = PV( '7bmb1:ExpInfo:SampleDetectorDistance.VAL') global_PVs['Sample_Out_Position_Y'] = PV( '7bmb1:ExpInfo:SampleOutPositionY.VAL') global_PVs['Sample_Out_Position_X'] = PV( '7bmb1:ExpInfo:SampleOutPositionX.VAL') global_PVs['Num_Projections'] = PV('7bmb1:ExpInfo:NumProjections.VAL') global_PVs['Sample_Rotation_Start'] = PV( '7bmb1:ExpInfo:SampleRotationStart.VAL') global_PVs['Sample_Rotation_End'] = PV( '7bmb1:ExpInfo:SampleRotationEnd.VAL') global_PVs['Sample_Rotation_Speed'] = PV( '7bmb1:ExpInfo:SampleRotationSpeed.VAL') global_PVs['Sample_Retrace_Speed'] = PV('7bmb1:ExpInfo:RetraceSpeed.VAL') global_PVs['Furnace_In_Position'] = PV( '7bmb1:ExpInfo:FurnaceInPosition.VAL') global_PVs['Furnace_Out_Position'] = PV( '7bmb1:ExpInfo:FurnaceOutPosition.VAL') global_PVs['Scan_Type'] = PV('7bmb1:ExpInfo:ScanType.VAL') global_PVs['Sleep_Time'] = PV('7bmb1:ExpInfo:SleepTime.VAL') global_PVs['Scan_Replicates'] = PV('7bmb1:ExpInfo:ScanReplicates.VAL') global_PVs['Vertical_Scan_Start'] = PV( '7bmb1:ExpInfo:VerticalScanStart.VAL') global_PVs['Vertical_Scan_End'] = PV('7bmb1:ExpInfo:VerticalScanEnd.VAL') global_PVs['Vertical_Scan_Step_Size'] = PV( '7bmb1:ExpInfo:VerticalScanStepSize.VAL') global_PVs['Horizontal_Scan_Start'] = PV( '7bmb1:ExpInfo:HorizontalScanStart.VAL') global_PVs['Horizontal_Scan_End'] = PV( '7bmb1:ExpInfo:HorizontalScanEnd.VAL') global_PVs['Horizontal_Scan_Step_Size'] = PV( '7bmb1:ExpInfo:HorizontalScanStepSize.VAL') params.station = global_PVs['Station'].get(as_string=True) log.info('Running in station {:s}.'.format(params.station)) if params.station == '7-BM-B': log.info('*** Running in station 7-BM-B:') # Set sample stack motor: global_PVs['Motor_SampleX'] = Motor('7bmb1:aero:m2') global_PVs['Motor_SampleY'] = Motor('7bmb1:aero:m1') global_PVs['Motor_SampleRot'] = Motor( '7bmb1:aero:m3') # Aerotech ABR-250 global_PVs['Motor_Focus'] = Motor('7bmb1:m38') else: log.error('*** %s is not a valid station' % params.station) # detector pv's params.valid_camera_prefixes = [ '7bm_pg1:', '7bm_pg2:', '7bm_pg3:', '7bm_pg4:' ] params.camera_ioc_prefix = global_PVs['Camera_IOC_Prefix'].get( as_string=True) if params.camera_ioc_prefix[-1] != ':': params.camera_ioc_prefix = params.camera_ioc_prefix + ':' log.info('Using camera IOC with prefix {:s}'.format( params.camera_ioc_prefix)) if params.camera_ioc_prefix in params.valid_camera_prefixes: update_pixel_size(global_PVs, params) # init Point Grey PV's # general PV's global_PVs['Cam1_SerialNumber'] = PV(params.camera_ioc_prefix + 'cam1:SerialNumber') global_PVs['Cam1_AsynPort'] = PV(params.camera_ioc_prefix + 'cam1:PortName_RBV') global_PVs['Cam1_ImageMode'] = PV(params.camera_ioc_prefix + 'cam1:ImageMode') global_PVs['Cam1_ArrayCallbacks'] = PV(params.camera_ioc_prefix + 'cam1:ArrayCallbacks') global_PVs['Cam1_AcquirePeriod'] = PV(params.camera_ioc_prefix + 'cam1:AcquirePeriod') global_PVs['Cam1_TriggerMode'] = PV(params.camera_ioc_prefix + 'cam1:TriggerMode') global_PVs['Cam1_SoftwareTrigger'] = PV( params.camera_ioc_prefix + 'cam1:SoftwareTrigger' ) ### ask Mark is this is exposed in the medm screen global_PVs['Cam1_AcquireTime'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTime') global_PVs['Cam1_FrameType'] = PV(params.camera_ioc_prefix + 'cam1:FrameType') global_PVs['Cam1_NumImages'] = PV(params.camera_ioc_prefix + 'cam1:NumImages') global_PVs['Cam1_NumImagesCounter'] = PV(params.camera_ioc_prefix + 'cam1:NumImagesCounter_RBV') global_PVs['Cam1_Acquire'] = PV(params.camera_ioc_prefix + 'cam1:Acquire') global_PVs['Cam1_AttributeFile'] = PV(params.camera_ioc_prefix + 'cam1:NDAttributesFile') global_PVs['Cam1_FrameTypeZRST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ZRST') global_PVs['Cam1_FrameTypeONST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.ONST') global_PVs['Cam1_FrameTypeTWST'] = PV(params.camera_ioc_prefix + 'cam1:FrameType.TWST') global_PVs['Cam1_Display'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Cam1_SizeX'] = PV(params.camera_ioc_prefix + 'cam1:SizeX') global_PVs['Cam1_SizeY'] = PV(params.camera_ioc_prefix + 'cam1:SizeY') global_PVs['Cam1_SizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeX_RBV') global_PVs['Cam1_SizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:SizeY_RBV') global_PVs['Cam1_MaxSizeX_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeX_RBV') global_PVs['Cam1_MaxSizeY_RBV'] = PV(params.camera_ioc_prefix + 'cam1:MaxSizeY_RBV') global_PVs['Cam1PixelFormat_RBV'] = PV(params.camera_ioc_prefix + 'cam1:PixelFormat_RBV') global_PVs['Cam1_Image_Dtype'] = PV(params.camera_ioc_prefix + 'image1:DataType_RBV') global_PVs['Cam1_Image'] = PV(params.camera_ioc_prefix + 'image1:ArrayData') # hdf5 writer PV's global_PVs['HDF1_AutoSave'] = PV(params.camera_ioc_prefix + 'HDF1:AutoSave') global_PVs['HDF1_DeleteDriverFile'] = PV(params.camera_ioc_prefix + 'HDF1:DeleteDriverFile') global_PVs['HDF1_EnableCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:EnableCallbacks') global_PVs['HDF1_BlockingCallbacks'] = PV(params.camera_ioc_prefix + 'HDF1:BlockingCallbacks') global_PVs['HDF1_FileWriteMode'] = PV(params.camera_ioc_prefix + 'HDF1:FileWriteMode') global_PVs['HDF1_NumCapture'] = PV(params.camera_ioc_prefix + 'HDF1:NumCapture') global_PVs['HDF1_Capture'] = PV(params.camera_ioc_prefix + 'HDF1:Capture') global_PVs['HDF1_Capture_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:Capture_RBV') global_PVs['HDF1_FilePath'] = PV(params.camera_ioc_prefix + 'HDF1:FilePath') global_PVs['HDF1_FileName'] = PV(params.camera_ioc_prefix + 'HDF1:FileName') global_PVs['HDF1_FullFileName_RBV'] = PV(params.camera_ioc_prefix + 'HDF1:FullFileName_RBV') global_PVs['HDF1_FileTemplate'] = PV(params.camera_ioc_prefix + 'HDF1:FileTemplate') global_PVs['HDF1_ArrayPort'] = PV(params.camera_ioc_prefix + 'HDF1:NDArrayPort') global_PVs['HDF1_FileNumber'] = PV(params.camera_ioc_prefix + 'HDF1:FileNumber') global_PVs['HDF1_XMLFileName'] = PV(params.camera_ioc_prefix + 'HDF1:XMLFileName') global_PVs['HDF1_ExtraDimSizeN'] = PV(params.camera_ioc_prefix + 'HDF1:ExtraDimSizeN') global_PVs['HDF1_QueueSize'] = PV(params.camera_ioc_prefix + 'HDF1:QueueSize') global_PVs['HDF1_QueueFree'] = PV(params.camera_ioc_prefix + 'HDF1:QueueFree') # proc1 PV's global_PVs['Image1_Callbacks'] = PV(params.camera_ioc_prefix + 'image1:EnableCallbacks') global_PVs['Proc1_Callbacks'] = PV(params.camera_ioc_prefix + 'Proc1:EnableCallbacks') global_PVs['Proc1_ArrayPort'] = PV(params.camera_ioc_prefix + 'Proc1:NDArrayPort') global_PVs['Proc1_Filter_Enable'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFilter') global_PVs['Proc1_Filter_Type'] = PV(params.camera_ioc_prefix + 'Proc1:FilterType') global_PVs['Proc1_Num_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:NumFilter') global_PVs['Proc1_Reset_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:ResetFilter') global_PVs['Proc1_AutoReset_Filter'] = PV(params.camera_ioc_prefix + 'Proc1:AutoResetFilter') global_PVs['Proc1_Filter_Callbacks'] = PV(params.camera_ioc_prefix + 'Proc1:FilterCallbacks') global_PVs['Proc1_Enable_Background'] = PV(params.camera_ioc_prefix + 'Proc1:EnableBackground') global_PVs['Proc1_Enable_FlatField'] = PV(params.camera_ioc_prefix + 'Proc1:EnableFlatField') global_PVs['Proc1_Enable_Offset_Scale'] = PV(params.camera_ioc_prefix + 'Proc1:EnableOffsetScale') global_PVs['Proc1_Enable_Low_Clip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableLowClip') global_PVs['Proc1_Enable_High_Clip'] = PV(params.camera_ioc_prefix + 'Proc1:EnableHighClip') elif (params.camera_ioc_prefix == '2bmbSP1:'): global_PVs['Cam1_AcquireTimeAuto'] = PV(params.camera_ioc_prefix + 'cam1:AcquireTimeAuto') global_PVs['Cam1_FrameRateOnOff'] = PV(params.camera_ioc_prefix + 'cam1:FrameRateEnable') global_PVs['Cam1_TriggerSource'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSource') global_PVs['Cam1_TriggerOverlap'] = PV(params.camera_ioc_prefix + 'cam1:TriggerOverlap') global_PVs['Cam1_ExposureMode'] = PV(params.camera_ioc_prefix + 'cam1:ExposureMode') global_PVs['Cam1_TriggerSelector'] = PV(params.camera_ioc_prefix + 'cam1:TriggerSelector') global_PVs['Cam1_TriggerActivation'] = PV(params.camera_ioc_prefix + 'cam1:TriggerActivation') else: log.error('Detector %s is not defined' % params.camera_ioc_prefix) return global TESTING TESTING = params.testing user_info_update(global_PVs, params) if params.update_from_PVs: update_params_from_PVs(global_PVs, params) return global_PVs