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


Groups > comp.lang.python > #44307

Re: Fixing escaped characters python-xbee

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Fixing escaped characters python-xbee
Date 2013-04-24 20:29 -0400
Organization > Bestiaria Support Staff <
References <704e1981-1e13-4030-b4ca-a7305ec98b32@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1043.1366849755.3114.python-list@python.org> (permalink)

Show all headers | View raw


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/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Fixing escaped characters python-xbee pabloblo85@gmail.com - 2013-04-24 00:33 -0700
  Re: Fixing escaped characters python-xbee MRAB <python@mrabarnett.plus.com> - 2013-04-24 11:53 +0100
  Re: Fixing escaped characters python-xbee Peter Otten <__peter__@web.de> - 2013-04-24 13:49 +0200
  Re: Fixing escaped characters python-xbee Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-24 20:29 -0400
    Re: Fixing escaped characters python-xbee pabloblo85@gmail.com - 2013-04-26 01:17 -0700

csiph-web