set_config
Change configuration settings for an open serial port without closing it, including baud rate, data bits, parity, stop bits, flow control, and timeout values.
Instructions
修改已打开串口的配置(热更新,无需关闭重开)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes | 串口路径 | |
| baudrate | No | 波特率,支持的值:[300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600] | |
| bytesize | No | 数据位,支持的值:[5, 6, 7, 8] | |
| parity | No | 校验位,支持的值:['N', 'E', 'O', 'M', 'S'] | |
| stopbits | No | 停止位,支持的值:[1.0, 1.5, 2.0] | |
| flow_control | No | 流控制,支持的值:['none', 'hardware', 'software'] | |
| read_timeout_ms | No | 读取超时(毫秒),范围 0-60000 | |
| write_timeout_ms | No | 写入超时(毫秒),范围 0-60000 |
Implementation Reference
- src/uart_mcp/tools/port_ops.py:80-116 (handler)The handler function that executes the set_config tool logic by calling the serial manager's set_config method and returning the updated status dictionary.def set_config( port: str, baudrate: int | None = None, bytesize: int | None = None, parity: str | None = None, stopbits: float | None = None, flow_control: str | None = None, read_timeout_ms: int | None = None, write_timeout_ms: int | None = None, ) -> dict[str, Any]: """修改串口配置(热更新) Args: port: 串口路径 baudrate: 波特率(可选) bytesize: 数据位(可选) parity: 校验位(可选) stopbits: 停止位(可选) flow_control: 流控制(可选) read_timeout_ms: 读取超时(可选) write_timeout_ms: 写入超时(可选) Returns: 更新后的串口状态 """ manager = get_serial_manager() status = manager.set_config( port=port, baudrate=baudrate, bytesize=bytesize, parity=parity, stopbits=stopbits, flow_control=flow_control, read_timeout_ms=read_timeout_ms, write_timeout_ms=write_timeout_ms, ) return status.to_dict()
- The input schema and metadata definition for the set_config tool used in MCP registration.SET_CONFIG_TOOL: dict[str, Any] = { "name": "set_config", "description": "修改已打开串口的配置(热更新,无需关闭重开)", "inputSchema": { "type": "object", "properties": { "port": { "type": "string", "description": "串口路径", }, "baudrate": { "type": "integer", "description": f"波特率,支持的值:{list(SUPPORTED_BAUDRATES)}", }, "bytesize": { "type": "integer", "description": f"数据位,支持的值:{list(SUPPORTED_BYTESIZES)}", }, "parity": { "type": "string", "description": f"校验位,支持的值:{[p.value for p in Parity]}", }, "stopbits": { "type": "number", "description": f"停止位,支持的值:{[s.value for s in StopBits]}", }, "flow_control": { "type": "string", "description": f"流控制,支持的值:{[f.value for f in FlowControl]}", }, "read_timeout_ms": { "type": "integer", "description": "读取超时(毫秒),范围 0-60000", }, "write_timeout_ms": { "type": "integer", "description": "写入超时(毫秒),范围 0-60000", }, }, "required": ["port"], }, }
- src/uart_mcp/server.py:82-86 (registration)Registration of the set_config tool in the MCP server's list_tools handler, providing name, description, and input schema.types.Tool( name=SET_CONFIG_TOOL["name"], description=SET_CONFIG_TOOL["description"], inputSchema=SET_CONFIG_TOOL["inputSchema"], ),
- src/uart_mcp/server.py:154-155 (registration)Dispatch logic in the MCP server's call_tool handler that invokes the set_config function when the tool is called.elif name == "set_config": result = set_config(**arguments)