本文整理匯總了Java中lejos.hardware.Bluetooth類的典型用法代碼示例。如果您正苦於以下問題:Java Bluetooth類的具體用法?Java Bluetooth怎麽用?Java Bluetooth使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Bluetooth類屬於lejos.hardware包,在下文中一共展示了Bluetooth類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: establishConnectionTo
import lejos.hardware.Bluetooth; //導入依賴的package包/類
@Override
public NXTConnection establishConnectionTo(String host, int timeOut) {
NXTCommConnector connector = Bluetooth.getNXTCommConnector();
NXTConnection con = null;
long start = System.currentTimeMillis();
while ( (con = connector.connect(host, NXTConnection.RAW)) == null && (System.currentTimeMillis() - start < timeOut * 1000) ) {
try {
Thread.sleep(100);
} catch ( InterruptedException e ) {
throw new DbcException(e);
}
}
if ( con == null ) {
throw new DbcException("Couldn't connect in given time");
}
return con;
}
示例2: startBlueToothConnection
import lejos.hardware.Bluetooth; //導入依賴的package包/類
static void startBlueToothConnection() // establish BT connection
{
NXTConnection connection = null;
try
{
// listen for BT connections
System.out.println("init BT connection ...");
connection = Bluetooth.getNXTCommConnector().waitForConnection(10000, NXTConnection.RAW);
inputDataStream = connection.openDataInputStream();
outputDataStream = connection.openDataOutputStream();
System.out.println("Connected");
}
catch (Exception a)
{
// TODO : properly reestablish BT connection on error
System.out.println("ERROR: shit hit the fan");
Bluetooth.getNXTCommConnector().cancel();
try {
inputDataStream.close();
outputDataStream.close();
connection.close();
} catch (IOException e) {
System.out.println("ERROR: closing failed");
}
startBlueToothConnection();
}
getData();
}
示例3: waitForConnection
import lejos.hardware.Bluetooth; //導入依賴的package包/類
@Override
public NXTConnection waitForConnection(int timeOut) {
NXTCommConnector connector = Bluetooth.getNXTCommConnector();
NXTConnection con = connector.waitForConnection(timeOut * 1000, NXTConnection.RAW);
return con;
}