Please note that this does not allow you to run Python on the RCX.
If you don't know what Python is, look here. It should be ready-installed on most standard Linux distributions.
Here's a quick example Python script that sends a message to the brick, and prints a reply:
# Import the LNP extension. This initializes lnp import lnp # Send a message to the RCX lnp.iwrite('hello') # Read & print the response lnp.iread() 'world'
Simple, Eh?
Pylnp supports integrity & addressing read/write operations. Read calls may be blocking or non-blocking (although non-blocking reads don't work yet.)
This module interfaces to LegOS lnp, using the lnpd package from Martin Cornelius (Martin.Cornelius@t-online.de). It allows a python script to send & received data via the IR tower to an RCX running LegOS. The following functions are available: iread() Blocking LNP integrity read ireada(callable) Asynchronous LNP integrity read iwrite(buf) LNP integrity write aread(port) Blocking LNP addressing read areada(port, callable) Asynchronous LNP addressing read awrite(buf, dst, src) LNP addressing write All reads are mutually exclusive. That is, only one asynchronous or blocking integrity or addressing read may be outstanding at one time.
aread(port) Performs a blocking LNP addressing read on port 'port', returning the result as the tuple (buf, port), where buf is the buffer string read from the RCX and 'port' is the RCX source port number. The string may contain embedded nulls. Any outstanding asynchronous LNP reads (integrity or addressing) are cancelled.
aread(port) Performs a blocking LNP addressing read on port 'port', returning the result as the tuple (buf, port), where buf is the buffer string read from the RCX and 'port' is the RCX source port number. The string may contain embedded nulls. Any outstanding asynchronous LNP reads (integrity or addressing) are cancelled. >>> print lnp.areada.__doc__ areada(port, callable) Performs an asynchronous LNP addressing read. The callable object 'callable' is called with the string read from the RCX, and the RCX port number. The string may contain embedded nulls. Any outstanding asynchronous LNP integrity reads are cancelled.
awrite(buf, dst, src) Performs LNP addressing write, sending the buffer buf to the RCX. The string may contain embedded nulls. dst & src are the lnp destination & source ports.
iread() Performs a blocking LNP integrity read, returning the result as a string. The string may contain embedded nulls. Any outstanding asynchronous LNP reads (integrity or addressing) are cancelled.
ireada(callable) Performs an asynchronous LNP integrity read. The callable object 'callable' is called with the string read from the RCX. The string may contain embedded nulls. Any outstanding asynchronous LNP addressing reads are cancelled.
iwrite(buf) Performs LNP integrity write, sending the buffer buf to the RCX. The string may contain embedded nulls.
Pylnp allows you to embed nulls in the data, so you can send binary as well as ordinary strings. Use the python struct module to handle binaries.
Multi-threaded applications must ensure that any lnp.read calls are made in the main thread. This is because python only delivers signals to the main thread.
It ought to be possible for a LegOS RCX program to send some python script to pylnp for interpretation. This might be usefull for pretty-printing data structures etc.
I've used pylnp as part of a gdb/legOS interface (see here for more info.). It sends messages between gdb connected via a socket & a debug stub running under legOS.