title: Using socat for raw serial connection
body: <p>The goal is to connect to an <code>embedded</code> device using <code>serial</code> interface.
  So far, I've used:</p>
  
  <pre><code>stty -F /dev/ttyS2 115200 cs8 ixoff
  socat readline,history=/etc/socat.history /dev/ttyS2,raw,echo=0
  </code></pre>
  
  <p>And it works excellent, but then I discovered that there are some options during <code>system boot</code> that require you to press a single key without pressing <code>enter</code>, and <code>readline</code> fails there. So my idea was to bind the <code>ttyS2</code> to <code>cons0</code>, but then I discovered multiple problems, such as inability to quit (<code>ctr+c</code>, <code>ctr+q</code> <code>ctr+]</code> and even <code>esc</code> doesn't work), <code>backspace</code> and <code>delete</code> do not work, letters are typed twice, etc. So after some trial and error, I came up with this:</p>
  
  <pre><code>socat /dev/cons0,raw,echo=0,crnl /dev/ttyS2,raw,echo=0,escape=0x03,crnl
  </code></pre>
  
  <ul>
  <li><code>raw</code> on both sides allows a single <code>key press</code> to trigger a <code>boot option</code></li>
  <li><code>echo=0</code> on both sides prevents <code>key press</code> doubling</li>
  <li><code>crnl</code> on both sides prevent <code>enter</code> <code>key press</code> doubling</li>
  <li><code>escape=0x03</code> allows me to <code>quit</code> the thing by pressing <code>ctr+c</code></li>
  </ul>
  
  <p>The problem is, when I quit, my <code>cons0</code> is all f****d up, as if it somehow preserved the <code>raw,echo=0,crnl</code> settings. I know this problem is probably too specific for my scenario, but I just need a simple way to send keystrokes to serial as I would with <code>putty</code> (which is not available on my platform). I am using <code>socat</code> because it is extremely lightweight, does not require any aditional libraries, and because the shown commands are a part of the greater script that uses <code>expect</code>.</p>
  
  <p>Any ideas and suggestions are greatly appreciated.</p>