is there a problem on this simple code

Bengt Richter bokr at oz.net
Sat Mar 12 22:33:57 EST 2005


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



More information about the Python-list mailing list