Python/Pyserial: reading incoming information from port
<p>I've just started using pyserial as I will eventually need to read/save information coming from a particular port. Using the following code I am merely printing the port used and then trying to write and then read in some text ("hello"). The port is printing fine, but the output of my string is coming out as 5. Any idea why this is?</p>

<pre><code>import serial
import sys
from time import sleep

try:
  ser = serial.Serial('\\.\COM8', 9600,timeout=None, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)

except:
    sys.exit("Error connecting device")

print ser.portstr

x = ser.write("hello")
print x

ser.close()  
</code></pre>

<p>Output:</p>

<pre><code>&gt;&gt;&gt; 
\.\COM8
5
&gt;&gt;&gt; 
</code></pre>

<p>Also, is there a simple way for me to mimic a stream of text information coming through the port so that I can test reading in/saving the incoming info?</p>

<p>I am using Python 2.7, and 'virtual serial port driver 8.0' [Eltima VSPD] to emulate a port for testing this stuff.</p>

<p>Thanks,
Steve</p>