tinyvm.rcx
Class Serial

java.lang.Object
  |
  +--tinyvm.rcx.Serial

public class Serial
extends Object

Low-level APIs for serial communications. Communication is carried out by sending packets with specific opcode formats. See the Opcodes section in Kekoa Proudfoot's RCX Internals page and the Opcode Reference. Additionally, see the serial and serial2rcx examples.


Method Summary
static boolean isPacketAvailable()
          Checks to see if a packet is available.
static int readPacket(byte[] aBuffer)
          Reads a packet received by the RCX, if one is available.
static void resetRcx()
          Resets serial communications.
static void sendPacket(byte[] aBuffer, int aOffset, int aLen)
          Sends a packet to the PC or another RCX.
static void setDataBuffer(byte[] aData)
          Sets the buffer that will be used to save data transferred with opcode 0x45.
 
Methods inherited from class java.lang.Object
getClass, toString
 

Method Detail

readPacket

public static int readPacket(byte[] aBuffer)
Reads a packet received by the RCX, if one is available. The first byte in the buffer is the opcode. Opcode 0x45 (Transfer Data) is received in a special way: Use setDataBuffer().
Returns:
The number of bytes received.
See Also:
isPacketAvailable(), setDataBuffer(byte[])

setDataBuffer

public static void setDataBuffer(byte[] aData)
Sets the buffer that will be used to save data transferred with opcode 0x45.

Note: This method must be used with caution. A pointer to the data buffer is passed to the ROM for asynchronous use. If more data is received than can be stored in the buffer, the VM's memory will be corrupted and it will crash or at least misbehave.


isPacketAvailable

public static boolean isPacketAvailable()
Checks to see if a packet is available. Call this method before calling receivePacket.

sendPacket

public static void sendPacket(byte[] aBuffer,
                              int aOffset,
                              int aLen)
Sends a packet to the PC or another RCX.

resetRcx

public static void resetRcx()
Resets serial communications.