cbox.comm
Class UARTCommPort

java.lang.Object
  extended by cbox.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

Field Summary
 
Fields inherited from interface cbox.comm.CommPort
BR_115200, BR_1200, BR_19200, BR_2400, BR_38400, BR_4800, BR_57600, BR_9600, DATABITS_EIGHT, DATABITS_SEVEN, 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.
static boolean uartOpen(int port, int baudrate, int parity, int databits, int stopbits)
           
static int uartRead(int port, byte[] buffer, int offset, int len)
           
static int uartStatus()
           
static int uartWrite(int port, byte[] buffer, int offset, int len)
           
 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 (0 or 1)
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

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

uartOpen

public static boolean uartOpen(int port,
                               int baudrate,
                               int parity,
                               int databits,
                               int stopbits)

uartWrite

public static int uartWrite(int port,
                            byte[] buffer,
                            int offset,
                            int len)

uartRead

public static int uartRead(int port,
                           byte[] buffer,
                           int offset,
                           int len)

uartStatus

public static int uartStatus()