jBotBrain.comm
Class BTCommPort

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

public class BTCommPort
extends Object
implements CommPort

Bluetooth communication abstraction class.
jBrain acts as client in communication. PC or other device must create "Serial Port" connection to jBrain.
To detect state of bluetooth device use getStatus() method.
Communication parameters like speed, parity, stop and data bits are ignored.

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
BTCommPort()
          Constructs BTCommPort object.
 
Method Summary
 void close()
          Close communication port
 int getStatus()
          Returns Bluetooth interface status.
 boolean open(int baudrate, int parity, int databits, int stopbits)
          Function used for compatibility, but function fails if Bluetooth hardware is powered off.
 int read(byte[] buffer, int offset, int len)
          Reads len bytes to buffer at offset from Bluetooth communication interface.
 int write(byte[] buffer, int offset, int len)
          Writes len bytes from buffer starting from offset to Bluetooth communication interface.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

BTCommPort

public BTCommPort()
Constructs BTCommPort object.

Parameters:
port - number of port (0 or 1)
Method Detail

open

public boolean open(int baudrate,
                    int parity,
                    int databits,
                    int stopbits)
Function used for compatibility, but function fails if Bluetooth hardware is powered off.
All parameters are ignored.

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 Bluetooth interface status.

Specified by:
getStatus in interface CommPort
Returns:
DEVICE_XXX value
See Also:
CommPort.DEVICE_OFF, CommPort.DEVICE_ON, CommPort.DEVICE_WAIT_CONN, CommPort.DEVICE_CONNECTED

read

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

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

write

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

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