def terminateValveControl(self, msg="NO_MSG"): endTest(msg) print(msg) if (self.stepper is not None): self.stepper.setVelocityLimit(0) self.stepper.setEngaged(0) self.stepper.close()
def onEncoderDetached(self, e): try: print("\nDetach event on Port %d Channel %d" % (detached.getHubPort(), detached.getChannel())) except PhidgetException as e: terminateValveControl("encoder detached! Phidget Exception " + str(e.code) + " " + e.details) try: tempVelocity = self.velocitySetting self.MEVStepper.setVelocity(0) tempPosition = self.encoder.getPosition() self.encoder.close() self.initEncoder(tempPosition) self.MEVStepper.setVelocity(tempVelocity) except Exception as e: endTest("Encoder detached error")
def onEncoderAttached(self, e): try: attached = e print("\nAttach Event Detected (Information Below)") print("===========================================") print("Library Version: %s" % attached.getLibraryVersion()) print("Serial Number: %d" % attached.getDeviceSerialNumber()) print("Channel: %d" % attached.getChannel()) print("Channel Class: %s" % attached.getChannelClass()) print("Channel Name: %s" % attached.getChannelName()) print("Device ID: %d" % attached.getDeviceID()) print("Device Version: %d" % attached.getDeviceVersion()) print("Device Name: %s" % attached.getDeviceName()) print("Device Class: %d" % attached.getDeviceClass()) print("\n") except Exception as e: endTest("Encoder attached error")
def initEncoder(self, serialNum, initPosition=0): self.encoder = Encoder() try: self.encoder.setDeviceSerialNumber(serialNum) self.encoder.setChannel(0) self.encoder.setOnAttachHandler(self.onEncoderAttached) self.encoder.setOnDetachHandler(self.onEncoderDetached) self.encoder.setOnErrorHandler(self.onErrorEvent) #self.encoder.setOnPositionChangeHandler(self.onPositionChanged) self.encoder.openWaitForAttachment(5000) self.encoder.setPosition(initPosition) self.encoder.setDataInterval(10) if (not self.encoder.getEnabled()): self.encoder.setEnabled(1) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) endTest("Encoder init error")
def onErrorEvent(self, e, eCode, description): print("Error event #%i : %s" % (eCode, description)) endTest("Encoder error")