query
Send a command to a serial device and retrieve its reply in one call. Wait for an expected response or line silence, enabling request/response interactions with AT modems, CLI firmware, and PING-PONG devices.
Instructions
Send a command and return its reply in one call. Best for request/response devices (AT modems, CLI firmware, 'PING' -> 'PONG' sketches).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes | Port device from list_ports (e.g. /dev/cu.usbserial-0001, /dev/ttyUSB0, COM3), or a pyserial URL such as socket://host:port, rfc2217://host:port or loop://. | |
| regex | No | Interpret `expect` as a regex. | |
| expect | No | Return as soon as this substring/regex shows up in the reply (e.g. 'OK', '\n'). Omit to collect until the device goes quiet. | |
| command | Yes | Command text to send (newline is appended). | |
| newline | No | Line ending appended to the command. | |
| settle_ms | No | Without `expect`: stop once the line is silent for this many ms. | |
| timeout_s | No | Max seconds to wait for the reply. | |
| clear_first | No | Discard stale buffered data before sending, so the reply is clean. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sent | Yes | ||
| bytes | Yes | ||
| error | No | ||
| matched | No | Whether `expect` was seen; null when no `expect` was given. | |
| response | Yes | ||
| elapsed_s | Yes |