diff --git a/.gitignore b/.gitignore index f241b1b..7f81d6c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ *.obj *.crf /History/ -/Output/ \ No newline at end of file +/Output/ +.idea/ +__pycache__/ \ No newline at end of file diff --git a/Hardware/UPbot-Tools/imgs/STM_32F103C8T6.jpg b/Hardware/UPbot-Tools/imgs/STM_32F103C8T6.jpg new file mode 100644 index 0000000..34aabba Binary files /dev/null and b/Hardware/UPbot-Tools/imgs/STM_32F103C8T6.jpg differ diff --git a/Hardware/UPbot-Tools/imgs/image.png b/Hardware/UPbot-Tools/imgs/image.png new file mode 100644 index 0000000..677d7a7 Binary files /dev/null and b/Hardware/UPbot-Tools/imgs/image.png differ diff --git a/Hardware/UPbot-Tools/imgs/接线.jpg b/Hardware/UPbot-Tools/imgs/接线.jpg new file mode 100644 index 0000000..eeaaf44 Binary files /dev/null and b/Hardware/UPbot-Tools/imgs/接线.jpg differ diff --git a/Hardware/UPbot-Tools/test.py b/Hardware/UPbot-Tools/test.py new file mode 100644 index 0000000..977a5b0 --- /dev/null +++ b/Hardware/UPbot-Tools/test.py @@ -0,0 +1,188 @@ +# 调试小车,ubuntu版本代码 +# 可以按格式发送、接受数据 + +import serial +import time +import struct +import keyboard +import sys +import termios +import tty + + +class SerialPort: + def __init__(self, port, baudrate=9600, timeout=1): + self.port = port + self.baudrate = baudrate + self.timeout = timeout + self.serial = None + + def open(self): + try: + self.serial = serial.Serial(self.port, self.baudrate, timeout=self.timeout) + print(f"成功打开串口: {self.port}") + except serial.SerialException as e: + print(f"打开串口失败: {e}") + self.serial = None + + def close(self): + if self.serial and self.serial.is_open: + self.serial.close() + print("串口已关闭") + + def write(self, data): + if self.serial and self.serial.is_open: + if isinstance(data, str): + data = data.encode() + self.serial.write(data) + + def write_hex(self, data): + if self.serial and self.serial.is_open: + self.serial.write(data) + + def read(self, size=22): + if self.serial and self.serial.is_open: + data = self.serial.read(size) + hex_data = ', '.join(f'0x{byte:02X}' for byte in data) + print(f"接收数据: {hex_data}") + return data + return None + + +def parse_serial_feedback(data): + struct_format = '