sdev 0.4.3__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sdev-0.4.3/sdev.egg-info → sdev-0.4.4}/PKG-INFO +10 -10
- {sdev-0.4.3 → sdev-0.4.4}/README.md +9 -9
- {sdev-0.4.3 → sdev-0.4.4}/pyproject.toml +1 -1
- {sdev-0.4.3 → sdev-0.4.4}/sdev/__init__.py +4 -3
- {sdev-0.4.3 → sdev-0.4.4}/sdev/class_wrapper.py +23 -7
- {sdev-0.4.3 → sdev-0.4.4}/sdev/cli_wrapper.py +1 -3
- {sdev-0.4.3 → sdev-0.4.4/sdev.egg-info}/PKG-INFO +10 -10
- {sdev-0.4.3 → sdev-0.4.4}/setup.py +1 -1
- {sdev-0.4.3 → sdev-0.4.4}/LICENSE +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/MANIFEST.in +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev/core.py +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev/demoboard/__init__.py +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev/demoboard/functional.py +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev/relay/__init__.py +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev/relay/functional.py +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev.egg-info/SOURCES.txt +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev.egg-info/dependency_links.txt +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev.egg-info/entry_points.txt +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev.egg-info/requires.txt +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/sdev.egg-info/top_level.txt +0 -0
- {sdev-0.4.3 → sdev-0.4.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sdev
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: 串口控制器工具包
|
|
5
5
|
Home-page: https://github.com/klrc/sdev
|
|
6
6
|
Author: klrc
|
|
@@ -62,39 +62,39 @@ sdev --no-check-alive shell "echo hello"
|
|
|
62
62
|
|
|
63
63
|
## 快速使用 (Python)
|
|
64
64
|
|
|
65
|
-
推荐使用 `sdev()` 工厂函数或 `Demoboard`
|
|
65
|
+
推荐使用 `sdev()` 工厂函数或 `Demoboard` 类,它们提供了更高层、更易用的接口。`Demoboard` 在实例化时默认会自动执行 `check_alive()`。
|
|
66
66
|
|
|
67
67
|
```python
|
|
68
68
|
from sdev import sdev
|
|
69
69
|
|
|
70
70
|
# 使用 context manager 自动连接/断开
|
|
71
71
|
with sdev("/dev/ttyUSB0", 115200) as board:
|
|
72
|
-
#
|
|
72
|
+
# 实例化时默认已执行 check_alive(),确保板子已就绪
|
|
73
73
|
out = board.shell("ls") # 执行命令并返回输出行列表
|
|
74
74
|
print(out)
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
使用旧版兼容接口:
|
|
78
78
|
|
|
79
79
|
```python
|
|
80
80
|
from sdev import Demoboard
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
board.
|
|
85
|
-
|
|
86
|
-
board.disconnect()
|
|
82
|
+
with Demoboard("/dev/ttyUSB0", 115200) as board:
|
|
83
|
+
# execute_command 是 shell 的别名,方便旧代码迁移
|
|
84
|
+
out = board.execute_command("ls", flag=" #")
|
|
85
|
+
print(out)
|
|
87
86
|
```
|
|
88
87
|
|
|
89
88
|
## 主要接口
|
|
90
89
|
|
|
91
90
|
### Demoboard (推荐)
|
|
92
91
|
|
|
93
|
-
继承自 `SerialDevice
|
|
92
|
+
继承自 `SerialDevice`,提供针对开发板的高层封装。实例化时会自动调用 `check_alive()`。
|
|
94
93
|
|
|
95
94
|
| 方法 | 说明 |
|
|
96
95
|
|------|------|
|
|
97
96
|
| `shell(cmd, prompt_flag=" #", timeout=None, stream=False)` | 清缓冲 -> 发送命令 -> 等待命令回显 -> 等待提示符。返回输出列表或生成器。 |
|
|
97
|
+
| `execute_command(cmd, flag, timeout=None, stream=False)` | `shell` 方法的别名,用于兼容旧版代码。 |
|
|
98
98
|
| `check_alive(uboot_flag="uboot#", prompt_flag=" #", response_timeout=3)` | 存活检测:处理 U-Boot 挂起、发送 Ctrl-C 唤醒并等待提示符。 |
|
|
99
99
|
|
|
100
100
|
### SerialDevice (底层)
|
|
@@ -28,39 +28,39 @@ sdev --no-check-alive shell "echo hello"
|
|
|
28
28
|
|
|
29
29
|
## 快速使用 (Python)
|
|
30
30
|
|
|
31
|
-
推荐使用 `sdev()` 工厂函数或 `Demoboard`
|
|
31
|
+
推荐使用 `sdev()` 工厂函数或 `Demoboard` 类,它们提供了更高层、更易用的接口。`Demoboard` 在实例化时默认会自动执行 `check_alive()`。
|
|
32
32
|
|
|
33
33
|
```python
|
|
34
34
|
from sdev import sdev
|
|
35
35
|
|
|
36
36
|
# 使用 context manager 自动连接/断开
|
|
37
37
|
with sdev("/dev/ttyUSB0", 115200) as board:
|
|
38
|
-
#
|
|
38
|
+
# 实例化时默认已执行 check_alive(),确保板子已就绪
|
|
39
39
|
out = board.shell("ls") # 执行命令并返回输出行列表
|
|
40
40
|
print(out)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
使用旧版兼容接口:
|
|
44
44
|
|
|
45
45
|
```python
|
|
46
46
|
from sdev import Demoboard
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
board.
|
|
51
|
-
|
|
52
|
-
board.disconnect()
|
|
48
|
+
with Demoboard("/dev/ttyUSB0", 115200) as board:
|
|
49
|
+
# execute_command 是 shell 的别名,方便旧代码迁移
|
|
50
|
+
out = board.execute_command("ls", flag=" #")
|
|
51
|
+
print(out)
|
|
53
52
|
```
|
|
54
53
|
|
|
55
54
|
## 主要接口
|
|
56
55
|
|
|
57
56
|
### Demoboard (推荐)
|
|
58
57
|
|
|
59
|
-
继承自 `SerialDevice
|
|
58
|
+
继承自 `SerialDevice`,提供针对开发板的高层封装。实例化时会自动调用 `check_alive()`。
|
|
60
59
|
|
|
61
60
|
| 方法 | 说明 |
|
|
62
61
|
|------|------|
|
|
63
62
|
| `shell(cmd, prompt_flag=" #", timeout=None, stream=False)` | 清缓冲 -> 发送命令 -> 等待命令回显 -> 等待提示符。返回输出列表或生成器。 |
|
|
63
|
+
| `execute_command(cmd, flag, timeout=None, stream=False)` | `shell` 方法的别名,用于兼容旧版代码。 |
|
|
64
64
|
| `check_alive(uboot_flag="uboot#", prompt_flag=" #", response_timeout=3)` | 存活检测:处理 U-Boot 挂起、发送 Ctrl-C 唤醒并等待提示符。 |
|
|
65
65
|
|
|
66
66
|
### SerialDevice (底层)
|
|
@@ -14,7 +14,7 @@ from typing import Literal
|
|
|
14
14
|
from .core import SerialDevice
|
|
15
15
|
from .class_wrapper import Demoboard, Relay
|
|
16
16
|
|
|
17
|
-
__version__ = "0.4.
|
|
17
|
+
__version__ = "0.4.4"
|
|
18
18
|
__author__ = "klrc"
|
|
19
19
|
__email__ = "1440698245@qq.com"
|
|
20
20
|
|
|
@@ -24,6 +24,7 @@ def sdev(
|
|
|
24
24
|
baudrate: int = 115200,
|
|
25
25
|
*,
|
|
26
26
|
device_type: Literal["demoboard", "relay"] = "demoboard",
|
|
27
|
+
**kwargs,
|
|
27
28
|
):
|
|
28
29
|
"""
|
|
29
30
|
构造一个设备实例。
|
|
@@ -31,9 +32,9 @@ def sdev(
|
|
|
31
32
|
默认返回 Demoboard,后续可根据需要扩展其它类型。
|
|
32
33
|
"""
|
|
33
34
|
if device_type == "demoboard":
|
|
34
|
-
return Demoboard(port, baudrate)
|
|
35
|
+
return Demoboard(port, baudrate, **kwargs)
|
|
35
36
|
if device_type == "relay":
|
|
36
|
-
return Relay(port, baudrate)
|
|
37
|
+
return Relay(port, baudrate, **kwargs)
|
|
37
38
|
raise ValueError(f"unsupported device_type: {device_type!r}")
|
|
38
39
|
|
|
39
40
|
|
|
@@ -21,11 +21,25 @@ class Demoboard(SerialDevice):
|
|
|
21
21
|
- 提供 shell() / check_alive() 等高层方法。
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
def __init__(self,
|
|
25
|
-
super().__init__(
|
|
26
|
-
self.check_alive
|
|
27
|
-
|
|
28
|
-
def
|
|
24
|
+
def __init__(self, port: str, baudrate: int = 115200, check_alive: bool = True):
|
|
25
|
+
super().__init__(port, baudrate)
|
|
26
|
+
self._auto_check_alive = check_alive
|
|
27
|
+
|
|
28
|
+
def connect(self) -> None:
|
|
29
|
+
"""连接并自动执行 check_alive。"""
|
|
30
|
+
if self._is_connected:
|
|
31
|
+
return
|
|
32
|
+
super().connect()
|
|
33
|
+
if self._auto_check_alive:
|
|
34
|
+
self.check_alive()
|
|
35
|
+
|
|
36
|
+
def execute_command(
|
|
37
|
+
self,
|
|
38
|
+
cmd: str,
|
|
39
|
+
flag: str = " #",
|
|
40
|
+
timeout: Optional[float] = None,
|
|
41
|
+
stream: bool = False,
|
|
42
|
+
) -> Union[List[str], Generator[str, None, None]]:
|
|
29
43
|
"""alias for shell"""
|
|
30
44
|
return self.shell(cmd, prompt_flag=flag, timeout=timeout, stream=stream)
|
|
31
45
|
|
|
@@ -61,8 +75,10 @@ class Relay(SerialDevice):
|
|
|
61
75
|
- 具体继电器控制逻辑后续在 sdev.relay.functional 中补充。
|
|
62
76
|
"""
|
|
63
77
|
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
def __init__(self, port: str, baudrate: int = 115200, **kwargs):
|
|
79
|
+
# 吞掉不支持的参数,确保与 sdev() 工厂兼容
|
|
80
|
+
kwargs.pop("check_alive", None)
|
|
81
|
+
super().__init__(port, baudrate)
|
|
66
82
|
|
|
67
83
|
|
|
68
84
|
__all__ = ["Demoboard", "Relay"]
|
|
@@ -27,10 +27,8 @@ def _get_default_baudrate() -> int:
|
|
|
27
27
|
def cmd_shell(args: argparse.Namespace) -> int:
|
|
28
28
|
port = args.port or _get_default_port()
|
|
29
29
|
baudrate = args.baudrate or _get_default_baudrate()
|
|
30
|
-
with Demoboard(port, baudrate) as board:
|
|
30
|
+
with Demoboard(port, baudrate, check_alive=not args.no_check_alive) as board:
|
|
31
31
|
try:
|
|
32
|
-
if not args.no_check_alive:
|
|
33
|
-
board.check_alive()
|
|
34
32
|
board.shell(args.command, prompt_flag=args.flag, timeout=args.timeout)
|
|
35
33
|
except TimeoutError as e:
|
|
36
34
|
print(e, file=sys.stderr)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sdev
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: 串口控制器工具包
|
|
5
5
|
Home-page: https://github.com/klrc/sdev
|
|
6
6
|
Author: klrc
|
|
@@ -62,39 +62,39 @@ sdev --no-check-alive shell "echo hello"
|
|
|
62
62
|
|
|
63
63
|
## 快速使用 (Python)
|
|
64
64
|
|
|
65
|
-
推荐使用 `sdev()` 工厂函数或 `Demoboard`
|
|
65
|
+
推荐使用 `sdev()` 工厂函数或 `Demoboard` 类,它们提供了更高层、更易用的接口。`Demoboard` 在实例化时默认会自动执行 `check_alive()`。
|
|
66
66
|
|
|
67
67
|
```python
|
|
68
68
|
from sdev import sdev
|
|
69
69
|
|
|
70
70
|
# 使用 context manager 自动连接/断开
|
|
71
71
|
with sdev("/dev/ttyUSB0", 115200) as board:
|
|
72
|
-
#
|
|
72
|
+
# 实例化时默认已执行 check_alive(),确保板子已就绪
|
|
73
73
|
out = board.shell("ls") # 执行命令并返回输出行列表
|
|
74
74
|
print(out)
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
使用旧版兼容接口:
|
|
78
78
|
|
|
79
79
|
```python
|
|
80
80
|
from sdev import Demoboard
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
board.
|
|
85
|
-
|
|
86
|
-
board.disconnect()
|
|
82
|
+
with Demoboard("/dev/ttyUSB0", 115200) as board:
|
|
83
|
+
# execute_command 是 shell 的别名,方便旧代码迁移
|
|
84
|
+
out = board.execute_command("ls", flag=" #")
|
|
85
|
+
print(out)
|
|
87
86
|
```
|
|
88
87
|
|
|
89
88
|
## 主要接口
|
|
90
89
|
|
|
91
90
|
### Demoboard (推荐)
|
|
92
91
|
|
|
93
|
-
继承自 `SerialDevice
|
|
92
|
+
继承自 `SerialDevice`,提供针对开发板的高层封装。实例化时会自动调用 `check_alive()`。
|
|
94
93
|
|
|
95
94
|
| 方法 | 说明 |
|
|
96
95
|
|------|------|
|
|
97
96
|
| `shell(cmd, prompt_flag=" #", timeout=None, stream=False)` | 清缓冲 -> 发送命令 -> 等待命令回显 -> 等待提示符。返回输出列表或生成器。 |
|
|
97
|
+
| `execute_command(cmd, flag, timeout=None, stream=False)` | `shell` 方法的别名,用于兼容旧版代码。 |
|
|
98
98
|
| `check_alive(uboot_flag="uboot#", prompt_flag=" #", response_timeout=3)` | 存活检测:处理 U-Boot 挂起、发送 Ctrl-C 唤醒并等待提示符。 |
|
|
99
99
|
|
|
100
100
|
### SerialDevice (底层)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|