is there a problem on this simple code

John Machin sjmachin at lexicon.net
Sat Mar 12 23:12:19 EST 2005


Bengt Richter wrote:
> On 12 Mar 2005 17:35:50 -0800, "John Machin" <sjmachin at lexicon.net>
wrote:
>
> >
> >mensanator at aol.com wrote:
> >>
> >> What actually gets transmitted is "C\x01\x02\x10'\x83".
> >
> >No, that's repr(What actually gets transmitted)
>
> If so, that's 6 bytes, not 18:
>
>  >>> "C\x01\x02\x10'\x83"
>  "C\x01\x02\x10'\x83"
>  >>> list("C\x01\x02\x10'\x83")
>  ['C', '\x01', '\x02', '\x10', "'", '\x83']
>  >>> len("C\x01\x02\x10'\x83")
>  6
>
> OTOH,
>  >>> list(r"C\x01\x02\x10'\x83")
>  ['C', '\\', 'x', '0', '1', '\\', 'x', '0', '2', '\\', 'x', '1', '0',
"'", '\\', 'x', '8', '3']
>  >>> len(r"C\x01\x02\x10'\x83")
>  18
>
> >
> >> That's 18 bytes. Is the command supposed to be the ASCII
> >> characters \x01 or a single byte whose value is 1?
> >
> >For a start, according to the OP's code, the command ('C' a.k.a. 67)
is
> >first. The 1 is a meant to be a message number.
> >
> >Secondly, the hardware smells like it's got an 8080 or 6502 inside.
The
> >likelihood that it groks Python/C string representation is minimal.
> >Folk just don't send 18 bytes at 9600 bps when 6 bytes will do.
> >
>
> Regards,
> Bengt Richter

The number of bytes transmitted is 6. However the length of the visual
representation of what was sent is 18. Mensator was confused by this,
as was apparent from his/her question "Is the command supposed to be
the ASCII characters \x01 or a single byte whose value is 1?". I tried
to explain this to him/her. However it's not apparent whether your post
is part of the problem or part of the solution. Enlightenment, please.




More information about the Python-list mailing list