josx.rcxcomm
Class RCXBean

java.lang.Object
  extended byjosx.rcxcomm.RCXBean
All Implemented Interfaces:
Serializable

public class RCXBean
extends Object
implements Serializable

Handles communication with a LEGO RCX Based on original code by the LEGO3 Team at DTU-IAU

See Also:
Serialized Form

Constructor Summary
RCXBean()
          Creates new RCXBean
 
Method Summary
 void close()
          Close this RCX bean.
 void finalize()
           
 void free(Object o)
          Make the RCX bean available for other threads.
 String getComPort()
          Getter for the property "ComPort".
 void lock(Object o)
          Create a lock of this the RCX bean.
 byte receive()
          Receive a byte from the RCX.
 byte[] receive(int n)
          Receive n bytes from the RCX.
 int receiveInt()
          Receive a byte from the RCX.
 void send(byte b)
          Send a byte to the RCX.
 void send(byte[] b)
          Send a byte array to the RCX
 void sendInt(int v)
          Send an integer to the RCX.
 void setComPort(String value)
          Change or set which comPort should be used for communication with the RCX
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

RCXBean

public RCXBean()
Creates new RCXBean

Method Detail

getComPort

public String getComPort()
Getter for the property "ComPort".

Returns:
The name of the comPort used by the bean.

setComPort

public void setComPort(String value)
                throws IOException
Change or set which comPort should be used for communication with the RCX

Parameters:
value - A identifier for the comPort e.g. COM1 or /dev/ttyS0
Throws:
IOException - If the initialysation of the comPort goes wrong.

sendInt

public void sendInt(int v)
             throws IOException
Send an integer to the RCX. The integer is sent as four bytes.

Parameters:
v - The integer to be sent.
Throws:
IOException - If the integer can not be sent.

send

public void send(byte b)
          throws IOException
Send a byte to the RCX.

Parameters:
b - The byte to send.
Throws:
IOException - If the byte can not be sent.

send

public void send(byte[] b)
          throws IOException
Send a byte array to the RCX

Parameters:
b - The byte array to send.
Throws:
IOException - If the byte array can not be sent.

receive

public byte receive()
             throws IOException
Receive a byte from the RCX.

Returns:
A byte sent from the RCX.
Throws:
IOException - If the read times out, or something else goes wrong.

receiveInt

public int receiveInt()
               throws IOException
Receive a byte from the RCX.

Returns:
A byte sent from the RCX.
Throws:
IOException - If the read times out, or something else goes wrong.

receive

public byte[] receive(int n)
               throws IOException
Receive n bytes from the RCX.

Parameters:
n - The number of bytes to receive.
Returns:
A byte array with bytes from the RCX.
Throws:
IOException - If the read times out.

lock

public void lock(Object o)
          throws IOException
Create a lock of this the RCX bean. The RCX bean can not be locked by an other object, before the free() has bin run.
Caution!! The lock does not prevent other thread from using the RCX bean!

Parameters:
o - The lock is bound to this object. It should therefore be unique for the thread.
Throws:
IOException - If an other object has allready locked the RCX bean.

free

public void free(Object o)
Make the RCX bean available for other threads.

Parameters:
o - The object which has the lock.

close

public void close()
Close this RCX bean.


finalize

public void finalize()