gpt4 book ai didi

pyserial gets no response from the bootloader in embedded device(嵌入式设备中的引导加载程序没有响应Py Serial)

转载 作者:bug小助手 更新时间:2023-10-25 17:06:24 27 4
gpt4 key购买 nike



I have an embedded device configured to boot in to the bootloader which expects to communicate with the user on the USART1 after reboot.

我有一个嵌入式设备配置为引导到引导程序,它希望在重新引导后在USART1上与用户通信。


This works if I open a serial terminal application (cutecom) and connect to the device /dev/ttyUSB0 using:

如果我打开一个串行终端应用程序(Cutecom)并使用以下命令连接到设备/dev/ttyUSB0,则可以使用此命令:



  • 115200 baud rate,

  • 8 data bits,

  • even parity

  • 1 stop bit


After connecting I reboot the device, send 0x7f to the bootloader and bootloader acknowledges with 0x79. Here is how it looks:

连接后,我重新启动设备,将0x7f发送到引导加载程序,引导加载程序以0x79确认。下面是它看起来的样子:


enter image description here


This works flawlessly.

这一点运作得天衣无缝。




Now, I want to automate this with the following python script which was supposed to automatically connect to the device, write 0x7f and then continue to read in order to receive the expected acknowledge 0x79 from the bootloader. But, acknowledge never comes...

现在,我想使用以下Python脚本自动执行此操作,该脚本应该自动连接到设备,写入0x7f,然后继续读取,以便从引导加载程序接收预期的确认0x79。但是,承认永远不会到来..。


import serial.tools.list_ports
import serial
s = serial.Serial(
port="/dev/ttyUSB0",
baudrate=115200,
bytesize=8,
parity=serial.PARITY_EVEN,
stopbits=1,
timeout=120
)

s.write(bytes([0x7f]))

while True:
readData = s.read()
print(readData)

What am I missing. Isn't this simple enough... I was thinking that bootloader responds too fast. Is this possible? How can I solve this?

我错过了什么。这还不够简单吗..。我在想引导加载程序反应太快了。这个是可能的吗?我怎么才能解决这个问题?


更多回答
优秀答案推荐

As I suspected, embedded device was too fast and python wasn't able to catch the initial acknowledge. It helps to start two processes and after we start reading we send a command 0x7f.

正如我所怀疑的那样,嵌入式设备太快了,而Python无法捕捉到最初的确认。它有助于启动两个进程,并且在我们开始阅读之后,我们发送命令0x7f。


import serial
import multiprocessing

s = serial.Serial(
port=r"/dev/ttyUSB0",
baudrate=115200,
bytesize=8,
parity=serial.PARITY_EVEN,
stopbits=1,
timeout=120
)

def readSerial(serialConn):
while True:
readData = serialConn.read()
readDataHex = ""
if readData:
for byte in readData:
readDataHex = readDataHex + ' ' + hex(byte)
print(f"RX:{readDataHex}")

def writeSerial(serialConn):
serialConn.write(bytes([0x7F]))
print("TX: 0x7F")

readProcess = multiprocessing.Process(target=readSerial, args=(s,))
sendProcess = multiprocessing.Process(target=writeSerial, args=(s,))

readProcess.start()
sendProcess.start()

# Wait for the reading process to finish (send process will exit after sending)
readProcess.join()

更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com