MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / command

Method command

tests/utils/api_client.py:121–167  ·  view source on GitHub ↗

Send a command and return the result. Args: command: Command name (e.g., "io.getStatus") params: Optional parameters dict timeout: Optional timeout override Returns: Result dict on success Raises: APIErro

(
        self,
        command: str,
        params: Optional[dict] = None,
        timeout: Optional[float] = None,
    )

Source from the content-addressed store, hash-verified

119 self._socket.sendall(data.encode("utf-8"))
120
121 def command(
122 self,
123 command: str,
124 params: Optional[dict] = None,
125 timeout: Optional[float] = None,
126 ) -> dict:
127 """
128 Send a command and return the result.
129
130 Args:
131 command: Command name (e.g., "io.getStatus")
132 params: Optional parameters dict
133 timeout: Optional timeout override
134
135 Returns:
136 Result dict on success
137
138 Raises:
139 APIError: If command fails
140 TimeoutError: If response not received in time
141 """
142 request_id = str(uuid.uuid4())
143 message = {"type": "command", "id": request_id, "command": command}
144
145 if params:
146 message["params"] = params
147
148 self._send_message(message)
149
150 deadline = time.time() + (timeout or self.timeout)
151
152 while True:
153 remaining = deadline - time.time()
154 if remaining <= 0:
155 raise TimeoutError("Timeout waiting for response")
156
157 response = self._recv_message(remaining)
158
159 if response.get("type") == "response" and response.get("id") == request_id:
160 if response.get("success"):
161 return response.get("result", {})
162 else:
163 error = response.get("error", {})
164 raise APIError(
165 error.get("code", "UNKNOWN"),
166 error.get("message", "Unknown error"),
167 )
168
169 def batch(
170 self, commands: list[dict], timeout: Optional[float] = None

Callers 15

_checkFunction · 0.95
set_bus_typeMethod · 0.95
connect_deviceMethod · 0.95
disconnect_deviceMethod · 0.95
is_connectedMethod · 0.95
enable_csv_exportMethod · 0.95
disable_csv_exportMethod · 0.95
get_csv_export_statusMethod · 0.95
load_projectMethod · 0.95
create_new_projectMethod · 0.95
get_project_statusMethod · 0.95
set_dashboard_fpsMethod · 0.95

Calls 4

_send_messageMethod · 0.95
_recv_messageMethod · 0.95
APIErrorClass · 0.85
getMethod · 0.45