[add] 增加了“开”和“关”命令

This commit is contained in:
JingweiCui 2025-03-20 10:24:52 +08:00
parent f85aea97ec
commit 1b7e0e7e31
3 changed files with 71 additions and 1 deletions

View File

@ -197,6 +197,13 @@ class SerialDataLogger(QObject):
f.write(data) f.write(data)
except Exception as e: except Exception as e:
print(f"保存数据出错: {e}") print(f"保存数据出错: {e}")
def send_cmd(self, cmd):
"""发送命令"""
try:
self.ser.write(cmd)
except Exception as e:
print(f"发送命令出错: {e}")
def test_connection(self): def test_connection(self):
"""测试串口连接 """测试串口连接

27
main.py
View File

@ -9,10 +9,15 @@ from data_collector import SerialDataLogger
import os import os
CMD_ON = b'\x01\x00\x01\x02'
CMD_OFF = b'\x01\x00\x00\x01'
class SerialUI(QMainWindow): class SerialUI(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.setWindowTitle("Signal Collector V1.0.5") self.setWindowTitle("Signal Collector V1.0.6 BUILD202503041320")
self.resize(400, 300) self.resize(400, 300)
# 设置应用样式 # 设置应用样式
@ -125,6 +130,19 @@ class SerialUI(QMainWindow):
baud_layout.addWidget(self.connect_btn) baud_layout.addWidget(self.connect_btn)
layout.addLayout(baud_layout) layout.addLayout(baud_layout)
# 开关按钮区域
cmd_layout = QHBoxLayout()
cmd_label = QLabel("开关命令:")
self.cmd_btn_on = QPushButton("ON")
self.cmd_btn_on.clicked.connect(self.on_cmd_btn_on)
self.cmd_btn_off = QPushButton("OFF")
self.cmd_btn_off.clicked.connect(self.on_cmd_btn_off)
cmd_layout.addWidget(baud_label)
cmd_layout.addWidget(self.cmd_btn_on)
cmd_layout.addWidget(self.cmd_btn_off)
layout.addLayout(cmd_layout)
# 录制控制区域 # 录制控制区域
record_layout = QHBoxLayout() record_layout = QHBoxLayout()
self.record_btn = QPushButton("开始录制") self.record_btn = QPushButton("开始录制")
@ -204,6 +222,13 @@ class SerialUI(QMainWindow):
# 添加退出时的确认标志 # 添加退出时的确认标志
self.exit_confirmed = False self.exit_confirmed = False
def on_cmd_btn_on(self):
self.serial_logger.send_cmd(CMD_ON)
def on_cmd_btn_off(self):
self.serial_logger.send_cmd(CMD_OFF)
def update_count_display(self): def update_count_display(self):
"""更新数据计数显示""" """更新数据计数显示"""
if self.serial_logger: if self.serial_logger:

View File

@ -0,0 +1,38 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='signal collector 1.0.6',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)