2016-12-13 13 views
0

私は同様の問題に関するいくつかの質問について読んだことがあります。しかし、それらのほとんどはサードパーティのBluetoothデバイス接続に関連しています。私が必要とするのは、IOSと接続を待っているサーバーアプレットとの間にブルートゥースシリアル接続を確立することです。このアプレットはWindowsまたはMAC OS上で動作するはずです。ここでは、サーバアプレットのJavaコードは次のとおりです。リモートPC/MACへのIOSブルートゥースシリアル接続

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import static my.remote.RemoteUI.OSName; 
import javax.bluetooth.*; 
import javax.microedition.io.*; 
import static my.remote.ProcessInput.line; 
import static my.remote.RemoteUI.OSName; 

/** 
* Class that implements an SPP Server which accepts single line of 
* message from an SPP client and sends a single line of response to the client. 
*/ 
public class Sspserver implements Runnable { 
    private static boolean Connected = true; 
    //start server 
    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=Sample SPP 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)); 

     while(Connected){ 
      try { 
       String lineRead=bReader.readLine(); 
       System.out.println(lineRead); 
       String com = lineRead.substring(0, lineRead.length()); 
       CommandActivity command = new CommandActivity(); 
       if ((lineRead != null) && (OSName != null)) { 
        command.Command(com,OSName); 
        System.out.println(com); 
       } 
      }catch(Exception e) { 
       return; 
      } 
     } 

    } 

    @Override 
    public void run() { 

     try { 
      //display local device address and name 
      LocalDevice localDevice = LocalDevice.getLocalDevice(); 
      System.out.println("Address: "+localDevice.getBluetoothAddress()); 
      System.out.println("Name: "+localDevice.getFriendlyName()); 

      //Sspserver sampleSPPServer=new Sspserver(); 
      startServer(); 
     } catch (BluetoothStateException ex) { 
      System.out.println(ex.getMessage()); 
     } catch (IOException ex) { 
      System.out.println(ex.getMessage()); 
     } 

    } 

} 

CommandActivityクラスは、ちょうど、デバイスからのデータの行を解析しています。 Androidデバイスは、PCのMACアドレスを使用して簡単にこのサーバーに接続できます。しかしIOSのために、私はブルートゥースのためのソケット接続のための解決策を見つけることができませんでした。

私はEAAccessoryManagerを試しましたが、残念ながらIOSデバイスはPCをアクセサリとして検出できませんでした。それはSupported external accessory protocolsの定義が必要ですが、私はすべてのPCまたはMACプロトコルを見つけることができません。

また、私はCoreBluetoothを試しました。しかし、このアプレットは、広告名やサービス/特性のUUIDではありません。

私が紛失している可能性がある簡単な方法が必要です。シンプルなシリアル接続は、IOSのような多くの機能を持つオペレーティングシステムにとっては問題ではありません。任意の提案が高く評価されました。ありがとう。

答えて

0

接続しているデバイスがMFi認定でない限り、外部アクセサリフレームワークを使用することができない限り、iOSアプリからBluetooth経由でシリアルポート接続を確立することはできません。お使いのPCはMFi認定デバイスではないため、動作しません。

Core Bluetoothを使用したり、Wi-Fi経由でTCP/IPなどの別の接続方法を使用できるように、PCをBLEデバイスとして宣伝する必要があります。