我在Java中使用Bluecove API时遇到了一个问题。我计划创建一个基本的BT侦听器,以便从自制设备(Arduino powered)接收一些数据。我有以下代码,非常容易理解:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.bluetooth.*;
import javax.microedition.io.*;
public class Bluetooth
{
private void startServer() throws IOException
{
//Create a UUID for SPP
UUID uuid = new UUID("1101", true);
//Create the servicve url
String connectionString = "btspp://localhost:" + uuid +";name=Magic Merlin Server";
//open server url
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open(connectionString);
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
StreamConnection connection = streamConnNotifier.acceptAndOpen();
RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
System.out.println("Remote device address: "+dev.getBluetoothAddress());
System.out.println("Remote device name: "+dev.getFriendlyName(true));
//read string from spp client
InputStream inStream=connection.openInputStream();
BufferedReader bReader=new BufferedReader(new InputStreamReader(inStream));
String lineRead=bReader.readLine();
System.out.println(lineRead);
//send response to spp client
OutputStream outStream = connection.openOutputStream();
PrintWriter pWriter=new PrintWriter(new OutputStreamWriter(outStream));
pWriter.write("Response String from SPP Server\r\n");
pWriter.flush();
pWriter.close();
streamConnNotifier.close();
}
public static void main(String[] args) throws IOException
{
LocalDevice localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());
Bluetooth sampleSPPServer = new Bluetooth();
sampleSPPServer.startServer();
}
}WHen我试图执行我的代码,我得到了这个奇怪的错误:
Exception in thread "main" javax.bluetooth.BluetoothStateException: BlueCove com.intel.bluetooth.BluetoothStackBlueZ not available
at com.intel.bluetooth.BlueCoveImpl.loadStackClass(BlueCoveImpl.java:342)
at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:427)
at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
at java.security.AccessController.doPrivileged(Native Method)
at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
at Bluetooth.main(Bluetooth.java:50)第50行是LocalDevice localDevice = LocalDevice.getLocalDevice();。
我的电脑上有一个启用了的BT加密狗,所以我真的对此很失望。如果你有任何关于如何解决这个问题的想法,那就太好了!
无论如何,感谢您阅读本主题。致以问候。
发布于 2013-01-11 18:24:10
最后,我找到了一种使用名为"GlovePie“的应用程序的更简单的方法。它提供了一个非常简单的接口来检索传感器值并通过网络协议发送。然后java程序监听该协议并获取这些值。
上面的错误(在我的第一篇文章中)是Bluecove跟踪器上报告的一个常见问题。
发布于 2012-10-28 03:10:58
如果这是在Linux上,您可以检查两件事:
net.sf.bluecove:bluecove-gpl:2.1.0吗?有关更多信息,请参阅this。libbluetooth-dev包?但这可能是特定于Xubuntu的。此包包含BlueZ,请键入apt-cache show libbluetooth-dev以查看说明。其他Linux发行版可能有一个等价库。
希望这能有所帮助。
发布于 2015-03-29 01:36:29
任何其他有此问题的人可能需要下载bluecove-gpl-x.jar以及bluecove-x.jar。你可以在这里买到,https://code.google.com/p/bluecove/downloads/list。
https://stackoverflow.com/questions/13047048
复制相似问题