22.

previous chapter table of contents next chapter
  

RCXPort

Version 1.1 of the rcx package by Dario Laverde defines various classes, of which the most important is RCXPort :

 package rcx; public class RCXPort {     public RCXPort(String port);     public void addRCXListener(RCXListener rl);     public boolean open();     public void close();     public boolean isOpen();     public OutputStream getOutputStream();     public InputStream getInputStream();     public synchronized boolean write(byte[] bArray);     public String getLastError(); } 

The RCXOpcode class has a useful static method for creating byte code:

 package rcx; public class RCXOpcode {     public static byte[] parseString(String str); } 

The relevant methods for this project are the following:

  • The constructor RCXPort() . This takes the name of a port as parameter, which should be something like COM1 for Windows and /dev/ttySO for Linux.
  • The write() method is used to send an array of opcodes and their arguments to the RCX. This is machine code, and you can only read it with a disassembler or a Unix tool like octal dump (od -t xC) .
  • The static parseString() method of RCXOpcode can be used to translate a string of instructions in readable form to an array of bytes for sending to the RCX. It isn't as good as an assembler, because you have to give strings such as "21 81" to start the A motor. To use this method for Jini, we will have to use a non-static method in our interface, because static methods are not allowed.
  • To handle responses from the RCX, a listener may be added with addRCXListener() . The listener must implement this interface:
     package rcx; import java.util.*;                  /*  * RCXListener  * @author Dario Laverde  * @version 1.1  * Copyright 1999 Dario Laverde, under terms of GNU LGPL  */ public interface RCXListener extends EventListener {     public void receivedMessage(byte[] message);     public void receivedError(String error); } 
  


A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
EAN: N/A
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net