Non-POSIX parity (mark/space) with Python-Serial on Linux.
MRAB
python at mrabarnett.plus.com
Mon Nov 21 13:20:01 EST 2011
On 21/11/2011 16:52, Matthew Lenz wrote:
> Ahh. Ok. So how would I go about doing that with python? I think in
> perl (sorry for the naughty word) I could use the tr// (translate)
> but is there a quick way to do so with python? Is it going to be
> necessary to convert commands I SEND to the device or only convert
> what I receive?
Python strings have a .translate method:
# Example in Python 2
import string
# From top bit set...
from_chars = "".join(chr(c | 0x80) for c in range(0x7F))
# ...to top bit clear.
to_chars = "".join(chr(c) for c in range(0x7F))
# Build the translation table.
force_clear = string.maketrans(from_chars, to_chars)
s = "\x41\xC1"
print s
print s.translate(force_clear)
More information about the Python-list
mailing list