org.openuat.sensors
Class BluetoothRFCOMMChannel

java.lang.Object
  extended by org.openuat.sensors.BluetoothRFCOMMChannel

public class BluetoothRFCOMMChannel
extends java.lang.Object

This is a very simple class that uses the JSR82 API to open an RFCOMM channel to a Bluetooth device.

Version:
1.0
Author:
Rene Mayrhofer

Constructor Summary
BluetoothRFCOMMChannel(java.lang.String remoteDeviceAddress, int remoteChannelNumber)
          Construct a Bluetooth RFCOMM channel object with a specific remote endpoint.
 
Method Summary
 void close()
          Closes the channel to the endpoint given to the constructor.
 java.io.InputStream getInputStream()
          Returns the InputStream object for reading from the remote Bluetooth device.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream object for writing to the remote Bluetooth device.
static void main(java.lang.String[] args)
          Switches the state of the local device between Master and Slave
 void open()
          Opens a channel to the endpoint given to the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BluetoothRFCOMMChannel

public BluetoothRFCOMMChannel(java.lang.String remoteDeviceAddress,
                              int remoteChannelNumber)
                       throws java.io.IOException
Construct a Bluetooth RFCOMM channel object with a specific remote endpoint. This does not yet open the channel, @see open needs to be called for that.

Parameters:
remoteDeviceAddress - The Bluetooth MAC address to connect to, in format "AABBCCDDEEFF".
remoteChannelNumber - The SDP RFCOMM channel number to connect to, usually between 1 and 10.
Throws:
java.io.IOException - When the local Bluetooth stack was not initialized properly.
Method Detail

open

public void open()
          throws java.io.IOException
Opens a channel to the endpoint given to the constructor.

Throws:
java.io.IOException - On Bluetooth errors.
java.io.IOException - When the channel has already been opened.

close

public void close()
           throws java.io.IOException
Closes the channel to the endpoint given to the constructor. It may be re-opened with another call to @see #open.

Throws:
java.io.IOException - On Bluetooth errors.
java.io.IOException - When the channel has not yet been opened.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns the InputStream object for reading from the remote Bluetooth device.

Returns:
The InputStream object openend in @see #open.
Throws:
java.io.IOException - When the channel has not yet been opened.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns the OutputStream object for writing to the remote Bluetooth device.

Returns:
The OutputStream object openend in @see #open.
Throws:
java.io.IOException - When the channel has not yet been opened.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        java.lang.NumberFormatException
Switches the state of the local device between Master and Slave

Throws:
java.io.IOException
java.lang.NumberFormatException


2005-2006, Rene Mayrhofer.