class Window(QtWidgets.QWidget): 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 btn_click(self): text = str(self.m.get('RBV')) self.l.setText(text)
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")