josx.rcxcomm
Class Tower

java.lang.Object
  extended byjosx.rcxcomm.Tower

public class Tower
extends Object

Low-level interface to the Lego IR Tower Used by RCXPort to send and receive messages to and from the RCX. Can be used to send any packet or any sequence of bytes to the RCX. The tower is opened with a call to open() or open(port) and closed by a call to close(). send can be used to send a packet, and receive to receive one. write can read a sequence of bytes, and read can read them.


Constructor Summary
Tower()
          Create the tower class
 
Method Summary
 int close()
          Close the tower
 int getError()
          Get the last OS error
 int getUsbFlag()
          Getter for USB Flag
 void hexdump(String prefix, byte[] b, int n)
          dump hex to standard out
 int isAlive()
          Check if RCX is alive
 int open()
          Open the tower
 int open(String p)
          Open the tower
 int read(byte[] b)
          Low-level read
 int receive(byte[] b)
          Receive a packet
 int send(byte[] b, int n)
          send a packet to the RCX, e.g 0x10 for ping
 void setError(int e)
          Setter for OS Error
 int setFast(int fast)
          Set fast mode
 String strerror(int errno)
          Converts an error number to a string Note you should negate the error number before passing it to this method as this method expects a positive value.
 int write(byte[] b, int n)
          Write low-level bytes to the tower, e.g 0xff550010ef10ef for ping
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

Tower

public Tower()
Create the tower class

Method Detail

setFast

public int setFast(int fast)
Set fast mode

Parameters:
fast - - 0 = slow mode, 1 = fast mode

open

public int open(String p)
Open the tower


close

public int close()
Close the tower

Returns:
error number or zero for success

write

public int write(byte[] b,
                 int n)
Write low-level bytes to the tower, e.g 0xff550010ef10ef for ping

Parameters:
b - bytes to send
n - number of bytes
Returns:
error number

send

public int send(byte[] b,
                int n)
send a packet to the RCX, e.g 0x10 for ping

Parameters:
b - packet to send
n - number of bytes
Returns:
error number

read

public int read(byte[] b)
Low-level read

Parameters:
b - buffer to receive bytes
Returns:
number of bytes read

receive

public int receive(byte[] b)
Receive a packet

Parameters:
b - buffer to receive packet
Returns:
number of bytes read

hexdump

public void hexdump(String prefix,
                    byte[] b,
                    int n)
dump hex to standard out

Parameters:
prefix - identifies the dump
b - bytes to dump
n - numberof bytes

isAlive

public int isAlive()
Check if RCX is alive

Returns:
1 if alive, 0 if not

open

public int open()
Open the tower

Returns:
an error number or zero for success

strerror

public String strerror(int errno)
Converts an error number to a string Note you should negate the error number before passing it to this method as this method expects a positive value. param errno the negation of the returned error

Returns:
the message

getError

public int getError()
Get the last OS error

Returns:
the error number

getUsbFlag

public int getUsbFlag()
Getter for USB Flag

Returns:
USB Flag as an integer

setError

public void setError(int e)
Setter for OS Error