What does PuTTY send when I press Enter key?

2019-04-06 13:24发布

问题:

I am trying desperately to get a Bluetooth dongle working with my Arduino but I can't send it a command that it needs. I can use it when I plug it into my computer via a USB to UART chip and send the command (C) from PuTTY and then press Enter.

The Bluetooth dongle's command sheet says that the command I am trying to send it C<cr> but I can't figure out how to send the proper carriage return character from the Arduino code. I have tried using the Serial.println() function as well as adding the \r character to my current Serial.write("C\r") but neither of those are working.

How can I achieve this? -- thank you.

回答1:

Interestingly, I can report the opposite on Win 7: PuTTY for me and my embedded project is sending ONLY '\r' over the COM port. Curious, read: frustraitingly unexplainable, but I simply look for either character on the other end of the serial connection.

Then, if you enable 'Implicit LF in every CR' under Terminal options it will send both '\r\n'. Default behaviour seems to be akin to a Commodore machine :D (http://en.wikipedia.org/wiki/Newline)... who knew...



回答2:

PuTTY emulates xterm which emulates vt100. To have putty send CR/LF when pressing enter, type ESC[20h in putty after connecting to the serial device. This sets VT100 LNM true.

http://vt100.net/docs/vt100-ug/chapter3.html

Line feed/new line New line ESC [20h Line feed ESC [20l



回答3:

If you watch the ascii table or similar reference you might find interesting: \r ou \x0D

For better understanding, see : http://www.grok2.com/sedfaq6.html



回答4:

On arduino program, just use Serial.write and both characters codes:

Serial.write(13);    // CR
Serial.write(10);    // LF

And Avoid Serial.print as it is intended as human readable, so formatted.

references: write print



回答5:

Sending CR+LF is possible in modified PuTTY. Source code is available at https://github.com/gniemirowski/putty-crlf and Windows binary at https://www.grzegorz.net/pliki/putty-crlf.zip When you run this version just go to Terminal -> Keyboard and select "CR LF" for "The Enter key" option.



回答6:

I'm almost sure that you are looking for the \n new line character.



回答7:

I tried this very simple code (cr = carriage return)

Serial.write(13);

And because the next "printed" caracters will feed the residual text, it's ok.



回答8:

Yesterday I was trying with this by other problem. In standard configuration (on Windows and Linux) if You type "help" and then press enter on serial port will appear followed chain of bits (checked with external connected terminal via RS232, and logic analyzer):

0x68(h) 0x65(e) 0x6c(l) 0x70(p) 0x0d(CR: Carriage Return U+000A)

so seems like PUTTY puts CR on ENTER (no matter if You are on Linux or Windows)