大屏分屏控制软件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

"""
core/mock_handler.py
模拟串口处理器 (开发调试用)
"""
import time
import logging
class MockSerialHandler:
def __init__(self):
self.is_open = False
self.logger = logging.getLogger("MockHandler")
def open(self):
self.is_open = True
self.logger.info("【模拟】串口已连接 (虚拟硬件就绪)")
def close(self):
self.is_open = False
self.logger.info("【模拟】串口已断开")
def send_command(self, byte_data):
if not self.is_open:
self.logger.error("【模拟】错误:串口未打开,无法发送")
return False
# 模拟发送耗时
time.sleep(0.01)
# 把字节数据转成可读的 Hex 字符串
hex_str = byte_data.hex().upper()
self.logger.info(f"【模拟发送】 -> {hex_str}")
# 这里可以模拟硬件的返回数据 (如果需要解析返回值)
# self.simulate_hardware_response(byte_data)
return True
def simulate_hardware_response(self, cmd):
"""可选:根据发送的指令模拟返回值"""
pass