Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107697
| From | Gonzalo V <gvm2121@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to read from serial port? |
| Date | 2016-04-26 21:21 -0400 |
| Message-ID | <mailman.135.1461720062.32212.python-list@python.org> (permalink) |
| References | <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> <nfoc30$cr8$1@ger.gmane.org> <CAF40P_3rE3QCQm6dLACd=14W5e+UB5rjBArO=q1BNq8MzEtV9g@mail.gmail.com> |
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
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to read from serial port? Gonzalo V <gvm2121@gmail.com> - 2016-04-26 21:21 -0400
csiph-web