本文整理汇总了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;
}