{"id":3280,"date":"2021-12-25T01:02:19","date_gmt":"2021-12-25T09:02:19","guid":{"rendered":"https:\/\/wonghoi.humgar.com\/blog\/?p=3280"},"modified":"2021-12-25T01:10:00","modified_gmt":"2021-12-25T09:10:00","slug":"fing-newline-in-putty","status":"publish","type":"post","link":"https:\/\/wonghoi.humgar.com\/blog\/2021\/12\/25\/fing-newline-in-putty\/","title":{"rendered":"F#*@ing newline in Putty"},"content":{"rendered":"\n<p>I tried to use Putty to connect to my serial port test instrument (Agilent&#8217;s 33120A or E3600 series power supplies) and to my dismay it doesn&#8217;t respond to my commands. <\/p>\n\n\n\n<p>I figured it might be newlines not being recognized properly. Checked the programming manuals and found that HP\/Agilent accepts LF (&#8216;\\n&#8217;)as newline and optionally allowing a CR (&#8216;\\r&#8217;) before it (i.e. CR+LF like Windows).<\/p>\n\n\n\n<p>I thought this configuration (Implicit LF in every CR) would work:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"259\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-2.png\" alt=\"\" class=\"wp-image-3281\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-2.png 442w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-2-300x176.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/figure>\n\n\n\n<p>However it doesn&#8217;t! I had to dig through internet forums to find out that the &#8216;Terminal&#8217; settings page controls what gets SPIT OUT TO THE TERMINAL SCREEN, not how your keystrokes are treated\/sent! This page controls what your keystrokes mean:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"443\" height=\"214\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-3.png\" alt=\"\" class=\"wp-image-3282\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-3.png 443w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-3-300x145.png 300w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/figure>\n\n\n\n<p>However, it says nothing about what Putty does with ENTER key. I found from Stackflow that <a href=\"https:\/\/z49x2vmq.github.io\/2017\/11\/12\/putty-cr-lf-en\/\" target=\"_blank\" rel=\"noreferrer noopener\">Putty sends out only CR (&#8216;\\r&#8217;) when ENTER key is pressed<\/a>. <\/p>\n\n\n\n<p>Turns out with terminals, <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Ctrl+J is LF<\/li><li>Ctrl+M is CR, <\/li><\/ul>\n\n\n\n<p>and the <a href=\"https:\/\/ss64.com\/bash\/syntax-keyboard.html\">convention<\/a> for ENTER is Ctrl+M (also mentioned <a rel=\"noreferrer noopener\" href=\"https:\/\/unix.stackexchange.com\/questions\/349214\/enter-key-is-different-from-carriage-return-cr\" target=\"_blank\">here<\/a>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"292\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-5-1024x292.png\" alt=\"\" class=\"wp-image-3286\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-5-1024x292.png 1024w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-5-300x86.png 300w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-5-768x219.png 768w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-5.png 1091w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>https:\/\/ss64.com\/bash\/syntax-keyboard.html<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">So if you want ENTER\/RETURN key to generate LF (instead of CR) with the official putty, you have to press Ctrl+J each time! <\/h2>\n\n\n\n<p>Putty sending CR (Ctrl+M) with ENTER key by default is also hinted by the default Telnet (<strong>only applies to telnet<\/strong>, not serial) setting in the <a rel=\"noreferrer noopener\" href=\"https:\/\/documentation.help\/PuTTY\/config-telnetnl.html\" target=\"_blank\">Putty docs<\/a> &#8220;Return key sends Telnet New Line instead of Ctrl+M&#8221;, which means outside Telnet, it the default behavior or ENTER\/RETURN key is Ctrl+M (CR)!<\/p>\n\n\n\n<p>Ironically even HyperTerminal came with the option to send out CR+LF on ENTER key! Luckily some kind soul (Grzegorz Niemirowski) compiled a <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/gniemirowski\/putty-crlf\" target=\"_blank\">mod<\/a> (currently <a rel=\"noreferrer noopener\" href=\"https:\/\/www.grzegorz.net\/pliki\/putty-crlf.zip\" target=\"_blank\">v0.74<\/a>) which added the option and and posted it on <a rel=\"noreferrer noopener\" href=\"https:\/\/stackoverflow.com\/a\/52193322\/11422004\" target=\"_blank\">Stack overflow<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"954\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-6-1024x954.png\" alt=\"\" class=\"wp-image-3287\" srcset=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-6-1024x954.png 1024w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-6-300x279.png 300w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-6-768x715.png 768w, https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2021\/12\/image-6.png 1402w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_3280\" class=\"pvc_stats all  \" data-element-id=\"3280\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I tried to use Putty to connect to my serial port test instrument (Agilent&#8217;s 33120A or E3600 series power supplies) and to my dismay it doesn&#8217;t respond to my commands. I figured it might be newlines not being recognized properly. &hellip; <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2021\/12\/25\/fing-newline-in-putty\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_3280\" class=\"pvc_stats all  \" data-element-id=\"3280\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[67,4],"tags":[],"class_list":["post-3280","post","type-post","status-publish","format-standard","hentry","category-free-open-source","category-windows"],"_links":{"self":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/comments?post=3280"}],"version-history":[{"count":2,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3280\/revisions"}],"predecessor-version":[{"id":3290,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3280\/revisions\/3290"}],"wp:attachment":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/media?parent=3280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/categories?post=3280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/tags?post=3280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}