工具/软件:
测试环境: mcu_plus_sdk_am261x_10_02_00_15 中的 LP AM261X + cc_echo_am261x-lp_r5fss0-0_nortos_ti-arm-clang 。
在将.out 文件下载到 LP AM261X 板并运行程序后、我使用 bat 文件循环执行 Python 脚本 200 次。 但是、当它运行到 100 次以上时、无法再找到 USB 设备。
USB_test.py 为:
import serial
import serial.tools.list_ports
# List all serial port devices
ports = serial.tools.list_ports.comports()
usb_port = None
# Enumerate all serial port devices
for port in sorted(ports):
if "USB" in port.description:
print(f"Found USB device on port: {port.device}")
usb_port = port.device
break # Exit the loop after finding the first USB device
# Exit directly if no USB device is found
if usb_port is None:
print("Error: No USB device found. Exiting...")
exit()
baudrate = 19200 # Baud rate, modify according to actual requirements
timeout = 2 # Timeout period (seconds)
# Define the data to be sent
data_to_send = [0xF8, 0x03, 0x01, 0x02, 0x00, 0x02, 0x70, 0x5E]
data_to_send_hex = ' '.join(f'{byte:02X}' for byte in data_to_send)
print(f"USB Sent data: {data_to_send_hex}")
try:
# Open the serial port
ser = serial.Serial(usb_port, baudrate, timeout=timeout)
# Send data
ser.write(data_to_send)
# Read the received data
received_data = ser.read(20)
# Close the serial port
ser.close()
# Print the received data
received_data_hex = ' '.join(f'{byte:02X}' for byte in received_data)
print(f"USB Received data: {received_data_hex}")
except serial.SerialException as e:
print(f"Serial communication error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
bat 文件为:μ s
@echo off set /a count=0 :loop set /a count+=1 echo The test times: %count% python USB_test.py timeout /t 2 /nobreak >nul if %count% lss 200 goto loop
测试结果:

我试过,但它不起作用。 您是否通过了测试? 如果您通过了测试、就可以向我发送.out 文件、我将对其进行测试。 

