当前位置: 首页>>代码示例>>Java>>正文


Java Bluetooth类代码示例

本文整理汇总了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;
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:18,代码来源:BluetoothComImpl.java

示例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();
}
 
开发者ID:galme,项目名称:ROLF-EV3,代码行数:31,代码来源:MainClass.java

示例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;
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:7,代码来源:BluetoothComImpl.java


注:本文中的lejos.hardware.Bluetooth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。