Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Gonzalo V Newsgroups: comp.lang.python Subject: Re: How to read from serial port? Date: Tue, 26 Apr 2016 21:21:00 -0400 Lines: 56 Message-ID: References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de Pw3tcEQ5d/PCO3cdeOvIXAx9fvgpU0znyhg8uLUKTZlw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; "'python": 0.07; 'cc:addr :python-list': 0.09; 'subject:How': 0.09; 'at\xc2\xa0': 0.09; 'typeerror:': 0.09; 'received:74.125.82.44': 0.15; 'encoding': 0.15; '2016': 0.16; 'cc:name:python list': 0.16; 'decode': 0.16; 'escribi\xc3\xb3:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:port': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'bytes': 0.18; 'string,': 0.18; '>': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saludos,': 0.22; 'this:': 0.23; "haven't": 0.24; 'import': 0.24; '(most': 0.24; 'url:view': 0.24; 'header:In-Reply-To:1': 0.24; 'skip:# 10': 0.27; 'message- id:@mail.gmail.com': 0.27; 'specify': 0.27; 'implicitly': 0.29; 'str': 0.29; 'convert': 0.29; 'url:mailman': 0.30; 'desde': 0.30; 'skip:s 30': 0.31; "can't": 0.32; 'run': 0.33; 'url:python': 0.33; 'sexual': 0.33; 'traceback': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; '(and': 0.36; 'url:library': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'skip:p 20': 0.38; 'skip:o 20': 0.38; 'google': 0.39; 'data': 0.39; 'subject:from': 0.39; 'url:mail': 0.40; 'url:3': 0.60; 'six': 0.65; 'day': 0.67; 'serial': 0.70; '26,': 0.72; 'subject:read': 0.84; 'edwards': 0.91; 'married': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=BaijrJkenF/FZtdug6uTsz5UG9RoN5gaiGGFls6B6d4=; b=i6mc44iC1nMICJ6zTQETLlU26iqvKyOT3fJ5P7pNQrKwuTpA4AXjOAQKuC2gcBp+gj unAs7yvysnr+HbDDvHhfNUp/jyPWxp7WkGRo66CkGE1giNR1bfXSvxmNZd4G9nIokRW5 FIH1WdSrlOSj9xwyGOtXU1XmxkbQmk0liI85N+WMv0NhlBvEeAxc68Qk7QmiS2G4kpry I/RWwCf4cIBx46D0XyYCsVNh+O2kuN1h7gjeJ7YBDYqbu8wI3WKlc+r7fSNFED/xNGFe FB5fV7ZPDWSg1MkZycFrxpBZcRwUQnaum1m9cVqcXON0KMYvqPsFy4R+4KeXCbiPXJ6n sE/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=BaijrJkenF/FZtdug6uTsz5UG9RoN5gaiGGFls6B6d4=; b=cnRtYlOVZBdlCyE5pjB/U+zD3FAP2VZWhsBnhvcjRXB6MMl1WtQlzF0W+WBPtUDeBv 5d0xqF4TxcvtoTu/thkIafso9L/BgrzAworOwvTPSZXs8mdKgwgLN0k74+xejSFvNdQj CkrKiRLIFRQ9gbpctNqmhDhy4rX+29RS7WjzmaNkLeGApadZvTS3LB3e/gM8rnGjVtMT HtLep4P/8i0FUSVlAmN8+b0UoAK+tjKEuwtpCh88Tz5/CkvYhFb+c0J4ZZKi+oUzkRDg 4uYBHA3cn1CtfPqNZeJGWRK+8k5QVmgDzFoP1gJwC3Vx1NvE9w3qVcSdR3auiLFt8d0x MsGg== X-Gm-Message-State: AOPr4FXrhpyqvJMln5MGXvHzAlZwJzTzyhPo9d+iPKO0tuD87hM5KF4/KMQJW1cl5XrjkmwOK9po2ko2hjRNww== X-Received: by 10.28.111.14 with SMTP id k14mr3751506wmc.32.1461720060555; Tue, 26 Apr 2016 18:21:00 -0700 (PDT) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <41302A7145AC054FA7A96CFD03835A0A0BAC66F9@EX10MBX02.EU.NEC.COM> Xref: csiph.com comp.lang.python:107697 Try print('blaba'+str(out)) saludos, desde un m=C3=B3vil. El abr 26, 2016 2:33 p.m., "Grant Edwards" escribi=C3=B3: > On 2016-04-26, David Aldrich wrote: > > > #!/usr/bin/python3 > > import serial > > > > ser=3Dserial.Serial('COM1',115200) > > while True: > > out =3D 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 > > 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/978149194623= 7/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 >