jBotBrain.comm
Class UARTCommPort

java.lang.Object
  extended by jBotBrain.comm.UARTCommPort
All Implemented Interfaces:
CommPort

public class UARTCommPort
extends Object
implements CommPort

UART communication abstraction class.

NOTE: This class is not static, it must be allocated.

Author:
Martin Wolf
See Also:
CommPort

Field Summary
 
Fields inherited from interface jBotBrain.comm.CommPort
BR_115200, BR_1200, BR_19200, BR_2400, BR_38400, BR_4800, BR_57600, BR_9600, DATABITS_EIGHT, DATABITS_SEVEN, DEVICE_CONNECTED, DEVICE_OFF, DEVICE_ON, DEVICE_WAIT_CONN, PARITY_EVEN, PARITY_MARK, PARITY_NONE, PARITY_ODD, PARITY_SPACE, STOPBIT_1_5, STOPBIT_ONE, STOPBIT_TWO
 
Constructor Summary
UARTCommPort(int port)
          Constructs UARTCommPort object.
 
Method Summary
 void close()
          Close communication port
 int getStatus()
          Returns UART interface status.
 boolean open(int baudrate, int parity, int databits, int stopbits)
          Open communication port with comm speed baudrate, parity, databits and stopbits.
 int read(byte[] buffer, int offset, int len)
          Reads len bytes to buffer at offset from UART communication interface.
 int write(byte[] buffer, int offset, int len)
          Writes len bytes from buffer starting from offset to UART communication interface.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

UARTCommPort

public UARTCommPort(int port)
Constructs UARTCommPort object.

Parameters:
port - number of port (currently only 0)
Method Detail

open

public boolean open(int baudrate,
                    int parity,
                    int databits,
                    int stopbits)
Open communication port with comm speed baudrate, parity, databits and stopbits.

Specified by:
open in interface CommPort
Returns:
true if operation succeed
See Also:
CommPort.BR_115200, CommPort.BR_57600, CommPort.BR_38400, CommPort.BR_19200, CommPort.BR_9600, CommPort.BR_4800, CommPort.BR_2400, CommPort.BR_1200, CommPort.PARITY_NONE, CommPort.PARITY_ODD, CommPort.PARITY_EVEN, CommPort.PARITY_MARK, CommPort.PARITY_SPACE, CommPort.DATABITS_EIGHT, CommPort.DATABITS_SEVEN, CommPort.STOPBIT_ONE, CommPort.STOPBIT_1_5, CommPort.STOPBIT_TWO

close

public void close()
Close communication port

Specified by:
close in interface CommPort

getStatus

public int getStatus()
Returns UART interface status.

Specified by:
getStatus in interface CommPort
Returns:
DEVICE_OFF, if port is closed; DEVICE_CONNECTED, if port is open
See Also:
CommPort.DEVICE_OFF, CommPort.DEVICE_CONNECTED

read

public int read(byte[] buffer,
                int offset,
                int len)
Reads len bytes to buffer at offset from UART communication interface.

Specified by:
read in interface CommPort
Returns:
Number of bytes readen

write

public int write(byte[] buffer,
                 int offset,
                 int len)
Writes len bytes from buffer starting from offset to UART communication interface.

Specified by:
write in interface CommPort
Returns:
Number of bytes written