title: Problem sending Bytes with pySerial and socat
body: <p>I want to send some bytes via pySerial.  I created virtual serial ports with socat for testing purposes: </p>
  
  <pre><code>socat PTY,link=./ptyp1,b9600 PTY,link=./ptyp2,b9600
  </code></pre>
  
  <p>Here's the python code: </p>
  
  <pre><code>ser = serial.Serial('./ptyp1')
  x = struct.pack('B',2)
  print binascii.hexlify(x) # 02
  ser.write(x)
  y = ser.read(2)
  print binascii.hexlify(y) # 5e42
  </code></pre>
  
  <p>The ouput I get:</p>
  
  <pre><code>02   # x
  5e42 # y
  </code></pre>
  
  <p>The output I expect:</p>
  
  <pre><code>02 # x
  02 # y
  </code></pre>
  
  <p>What am I doing wrong here? Is it socat or python?</p>
  
  <p>Edit:</p>
  
  <p>I just noticed some other strange behavior for different x values. Here the ouput:</p>
  
  <pre><code>x = 12  =&gt; y = 5E 52 0D 0A 5E 50
  x = 100 =&gt; y = 100 # why does it work here?
  </code></pre>
  
  <p>Solution:</p>
  
  <p>The problem was that I read on the same port I wrote to. If I get it right socat "connects" the two ports as "in" and "out". So I have to read on ./ptyp2 if I write to ./ptyp1. After that, everything is fine.</p>