set_config
Modify configuration parameters like baud rate, data bits, and flow control for an open serial port without closing and reopening the connection.
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 implementing the 'set_config' tool logic, which calls the serial manager to update port configuration.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 schema definition for the 'set_config' tool, including inputSchema used for validation.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 list_tools handler.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 to the 'set_config' handler in the call_tool implementation.elif name == "set_config": result = set_config(**arguments)
- src/uart_mcp/server.py:25-33 (helper)Import of the set_config handler and SET_CONFIG_TOOL schema for use in server.py.from .tools.port_ops import ( CLOSE_PORT_TOOL, GET_STATUS_TOOL, OPEN_PORT_TOOL, SET_CONFIG_TOOL, close_port, get_status, open_port, set_config,