3

JavaでBluecoveAPIを使用する際に問題が発生しました。自家製のデバイス(Arduino搭載)からデータを受信するために、基本的なBTリスナーを作成する予定です。私は非常に理解しやすい次のコードを持っています:

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();
    }
}

コードを実行しようとすると、次の奇妙なエラーが発生します。

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ドングルが有効になっているので、本当にがっかりしています。これを解決する方法について何かアイデアがあれば、親切になります!

とにかくこの主題を読んでくれてありがとう。よろしく。

4

3 に答える 3

8

これが Linux の場合は、次の 2 つのことを確認できます。

  • あなたnet.sf.bluecove:bluecove-gpl:2.1.0のクラスパスにはありますか?詳細については、これを参照してください。
  • libbluetooth-devパッケージをインストールしていますか?ただし、これは Xubuntu 固有のものである可能性があります。このパッケージには BlueZ が含まれています。入力apt-cache show libbluetooth-devして説明を表示します。他の Linux ディストリビューションには、おそらく同等のライブラリがあります。

お役に立てれば。

于 2012-10-27T19:10:58.347 に答える
0

最後に、「GlovePie」という名前のアプリケーションを使用するより簡単な方法を見つけました。センサー値を取得し、ネットワークプロトコルを介して送信するための非常にシンプルなインターフェイスを提供します。次に、Javaプログラムがそのプロトコルをリッスンし、値を取得します。

上記のエラー(私の最初の投稿)は、Bluecoveトラッカーで報告されている一般的な問題です。

于 2013-01-11T10:24:09.660 に答える