PySerial: How to send Ctrl-C command on the serial line
Asked Answered
A

4

19

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

Assembler answered 10/8, 2011 at 21:34 Comment(0)
G
28

IIRC, Ctrl-C is etx. Thus send \x03.

Goda answered 10/8, 2011 at 21:39 Comment(1)
See also, the wikipedia pages on ASCII and ETX.Boyd
D
10

You should send a character with the ASCII code 3:

serial.write('\x03')
Dropwort answered 10/8, 2011 at 21:40 Comment(0)
U
5
\x03

Which means 'end of text' or 'break' is what Ctrl+C sends.

Urnfield answered 10/8, 2011 at 21:39 Comment(1)
any idea how to use it in a python3 script?Kalmick
S
4

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.

Slipover answered 29/10, 2021 at 2:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.