當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。