Serial ViewModel
controller.presentation.view_models.serial_view_model
串口视图模型 - Presentation层 纯信号转发层,不包含业务逻辑
SerialViewModel
SerialViewModel(serial_service: SerialApplicationService, command_hub_service: CommandHubService, parent=None)
Bases: BaseViewModel
串口视图模型。
纯信号转发层,不包含业务逻辑,负责 UI 与串口服务的交互。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
port_list_updated |
pyqtSignal
|
端口列表更新信号,携带端口列表。 |
serial_service |
SerialApplicationService
|
串口应用服务。 |
command_hub_service |
CommandHubService
|
命令中心服务。 |
初始化视图模型。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
serial_service
|
SerialApplicationService
|
串口应用服务。 |
必需 |
command_hub_service
|
CommandHubService
|
命令中心服务。 |
必需 |
parent
|
QObject
|
父对象. Defaults to None. |
None
|
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
refresh_ports
refresh_ports() -> None
刷新端口列表命令 - 直接转发到Service。
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
40 41 42 | |
connect_serial
connect_serial(port: str, config: Dict[str, Any]) -> None
连接串口命令 - 直接转发到Service。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
port
|
str
|
端口名称。 |
必需 |
config
|
Dict[str, Any]
|
配置参数。 |
必需 |
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
44 45 46 47 48 49 50 51 | |
disconnect_serial
disconnect_serial() -> None
断开连接命令 - 直接转发到Service。
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
53 54 55 | |
get_available_ports
get_available_ports() -> List[str]
获取可用端口列表 - 委托给Service。
返回:
| 类型 | 描述 |
|---|---|
List[str]
|
List[str]: 端口列表。 |
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
59 60 61 62 63 64 65 | |
get_current_port
get_current_port() -> Optional[str]
获取当前连接的端口 - 委托给Service。
返回:
| 类型 | 描述 |
|---|---|
Optional[str]
|
Optional[str]: 端口名称。 |
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
67 68 69 70 71 72 73 | |
get_connection_status
get_connection_status() -> bool
获取连接状态 - 委托给Service。
返回:
| 名称 | 类型 | 描述 |
|---|---|---|
bool |
bool
|
是否已连接。 |
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
75 76 77 78 79 80 81 | |
get_port_info
get_port_info(port_name: str) -> Optional[Dict[str, str]]
获取端口信息 - 委托给Service。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
port_name
|
str
|
端口名称。 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Optional[Dict[str, str]]
|
Optional[Dict[str, str]]: 端口信息。 |
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
83 84 85 86 87 88 89 90 91 92 | |
cleanup
cleanup() -> None
清理视图模型 - 断开信号连接。
源代码位于: src/controller/controller/presentation/view_models/serial_view_model.py
110 111 112 113 | |