NQC stands for Not Quite C, and is a simple language for programming
the LEGO RCX. The preprocessor and control structures of NQC are
very similar to C. NQC is not a general purpose language -- there are many
restrictions that stem from limitations of the standard RCX firmware.
This man page does not attempt to describe the NQC programming language or
the RCX API, merely the options of the nqc command-line program. References
to more complete documentation are given at the end of this man page.
nqc is normally used to process a single source file given as
filename. You can also read from stdin by using -
instead. If the filename ends in .rcx, it is assumed to be a RCX image
file from a previous compile, and will be used as is (for downloading or
listing).
Options
-1
use NQC 1.x compatibility mode. The RCX API changed significantly with
version 2.0. This flag makes the compiler grok old code.
-Ttargetgenerate code and use communications methods for "smart
bricks" other than the RCX. Currently, can be either CM or
Scout.
-d
download program to the RCX. When this option is given, code is sent
directly over the serial port to the brick and no output file is generated
by default.
-n
prevent the standard nqc.h file from being automatically included.
-Dsym[=value]
define macro sym as value.
-E[filename]
write compiler errors to filename (or to stdout, if no name specified)
instead of to stderr.
-Ipath
search path for include files. Multiple directories should be
separated as normal for the platform (under Linux / Unix, that'd be "").
Can also be set with the NQC_INCLUDE environment variable.
-L[filename]
generate a human-readable bytecode listing to filename (or to stdout)
instead of generating a binary file.
-Ooutfile
output code to outfile. This option causes a file to be written even
if -d or -L is also given. If no filename is specified, the
output file will have the same basename as the input file but an
extension of .rcx instead of .nqc.
-Sportname
use serial port portname. Under Linux, /dev/rcx is the
default. (This will differ on other platforms.) The port can also be specified
via the RCX_PORT environment variable, but the command line option takes
precedence.
-Usym
undefine macro sym.
ACTIONS
Actions look similar to options, but they have some subtle differences. In
general, options set up things (such as a serial port) for later use, while
actions cause something to happen. Actions are executed in the order that
they appear on the command line. In addition, actions appearing before the
source file happen before compilation, while actions after the source file
happen after compilation. For historical reasons, downloading the compiled
file (-d) works as an option and not an action.
-run
run the current program. This causes the program selected on the RCX to
execute.
-pgmnumber
select program number. This changes the program slot on the RCX.
-datalog
get the datalog from the RCX and print it to stdout.
-datalog-full
same as -datalog but with more verbose output.
-near
set the IR port to short-range mode.
-far
set the IR port to long-range mode.
-watchtime
set the RCX's clock to the specified time. If you use now, then the host's
current time is used.
-firmwarefilename
downloads the firmware to the RCX. You'll need the official Lego RCX
firmware from the CD-ROM -- the current (and so far only) file is called
firm0309.lgo. This will probably be necessary the first time you use
your RCX, and whenever it's been without batteries for more than a few
minutes.
-firmfastfilename
same as -firmware, but at quad speed. Requires the tower to be in
near mode (see -near). If you have trouble getting the fast
download to work, please revert to the older (and slower) method.
-sleeptimeout
set RCX auto-shutoff timeout, in minutes.
-msgnumber
send IR message to RCX. The brick will respond to this just as it would a
communication from another RCX.
-rawdata
send an arbitrary packet to the RCX and print the reply (if any) to stdout.
The data should be a hexadecimal string, with no spaces, zero-padded so that
it is an even number of characters (although it may be an odd number of
bytes). For example, to read the contents of variable 1, you could use
-raw 120001. The bytecodes for raw messages can be found on web sites
that document the RCX protocol.
-remotevaluerepeat
send a repeating remote command to the RCX.
-clear
erase all programs and datalog from the RCX.
Environment
RCX_PORT
sets the default serial port. See the -S option.
NQC_OPTIONS
specifies extra options to be inserted into the command line. For example,
setting NQC_OPTIONS to -TScout would cause nqc to target the Scout
by default.
NQC_INCLUDE
specifies additional paths to search for include files. See also the
-I option.
Examples
To compile foo.nqc, download the bytecode to program slot three, and
make the RCX start executing it immediately:
To just compile bar.nqc, resulting in bar.rcx:
To download bar.rcx to the RCX:
To set the IR tower to short-range mode and download the firmware at high
speed:
To compile /usr/share/doc/nqc/examples/test.nqc and print the resulting
bytecode listing to the screen in human-readable format:
(This should result in the following output under nqc 2.1.0:
)
Files
Older versions of nqc required a separate rcx.nqh or rcx2.nqh
file. This is now integrated into the binary and no longer necessary,
but for reference, rcx2.nqh is included with the package.
(If you installed the RPM, try /usr/share/doc/nqc-2.1.0/rcx2.nqh).
Releases
13 releases since Debian 2.2 (Potato); the text changed 5 times.
-firmware since Debian 5.0 (Lenny);
-msg since Debian 5.0 (Lenny);
-sleep since Debian 5.0 (Lenny).
-1 until Debian 4.0 (Etch);
-D until Debian 4.0 (Etch);
-Dsym until Debian 2.2 (Potato);
-E until Debian 4.0 (Etch);
-I until Debian 4.0 (Etch);
-Idir until Debian 2.2 (Potato);
-L until Debian 4.0 (Etch);
-Lfile until Debian 2.2 (Potato);
-O until Debian 4.0 (Etch);
-Ooutfile until Debian 2.2 (Potato);
-S until Debian 4.0 (Etch);
-Sport until Debian 2.2 (Potato);
-T until Debian 4.0 (Etch);
-U until Debian 4.0 (Etch);
-Usym until Debian 2.2 (Potato);
-c until Debian 2.2 (Potato);
-clear until Debian 2.2 (Potato);
-d until Debian 4.0 (Etch);
-datalog until Debian 2.2 (Potato);
-datalog_full until Debian 2.2 (Potato);
-far until Debian 2.2 (Potato);
-l until Debian 2.2 (Potato);
-n until Debian 4.0 (Etch);
-near until Debian 2.2 (Potato);
-pgm until Debian 2.2 (Potato);
-raw until Debian 2.2 (Potato);
-run until Debian 2.2 (Potato);
-t until Debian 2.2 (Potato);
-v until Debian 2.2 (Potato).