Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'detect': 0.07; 'string': 0.09; 'bits': 0.09; 'escape': 0.09; 'exit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:characters': 0.09; 'xor': 0.09; 'python': 0.11; 'def': 0.12; 'itself.': 0.14; 'iterator': 0.16; 'occurs,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:python': 0.16; 'wed,': 0.18; 'trying': 0.19; 'later': 0.20; 'appears': 0.22; 'char': 0.24; 'sends': 0.24; 'url:home': 0.24; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'character': 0.29; 'characters': 0.30; 'network.': 0.30; 'skip:= 20': 0.31; 'something': 0.35; 'but': 0.35; 'false': 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'email addr:gmail.com': 0.63; 'receive': 0.70; 'serial': 0.72; 'recover': 0.91; 'received:108': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Fixing escaped characters python-xbee Date: Wed, 24 Apr 2013 20:29:05 -0400 Organization: > Bestiaria Support Staff < References: <704e1981-1e13-4030-b4ca-a7305ec98b32@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-73-118-188.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366849755 news.xs4all.nl 15947 [2001:888:2000:d::a6]:52114 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44307 On Wed, 24 Apr 2013 00:33:30 -0700 (PDT), pabloblo85@gmail.com declaimed the following in gmane.comp.python.general: > I am using a XBee to receive data from an arduino network. > > But they have AP=2 which means escaped characters are used when a 11 or 13 appears (and some more...) > > When this occurs, XBee sends 7D and inmediatly XOR operation with char and 0x20. > > I am trying to recover the original character in python but I don't know ho to do it. > > I tried something like this: > > read = ser.read(4) #Read 4 chars from serial port Why read 4 at a time if you need to detect the escape marker... PSEUDO_CODE -- UNTESTED: for c in ser.read(): #presumes it will function as an iterator if ord(c) == 0x7D: c =chr(ord(ser.read(1)) ^ 0x20) #do something with c (save to a list for later joining as a string?) #probably need some condition to exit the read loop too > def logical_xor(str1, str2): > return bool(str1) ^ bool(str2) > bool() returns True or False based on the argument... Any non-empty string will be True. Instead what you want is to x-or the bits of the character itself. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/