Page 247 - The Unofficial Guide to Lego Mindstorms Robots
P. 247

236


          Download prints a period for each line of the file it downloads to the RCX. If there's an error, you'll hear about it like this:

            c:\>java Download thermometer.f
            ....
            Line 5: Error: redefine isRunButtonPressed RbuttonState ? undefined word
            c:\>

          By default, Download uses the COM1 port. If you are not running Windows, or if you have your IR tower attached to a
          different port, you can tell Download to use a different port like this:

            C:\>java Download -port COM3 thermometer.f

          Source Code

           import java.io.∗;
           import java.util.∗;

           import javax.comm.∗;

            public class Download {
              public static void main (String[] args) {
                String filename = args[args.length - 1];
                String portName = "COM1";

                for (int i = 0; i < args.length - 2; i++) {
                  if (args[i].equals("-port")) portName = args[i + 1];
              }

                try { new Download (filename, portName); }
                catch (NoSuchPortException nspe) {
                System.out.println("Sorry, I don't know about the " +
                  portName + " port. ");
              }
                catch (PortInUseException piue) {
                  System.out.println("Sorry, somebody else is using " +
                 portName + ".");
              }
                catch (UnsupportedCommOperationException ucoe) {
               System.out.println(ucoe);
              }
                catch (IOException ioe) {
                  System.out.println("An IOException occurred: " + ioe);
              }
           }

            private SerialPort mPort;
            private Reader mFileIn;
            private Writer mOut;
            private PortListener mPortListener;

            private static final int kCharSleep = 20;
   242   243   244   245   246   247   248   249   250   251   252