title: pySerial - Only reading one byte
body: <p>I am trying to read and write to a sensor via serial using pySerial. I have no software or hardware flow control. </p>
  
  <p>I am able to send a string of hex to the device, but I only receive one byte back instead of the two-to-ten bytes I should see. The sensor is working -- I've verified this using Realterm.</p>
  
  <p>I've tried using ser.readline() (instead of the inWaiting loop), and ser.read(2); this just causes the program to hang. I've also tried increasing the sleep time, and experimented with different baud rates (on both the PC and sensor), but nothing seems to work. </p>
  
  <p>Does anyone have any advice?</p>
  
  <pre><code>import time
  import serial
  
  # configure the serial connections
  ser = serial.Serial(
      port='COM1',
      baudrate=115200,
      parity=serial.PARITY_EVEN,
      stopbits=serial.STOPBITS_ONE,
      bytesize=serial.EIGHTBITS
  )
  
  ser.isOpen()
  
  print 'Enter your commands below.\r\nInsert "exit" to leave the application.'
  
  while 1 :
      # get keyboard input
      data_in = raw_input("&gt;&gt; ")
  
      if data_in == 'exit':
          ser.close()
          exit()
      else:
          # send the character to the device
          ser.write(data_in.decode('hex') + '\r\n')
  
          out = ''
          time.sleep(1)
          while ser.inWaiting() &gt; 0:
              out += ser.read(1)
  
          if out != '':
              print "&gt;&gt;" + " ".join(hex(ord(n)) for n in out)
  </code></pre>
  
  <p>(I slightly modified the code from that found on <a href="https://stackoverflow.com/questions/676172/full-examples-of-using-pyserial-package">Full examples of using pySerial package</a>)</p>