#37 Simple example would be nice


Hi, i have tried getting pySerial to work on both Windows XP (32-bit) and Ubuntu.

When i run the miniterm.py example everything works fine, i can both read and write to my USB serial connected device.

But when i try to write my own script it doesn't work, all the examples use threading and all sorts of neat tricks, but i think the beginner really need some much simpler examples.

When i try the following example, readline() times out.

import serial

port = serial.Serial ( 'COM8', baudrate = 57600, parity = 'N', stopbits = 1, bytesize = 8, rtscts = False, xonxoff = False, timeout = 10 )
print port.isOpen()
print port.write ( 'PROTOCOL\r\n' )
print port.readline()

But when i write PROTOCOL<newline> into the miniterm.py example it works great, leaving me to wonder whether threading is required for it to work (i have tried that too and it didn't work).

So i have two problems, really, better examples. And why doesn't the code above work?

Thanks for any insight you can give


  • Rasmus Toftdahl Olesen

    Please disregard the problem about the code not working, i think the bug is related to the device instead. Hyper Terminal works with the device, but other programs does not - looks like i timing issue inside the target.

    But i would still like some easier examples.

  • Chris Liechti

    Chris Liechti - 2011-03-19

    No, threading is not required. The example you give is perfectly fine.

    In such situations, where miniterm works but the script not, it is often a timing issue. When the port is opened, the RTS and DTR lines are switched. In this case, i suspect that the device you're trying to communicate with resets or otherwise does some processing. So it is not ready when you write to the port. Try a time.sleep(1) (or larger) after opening the port but before writing to it.

  • Chris Liechti

    Chris Liechti - 2011-03-19
    • status: open --> pending
  • SourceForge Robot

    • status: pending --> closed
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).


Log in to post a comment.