def _response_validator(response, expected_responses): for r in expected_responses: if response.startswith(r): return response raise QRTCommandException('Expected %s but got %s' % (expected_responses, response))
def connect(self, on_connect, on_disconnect=None, on_event=None): """Connect to QTM :param on_connect: Called on successful connection to QTM. Callback receives an :class:`QRTConnection` object. :param on_disconnect: Called if connection fails or when connection is lost. :param on_event: Called when there's an event from QTM. """ point = TCP4ClientEndpoint(reactor, self.host, self.port) factory = QRTFactory(self.version, on_disconnect, on_event, self.logger) try: p = yield point.connect(factory) except ConnectionRefusedError as reason: if on_disconnect: on_disconnect(QRTCommandException(str(reason))) return except Exception as reason: if on_disconnect: on_disconnect(reason) return try: version = yield p.connected_d except Exception as reason: if on_disconnect: p.on_disconnect = None p.transport.loseConnection() on_disconnect(reason) return on_connect(QRTConnection(p), version)
async def get_parameters(self, parameters=None): """Get the settings for the requested component(s) of QTM in XML format. :param parameters: A list of parameters to request. Could be 'all' or any combination of 'general', '3d', '6d', 'analog', 'force', 'gazevector', 'image', 'skeleton', 'skeleton:global', 'calibration'. :rtype: An XML string containing the requested settings. See QTM RT Documentation for details. """ if parameters is None: parameters = ["all"] else: for parameter in parameters: if not parameter in [ "all", "general", "3d", "6d", "analog", "force", "gazevector", "image", "skeleton", "skeleton:global", "calibration", ]: raise QRTCommandException("%s is not a valid parameter" % parameter) cmd = "getparameters %s" % " ".join(parameters) return await asyncio.wait_for(self._protocol.send_command(cmd), timeout=self._timeout)
def _validate_components(components): for component in components: if not component.lower() in [ "2d", "2dlin", "3d", "3dres", "3dnolabels", "3dnolabelsres", "analog", "analogsingle", "force", "forcesingle", "6d", "6dres", "6deuler", "6deulerres", "gazevector", "image", "timecode", "skeleton", "skeleton:global", ]: raise QRTCommandException("%s is not a valid component" % component)
async def wrapper(*args, **kwargs): response = await function(*args, **kwargs) for expected_response in expected_responses: if response.startswith(expected_response): return response raise QRTCommandException("Expected %s but got %s" % (expected_responses, response))
async def calibrate(self, timeout=600): # Timeout 10 min. """Start calibration and return calibration result. :param timeout_: Calibration timeout. :rtype: An XML string containing the calibration result. See QTM RT Documentation for details. """ cmd = "calibrate" response = await asyncio.wait_for(self._protocol.send_command(cmd), timeout=self._timeout) if response != b"Starting calibration": raise QRTCommandException(response) return await asyncio.wait_for(self._protocol.receive_response(), timeout=timeout)