On 06/12/2010 15:37, Astan Chee wrote:
Hi,
I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of
those old serial IR towers to control the microcontroller. I've had a
look around at python's serial documentation as well as the RCX's
documentation and I'm trying to write something to control the RCX
directly using python. Several examples from of doing this in python
include using lnp (i think) and that doesn't quite run well in windows.
I've had a look at the C++ code and some protocol documentation here:
http://www.generation5.org/content/2001/rob08.asp and converted it to
python. I've attached it at the end of the email. So now I've figured
out how to check for the battery level and it seems to work (I've tested
it on my RCX) but I'm confused with the other documentation (e.g.
http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in
python or what this all means. I was wondering if anyone can help me
complete these? or maybe help me do it step-by-step?
Thanks for any help.
[snip]
Here's a brief summary of the protocol:

A command or request to the microcontroller is a packet consisting of a header, an opcode, arguments, and a checksum.

        The header used in the documentation is 0x55, 0xFF, 0x00.

        The opcode is 1 byte, followed by its one's complement.

        The argument is 0 or more bytes, each followed by its one's complement.

The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement.

A reply from the microcontroller is also a packet consisting of a header, an opcode, arguments, and a checksum.

        The header is the same as the original command or request.

The opcode is the one's complement of the original opcode, followed by its one's complement (ie, the original opcode).

        The argument is 0 or more bytes, each followed by its one's complement.

The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement.

The microcontroller will ignore a packet whose opcode is the same as the previous one; this is to prevent unintended duplicates due to communication errors.

Each opcode has 2 alternatives, one with bit 3 clear and the other with bit 3 set (bitwise-ored with 0x08), so if you do want to send a command or request with the same opcode as the previous packet you can just use the alternative form.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to