[Tutor] Python Serial Communication

Steven D'Aprano steve at pearwood.info
Mon Sep 29 15:15:54 CEST 2014


On Mon, Sep 29, 2014 at 12:58:09PM +0100, Alan Gauld wrote:
[...]
> How do you know that val is not a blank line?
> Remember that a blank line is not necessarily empty, it might be full of 
> unprintable characters.
> 
> Try this instead:
> 
> while True:
>      print "try"
>      val = ser.read(10)
>      print 'len: ', len(val)
>      for char in val:
>         print ord(char)

Another way to see invisible control characters is:

    print repr(val)



-- 
Steven


More information about the Tutor mailing list