java bluecove,Java-蓝牙API Bluecove问题

I'm having an issue using the Bluecove API in Java. I plan to create a basic BT listener in order to receive some data from a homemade device (Arduino powered). I've the following code which is quite easy to understand:

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 I try to execute my code, I got this weird error:

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)

The 50th line is LocalDevice localDevice = LocalDevice.getLocalDevice();.

I have a BT dongle on my computer which is enabled, so I'm really disapointed with that.

If you have any idea on how to solve this, it'd be kind!

Thanks anyway for reading this subject.

Regards.

解决方案

Finally I found an easier way using an application named "GlovePie". It provides a very simple interface to retrieve the sensor values and send it through a network protocol. Then a java program listen to that protrocol and grab the values.

The above error (in my first post) is a common issue that has been reported on Bluecove tracker.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值