Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107697 > unrolled thread

Re: How to read from serial port?

Started byGonzalo V <gvm2121@gmail.com>
First post2016-04-26 21:21 -0400
Last post2016-04-26 21:21 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to read from serial port? Gonzalo V <gvm2121@gmail.com> - 2016-04-26 21:21 -0400

#107697 — Re: How to read from serial port?

FromGonzalo V <gvm2121@gmail.com>
Date2016-04-26 21:21 -0400
SubjectRe: How to read from serial port?
Message-ID<mailman.135.1461720062.32212.python-list@python.org>
Try print('blaba'+str(out))

saludos,
desde un móvil.
El abr 26, 2016 2:33 p.m., "Grant Edwards" <grant.b.edwards@gmail.com>
escribió:

> On 2016-04-26, David Aldrich <David.Aldrich@EMEA.NEC.COM> wrote:
>
> > #!/usr/bin/python3
> > import serial
> >
> > ser=serial.Serial('COM1',115200)
> > while True:
> >     out = ser.read()
> >     print('Receiving...'+out)
> >
> > When I run it and send data for it to read I get:
>
> > Traceback (most recent call last):
> >   File "serial_read.py", line 9, in <module>
> >     print('Receiving...'+out)
> > TypeError: Can't convert 'bytes' object to str implicitly
>
> Try this:
>
>   print('Receiving...',out)
>
> If you want to convert the bytes you read from the serial port into a
> string, you need to decode they bytes (and you have to specify what
> encoding to use):
>
>   print('Receiving...' + out.decode('ascii'))
>
> If you google 'Python 3 bytes strings' you should find a bunch of info:
>
> https://docs.python.org/3.5/library/stdtypes.html
> http://www.diveintopython3.net/strings.html
> http://pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/
>
> https://www.safaribooksonline.com/library/view/fluent-python/9781491946237/ch04.html
>
> --
> Grant Edwards               grant.b.edwards        Yow! I haven't been
> married
>                                   at               in over six years, but
> we
>                               gmail.com            had sexual counseling
> every
>                                                    day from Oral Roberts!!
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web