sdev 0.1.0__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.1.0/LICENSE +21 -0
- sdev-0.1.0/MANIFEST.in +6 -0
- sdev-0.1.0/PKG-INFO +78 -0
- sdev-0.1.0/README.md +44 -0
- sdev-0.1.0/pyproject.toml +38 -0
- sdev-0.1.0/sdev/__init__.py +13 -0
- sdev-0.1.0/sdev/serial_controller.py +264 -0
- sdev-0.1.0/sdev.egg-info/PKG-INFO +78 -0
- sdev-0.1.0/sdev.egg-info/SOURCES.txt +12 -0
- sdev-0.1.0/sdev.egg-info/dependency_links.txt +1 -0
- sdev-0.1.0/sdev.egg-info/requires.txt +2 -0
- sdev-0.1.0/sdev.egg-info/top_level.txt +1 -0
- sdev-0.1.0/setup.cfg +4 -0
- sdev-0.1.0/setup.py +35 -0
sdev-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 klrc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
sdev-0.1.0/MANIFEST.in
ADDED
sdev-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdev
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 串口控制器工具包
|
|
5
|
+
Home-page: https://github.com/klrc/sdev
|
|
6
|
+
Author: klrc
|
|
7
|
+
Author-email: klrc <144069824@qq.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/klrc/sdev
|
|
10
|
+
Project-URL: Repository, https://github.com/klrc/sdev
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/klrc/sdev/issues
|
|
12
|
+
Keywords: serial,controller,hardware,embedded
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: System :: Hardware
|
|
25
|
+
Requires-Python: >=3.7
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pyserial>=3.5
|
|
29
|
+
Requires-Dist: loguru>=0.6.0
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-python
|
|
34
|
+
|
|
35
|
+
# SDEV
|
|
36
|
+
|
|
37
|
+
串口控制器工具包
|
|
38
|
+
|
|
39
|
+
## 安装
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install sdev
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 使用方法
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from sdev import SerialController
|
|
49
|
+
|
|
50
|
+
# 创建串口控制器实例
|
|
51
|
+
controller = SerialController(serial_port="/dev/ttyUSB0", baudrate=115200)
|
|
52
|
+
|
|
53
|
+
# 连接串口
|
|
54
|
+
if controller.connect():
|
|
55
|
+
print("连接成功")
|
|
56
|
+
|
|
57
|
+
# 执行命令
|
|
58
|
+
result = controller.execute_command("ls")
|
|
59
|
+
print(result)
|
|
60
|
+
|
|
61
|
+
# 断开连接
|
|
62
|
+
controller.disconnect()
|
|
63
|
+
else:
|
|
64
|
+
print("连接失败")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 功能特性
|
|
68
|
+
|
|
69
|
+
- 支持串口通信
|
|
70
|
+
- 命令执行和响应处理
|
|
71
|
+
- 自动ANSI转义码清理
|
|
72
|
+
- 连接状态管理
|
|
73
|
+
|
|
74
|
+
## 依赖
|
|
75
|
+
|
|
76
|
+
- Python >= 3.7
|
|
77
|
+
- pyserial >= 3.5
|
|
78
|
+
- loguru >= 0.6.0
|
sdev-0.1.0/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# SDEV
|
|
2
|
+
|
|
3
|
+
串口控制器工具包
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install sdev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用方法
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from sdev import SerialController
|
|
15
|
+
|
|
16
|
+
# 创建串口控制器实例
|
|
17
|
+
controller = SerialController(serial_port="/dev/ttyUSB0", baudrate=115200)
|
|
18
|
+
|
|
19
|
+
# 连接串口
|
|
20
|
+
if controller.connect():
|
|
21
|
+
print("连接成功")
|
|
22
|
+
|
|
23
|
+
# 执行命令
|
|
24
|
+
result = controller.execute_command("ls")
|
|
25
|
+
print(result)
|
|
26
|
+
|
|
27
|
+
# 断开连接
|
|
28
|
+
controller.disconnect()
|
|
29
|
+
else:
|
|
30
|
+
print("连接失败")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 功能特性
|
|
34
|
+
|
|
35
|
+
- 支持串口通信
|
|
36
|
+
- 命令执行和响应处理
|
|
37
|
+
- 自动ANSI转义码清理
|
|
38
|
+
- 连接状态管理
|
|
39
|
+
|
|
40
|
+
## 依赖
|
|
41
|
+
|
|
42
|
+
- Python >= 3.7
|
|
43
|
+
- pyserial >= 3.5
|
|
44
|
+
- loguru >= 0.6.0
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sdev"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "串口控制器工具包"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "klrc", email = "144069824@qq.com"},
|
|
13
|
+
]
|
|
14
|
+
keywords = ["serial", "controller", "hardware", "embedded"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.7",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
"Topic :: System :: Hardware",
|
|
28
|
+
]
|
|
29
|
+
requires-python = ">=3.7"
|
|
30
|
+
dependencies = [
|
|
31
|
+
"pyserial>=3.5",
|
|
32
|
+
"loguru>=0.6.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/klrc/sdev"
|
|
37
|
+
Repository = "https://github.com/klrc/sdev"
|
|
38
|
+
"Bug Tracker" = "https://github.com/klrc/sdev/issues"
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import serial
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
import threading
|
|
5
|
+
import queue
|
|
6
|
+
import re
|
|
7
|
+
from loguru import logger
|
|
8
|
+
|
|
9
|
+
CTRL_C = chr(0x03)
|
|
10
|
+
|
|
11
|
+
class SerialController:
|
|
12
|
+
"""异步串口控制器,使用后台线程读取串口数据"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, serial_port="/dev/ttyUSB0", baudrate=115200, log_level="DEBUG", mcp_mode=False):
|
|
15
|
+
self.serial_port = serial_port
|
|
16
|
+
self.baudrate = baudrate
|
|
17
|
+
self.serial_conn = None
|
|
18
|
+
self.is_connected = False
|
|
19
|
+
self.mcp_mode = mcp_mode # MCP模式下禁用终端输出
|
|
20
|
+
|
|
21
|
+
# 异步处理相关
|
|
22
|
+
self.read_thread = None
|
|
23
|
+
self.output_queue = queue.Queue()
|
|
24
|
+
self.stop_reading = False
|
|
25
|
+
self.last_message = None
|
|
26
|
+
|
|
27
|
+
# 设置调试模式
|
|
28
|
+
logger.remove()
|
|
29
|
+
if not mcp_mode: # MCP模式下禁用日志输出
|
|
30
|
+
logger.add(sys.stdout, level=log_level, colorize=True)
|
|
31
|
+
|
|
32
|
+
def _remove_ansi_codes(self, text):
|
|
33
|
+
"""移除文本中的ANSI转义码"""
|
|
34
|
+
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
|
35
|
+
return ansi_escape.sub('', text)
|
|
36
|
+
|
|
37
|
+
def _serial_reader(self):
|
|
38
|
+
"""后台线程:持续读取串口数据到队列"""
|
|
39
|
+
while not self.stop_reading and self.serial_conn and self.serial_conn.is_open:
|
|
40
|
+
try:
|
|
41
|
+
line = self.serial_conn.readline()
|
|
42
|
+
if line:
|
|
43
|
+
try:
|
|
44
|
+
decoded_line = line.decode('utf-8').strip()
|
|
45
|
+
if decoded_line:
|
|
46
|
+
self.output_queue.put(decoded_line)
|
|
47
|
+
self.last_message = decoded_line
|
|
48
|
+
except UnicodeDecodeError:
|
|
49
|
+
continue
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logger.debug(f"串口读取异常: {e}")
|
|
52
|
+
break
|
|
53
|
+
|
|
54
|
+
def connect(self):
|
|
55
|
+
"""连接串口并启动后台读取线程"""
|
|
56
|
+
if self.is_connected:
|
|
57
|
+
return True
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
self.serial_conn = serial.Serial(self.serial_port, self.baudrate, timeout=0.1)
|
|
61
|
+
|
|
62
|
+
if not self.serial_conn.is_open:
|
|
63
|
+
raise Exception(f"无法打开串口 {self.serial_port}")
|
|
64
|
+
|
|
65
|
+
# 启动后台读取线程
|
|
66
|
+
self.stop_reading = False
|
|
67
|
+
self.read_thread = threading.Thread(target=self._serial_reader, daemon=True)
|
|
68
|
+
self.read_thread.start()
|
|
69
|
+
|
|
70
|
+
self.is_connected = True
|
|
71
|
+
logger.success(f"串口连接成功: {self.serial_port}@{self.baudrate}")
|
|
72
|
+
return True
|
|
73
|
+
|
|
74
|
+
except Exception as e:
|
|
75
|
+
logger.error(f"串口连接失败: {e}")
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
def disconnect(self):
|
|
79
|
+
"""断开串口连接并停止后台线程"""
|
|
80
|
+
if not self.is_connected:
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
# 执行退出清理命令,多次发送确保中断任何运行中的程序
|
|
84
|
+
self.execute_command(CTRL_C, " #")
|
|
85
|
+
|
|
86
|
+
if not self.mcp_mode:
|
|
87
|
+
print() # 强制换行
|
|
88
|
+
try:
|
|
89
|
+
# 停止后台读取线程
|
|
90
|
+
self.stop_reading = True
|
|
91
|
+
if self.read_thread and self.read_thread.is_alive():
|
|
92
|
+
self.read_thread.join(timeout=1)
|
|
93
|
+
|
|
94
|
+
# 关闭串口
|
|
95
|
+
if self.serial_conn and self.serial_conn.is_open:
|
|
96
|
+
self.serial_conn.close()
|
|
97
|
+
|
|
98
|
+
self.is_connected = False
|
|
99
|
+
logger.success("串口连接已断开")
|
|
100
|
+
|
|
101
|
+
except Exception as e:
|
|
102
|
+
logger.error(f"断开连接时出错: {e}")
|
|
103
|
+
|
|
104
|
+
def get_queue_size(self):
|
|
105
|
+
"""获取当前队列中的数据数量"""
|
|
106
|
+
return self.output_queue.qsize()
|
|
107
|
+
|
|
108
|
+
def clear_queue(self):
|
|
109
|
+
"""清空输出队列"""
|
|
110
|
+
cleared_count = 0
|
|
111
|
+
while not self.output_queue.empty():
|
|
112
|
+
try:
|
|
113
|
+
self.output_queue.get_nowait()
|
|
114
|
+
cleared_count += 1
|
|
115
|
+
except queue.Empty:
|
|
116
|
+
break
|
|
117
|
+
|
|
118
|
+
if cleared_count > 0:
|
|
119
|
+
logger.debug(f"清空队列,丢弃 {cleared_count} 条消息")
|
|
120
|
+
|
|
121
|
+
def send(self, command):
|
|
122
|
+
"""发送命令到串口"""
|
|
123
|
+
if not self.is_connected or not self.serial_conn:
|
|
124
|
+
logger.error("串口未连接")
|
|
125
|
+
return False
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
self.serial_conn.write((command + "\n").encode('utf-8'))
|
|
129
|
+
self.serial_conn.flush()
|
|
130
|
+
return True
|
|
131
|
+
except Exception as e:
|
|
132
|
+
logger.error(f"发送命令失败: {e}")
|
|
133
|
+
return False
|
|
134
|
+
|
|
135
|
+
def reap(self, pattern=None, timeout_seconds=None, highlight_cmd=False):
|
|
136
|
+
"""从队列读取数据直到找到指定pattern或超时"""
|
|
137
|
+
if not self.is_connected:
|
|
138
|
+
logger.error("串口未连接")
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
output_lines = []
|
|
142
|
+
start_time = time.time()
|
|
143
|
+
|
|
144
|
+
logger.debug(f"等待pattern: {pattern}, 队列当前大小: {self.get_queue_size()}")
|
|
145
|
+
|
|
146
|
+
while timeout_seconds is None or time.time() - start_time < timeout_seconds:
|
|
147
|
+
try:
|
|
148
|
+
# 非阻塞获取队列数据
|
|
149
|
+
line = self.output_queue.get(timeout=0.1)
|
|
150
|
+
output_lines.append(line)
|
|
151
|
+
|
|
152
|
+
if not self.mcp_mode: # 仅在非MCP模式下输出到终端
|
|
153
|
+
if len(output_lines) == 1 and highlight_cmd: # 粉色高亮 输入命令回显
|
|
154
|
+
print(f"\033[95m{output_lines[0]}\033[0m")
|
|
155
|
+
elif pattern and pattern in line: # 绿色高亮 命令匹配pattern
|
|
156
|
+
clean_line = self._remove_ansi_codes(line)
|
|
157
|
+
highlighted_line = clean_line.replace(pattern, f"\033[32m{pattern}\033[90m")
|
|
158
|
+
highlighted_line = f"\033[90m{highlighted_line}\033[0m"
|
|
159
|
+
print(highlighted_line, end=" ")
|
|
160
|
+
else: # 浅灰色 其他回显
|
|
161
|
+
clean_line = self._remove_ansi_codes(line)
|
|
162
|
+
print(f"\033[90m{clean_line}\033[0m")
|
|
163
|
+
|
|
164
|
+
# 检查pattern匹配(无论是否MCP模式都要检查)
|
|
165
|
+
if pattern and pattern in line:
|
|
166
|
+
logger.debug(f"找到pattern: {pattern}")
|
|
167
|
+
if not self.mcp_mode and not pattern.endswith(" #"): # 不常见的pattern匹配符,大概率需要输出换行
|
|
168
|
+
print()
|
|
169
|
+
return output_lines
|
|
170
|
+
|
|
171
|
+
except queue.Empty:
|
|
172
|
+
continue
|
|
173
|
+
except Exception as e:
|
|
174
|
+
logger.debug(f"队列读取异常: {e}")
|
|
175
|
+
continue
|
|
176
|
+
|
|
177
|
+
# 超时处理
|
|
178
|
+
if pattern:
|
|
179
|
+
logger.debug(f"等待pattern超时: {pattern}, 最终队列大小: {self.get_queue_size()}")
|
|
180
|
+
|
|
181
|
+
return output_lines if output_lines else None
|
|
182
|
+
|
|
183
|
+
def execute_command(self, command, pattern=" #", timeout=None):
|
|
184
|
+
"""
|
|
185
|
+
执行命令 - 统一的命令执行接口
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
command: 要执行的命令
|
|
189
|
+
pattern: 等待的完成标志 (默认: " #" 命令提示符)
|
|
190
|
+
timeout: 超时时间(秒)
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
命令输出结果列表,失败返回None
|
|
194
|
+
"""
|
|
195
|
+
logger.debug(f"执行命令: {command}, 队列大小: {self.get_queue_size()}")
|
|
196
|
+
|
|
197
|
+
# 清空队列中的残留数据(主要是提示符)
|
|
198
|
+
self.clear_queue()
|
|
199
|
+
|
|
200
|
+
# 发送命令
|
|
201
|
+
if not self.send(command):
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
# 等待响应
|
|
205
|
+
result = self.reap(pattern, timeout, highlight_cmd=True)
|
|
206
|
+
if not result:
|
|
207
|
+
logger.error("命令执行失败或超时")
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
return result
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class Demoboard(SerialController):
|
|
214
|
+
"""
|
|
215
|
+
抽象的演示板控制器基类
|
|
216
|
+
定义了通用的初始化和配置流程,具体的芯片配置由子类实现
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
cli_prompt = " #"
|
|
220
|
+
cli_startup_done_flag = "Processing /etc/profile... Done"
|
|
221
|
+
|
|
222
|
+
def __init__(self, serial_port, baudrate=115200, log_level="INFO", mcp_mode=False):
|
|
223
|
+
"""
|
|
224
|
+
初始化开发板控制器
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
serial_port: 串口地址 (默认: /dev/ttyUSB0)
|
|
228
|
+
baudrate: 波特率 (默认: 115200)
|
|
229
|
+
log_level: 日志级别 (默认: INFO)
|
|
230
|
+
auto_mount_nfs: 是否自动挂载NFS (默认: True)
|
|
231
|
+
auto_loadko: 是否自动加载驱动 (默认: True)
|
|
232
|
+
mcp_mode: 是否为MCP模式 (默认: False)
|
|
233
|
+
"""
|
|
234
|
+
super().__init__(serial_port, baudrate, log_level, mcp_mode)
|
|
235
|
+
|
|
236
|
+
# 连接串口
|
|
237
|
+
self.connect()
|
|
238
|
+
|
|
239
|
+
# 确保命令行状态
|
|
240
|
+
result = self.execute_command(CTRL_C, self.cli_prompt, 1)
|
|
241
|
+
if result is None:
|
|
242
|
+
self.reap(self.cli_startup_done_flag)
|
|
243
|
+
|
|
244
|
+
# 校正回显
|
|
245
|
+
print()
|
|
246
|
+
self.reap(self.cli_prompt)
|
|
247
|
+
|
|
248
|
+
def close(self):
|
|
249
|
+
"""关闭连接"""
|
|
250
|
+
self.disconnect()
|
|
251
|
+
|
|
252
|
+
def __enter__(self):
|
|
253
|
+
"""上下文管理器支持"""
|
|
254
|
+
return self
|
|
255
|
+
|
|
256
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
257
|
+
"""上下文管理器退出"""
|
|
258
|
+
self.close()
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
with Demoboard("/dev/ttyUSB0") as board:
|
|
263
|
+
board.execute_command("pwd")
|
|
264
|
+
board.execute_command("lsmod | grep nnp")
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdev
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 串口控制器工具包
|
|
5
|
+
Home-page: https://github.com/klrc/sdev
|
|
6
|
+
Author: klrc
|
|
7
|
+
Author-email: klrc <144069824@qq.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/klrc/sdev
|
|
10
|
+
Project-URL: Repository, https://github.com/klrc/sdev
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/klrc/sdev/issues
|
|
12
|
+
Keywords: serial,controller,hardware,embedded
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: System :: Hardware
|
|
25
|
+
Requires-Python: >=3.7
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pyserial>=3.5
|
|
29
|
+
Requires-Dist: loguru>=0.6.0
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-python
|
|
34
|
+
|
|
35
|
+
# SDEV
|
|
36
|
+
|
|
37
|
+
串口控制器工具包
|
|
38
|
+
|
|
39
|
+
## 安装
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install sdev
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 使用方法
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from sdev import SerialController
|
|
49
|
+
|
|
50
|
+
# 创建串口控制器实例
|
|
51
|
+
controller = SerialController(serial_port="/dev/ttyUSB0", baudrate=115200)
|
|
52
|
+
|
|
53
|
+
# 连接串口
|
|
54
|
+
if controller.connect():
|
|
55
|
+
print("连接成功")
|
|
56
|
+
|
|
57
|
+
# 执行命令
|
|
58
|
+
result = controller.execute_command("ls")
|
|
59
|
+
print(result)
|
|
60
|
+
|
|
61
|
+
# 断开连接
|
|
62
|
+
controller.disconnect()
|
|
63
|
+
else:
|
|
64
|
+
print("连接失败")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 功能特性
|
|
68
|
+
|
|
69
|
+
- 支持串口通信
|
|
70
|
+
- 命令执行和响应处理
|
|
71
|
+
- 自动ANSI转义码清理
|
|
72
|
+
- 连接状态管理
|
|
73
|
+
|
|
74
|
+
## 依赖
|
|
75
|
+
|
|
76
|
+
- Python >= 3.7
|
|
77
|
+
- pyserial >= 3.5
|
|
78
|
+
- loguru >= 0.6.0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
sdev/__init__.py
|
|
7
|
+
sdev/serial_controller.py
|
|
8
|
+
sdev.egg-info/PKG-INFO
|
|
9
|
+
sdev.egg-info/SOURCES.txt
|
|
10
|
+
sdev.egg-info/dependency_links.txt
|
|
11
|
+
sdev.egg-info/requires.txt
|
|
12
|
+
sdev.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sdev
|
sdev-0.1.0/setup.cfg
ADDED
sdev-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="sdev",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
author="klrc",
|
|
10
|
+
author_email="144069824@qq.com",
|
|
11
|
+
description="串口控制器工具包",
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/klrc/sdev",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.7",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Topic :: System :: Hardware",
|
|
29
|
+
],
|
|
30
|
+
python_requires=">=3.7",
|
|
31
|
+
install_requires=[
|
|
32
|
+
"pyserial>=3.5",
|
|
33
|
+
"loguru>=0.6.0",
|
|
34
|
+
],
|
|
35
|
+
)
|