lejos.nxt.comm
Class RS485

java.lang.Object
  extended by lejos.nxt.comm.NXTCommDevice
      extended by lejos.nxt.comm.RS485

public class RS485
extends NXTCommDevice

Low-level RS485/BitBus Network implementation This class provides simple low level access to the underlying RS485 hardware implemented on port 4 of the Lego NXT. It also supports a higher level network connection based on this hardware, in the form of a BitBus netowk node implmentation. For full details see the BitBus specifiaction at: http://www.bitbus.org/ Basically the network provides a simple master/slave implementation using SDLC packet framing with CRC-16-CITT error checking. In this implementation the on the wire format has been modified to use the Lego defined baud rate of 921600 bps and uses byte stuffing rather than bit stuffing (since there is no hardware support). The protocol has been integrated with the standard leJOS connection object and offers up to 7 connections. The BitBus broadcast mechanism is used to provide a higher level mapping between NXT address (we use the Bluetooth address of the nxt), or name and the underlying BitBus address (a single byte). The original implementation used Java for frame handling. However this was found to add considerable overhead to the process. To improve performance (by a factor of approximately 10), the lowest level routines have been re-implemented in C and moved into the firmware as native methods.

Author:
Andy Shaw

Field Summary
static int BUFSZ
           
static int MAX_CONNECTIONS
           
 
Fields inherited from class lejos.nxt.comm.NXTCommDevice
ADDRESS_LEN, cs, NAME, NAME_LEN, SERIAL_NO
 
Method Summary
static RS485Connection connect(String target)
          Connect to a remote device by name/address
static RS485Connection connect(String target, int mode)
          Connect to a remote device either by name or by address.
static NXTCommConnector getConnector()
          Provides access to the singleton connection object.
static void hsDisable()
          Disable the RS485 hardware port.
static void hsEnable()
          Enable the RS485 hardware port.
static int hsRead(byte[] buf, int offset, int len)
          Low level read from the RS485 port
static int hsWrite(byte[] buf, int offset, int len)
          Low level write to the RS485 hardware port.
static RS485Connection waitForConnection(int timeout, int mode)
          Wait for a connection from another nxt
 
Methods inherited from class lejos.nxt.comm.NXTCommDevice
addressToString, getAddress, getName, isAddress, loadSettings, nameToString, setAddress, setName, stringToAddress, stringToName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFSZ

public static final int BUFSZ
See Also:
Constant Field Values

MAX_CONNECTIONS

public static final int MAX_CONNECTIONS
See Also:
Constant Field Values
Method Detail

connect

public static RS485Connection connect(String target,
                                      int mode)
Connect to a remote device either by name or by address.

Parameters:
target - The address/name of the remote device to connect to
mode - I/O mode to use for this connection
Returns:
null if failed to connect, or a NXTConnection object

connect

public static RS485Connection connect(String target)
Connect to a remote device by name/address

Parameters:
target - The name/address of the remote device
Returns:
null if failed to connect, or a NXTConnection object

waitForConnection

public static RS485Connection waitForConnection(int timeout,
                                                int mode)
Wait for a connection from another nxt

Parameters:
timeout - How long to wait for the connect 0 means wait forever
mode - The I/O mode to use for this connection
Returns:
null if failed to connect, or a NXTConnection object

hsEnable

public static void hsEnable()
Enable the RS485 hardware port.


hsDisable

public static void hsDisable()
Disable the RS485 hardware port.


hsRead

public static int hsRead(byte[] buf,
                         int offset,
                         int len)
Low level read from the RS485 port

Parameters:
buf -
offset -
len -
Returns:
the number of bytes read

hsWrite

public static int hsWrite(byte[] buf,
                          int offset,
                          int len)
Low level write to the RS485 hardware port.

Parameters:
buf -
offset -
len -
Returns:
the number of bytes written

getConnector

public static NXTCommConnector getConnector()
Provides access to the singleton connection object. This object can be used to create new connections.

Returns:
the connector object