doc文档转pdf;优化运行代码

This commit is contained in:
sityliu 2024-04-22 00:17:59 +08:00
parent 9874cd49a2
commit 590a57e6f9
7 changed files with 13 additions and 12 deletions

View File

@ -16,16 +16,16 @@ print("Hello,World!")
# 打开串口
port = "COM7"
baud = 9600
timeout = 1
try:
ser = serial.Serial(port=port, baudrate=baud, bytesize=8,parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
if ser.isOpen():
print("Port is open")
except:
print("请检查串口是否被占用;或者串口出现异常!")
exit()
def init(port, baudrate, timeout):
try:
ser = serial.Serial(port=port, baudrate=baudrate, bytesize=8,parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout)
if ser.isOpen():
print("Port is open")
except:
print("请检查串口是否被占用;或者串口出现异常!")
exit()
return ser
# crc16 算法
def crc16(data: bytes) -> int:
@ -56,7 +56,7 @@ sed_msg = sed_msg + sendbytes
print("发送帧:",sed_msg)
def run():
def run(ser):
# 读取和解析串口数据
while True:
ser.write(bytes(sed_msg))

Binary file not shown.

Binary file not shown.

3
run.py
View File

@ -2,4 +2,5 @@ from app import get_temperature
if __name__ == '__main__':
get_temperature.run()
ser = get_temperature.init("COM5", 9600, 1)
get_temperature.run(ser)