PySerial: How to send Ctrl-C command on the serial line
I'm automating a configuration process for an embedded board. To enter the setup screen I need to send "Ctrl-C" command.
This is NOT to interrupt a process I'm running locally, KeyboardInterrupt开发者_运维问答 will not work. I need to send a value that will be interpreted by the bootloader as Ctrl-C.
What is the value I need to send?
Thank you
IIRC, Ctrl-C is etx
. Thus send \x03
.
You should send a character with the ASCII code 3:
serial.write('\x03')
\x03
Which means 'end of text' or 'break' is what Ctrl+C sends.
Python doesn't take the ASCII code as a string, it needs to be encoded as bytes. So just add b before the code.
serial.write(b'\x03')
I've used here and saved and saved my life a couple times.
精彩评论