title: How do I decode bytes using pyserial in serial communication
body: <p>I am a beginner to Python. I have a program that uses pyserial library to communicate with a serial device. The program sends a byte of numbers to the machine and receive number of bytes as reply. </p>
  
  <p>My code is  </p>
  
  <pre><code>   import serial, string
     port = serial.Serial("COM9", 38400, timeout=10.0)
     serial.PARITY_NONE
     serial.EIGHTBITS
     serial.STOPBITS_ONE
     port.write(bytes([53, 1, 4, 0, 83]))
     print("Write done")
     data = port.read(20)
  
     data1= data.decode('utf-8')
     print(data1)
  </code></pre>
  
  <p>The ouput is</p>
  
  <pre><code>   Write done
     Traceback (most recent call last):
     File "C:\Python34\serialcomm.py", line 18, in &lt;module&gt;
     data1= data.decode('utf-8')
     UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 8:                                                                                                               
     invalid start byte
  </code></pre>
  
  <p>The output is supposed to be 
  [53,1,4,0,83,53,1,63,83]</p>
  
  <p>If I exclude the decoding, I get</p>
  
  <pre><code>  Write done
    b'5\x01\x04\x00S5\x1b\x00\x84S'
  </code></pre>