Fixing escaped characters python-xbee
pabloblo85 at gmail.com
pabloblo85 at gmail.com
Fri Apr 26 04:17:05 EDT 2013
>
> 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.
>
> --
It works! Thank you so much. Now I can go ahead with my work!
More information about the Python-list
mailing list