2017-07-06 9 views
2

Bluetoothを使用して2つ以上のデバイスを1つのデバイスに接続しようとしましたが、のC#でプログラムするのに最適な方法は何ですか?Bluetoothを使用して複数のデバイスを接続する方法

public BluetoothDeviceInfo[] DiscoverDevices(); 
+0

何か試したことがありますか?あなたの署名はちょうど言う:私は方法が必要です。私たちはあなたの仕事をするためにここにいません。 – HimBromBeere

答えて

2

使用可能なデバイスの数を取得することができ、その後、BluetoothClientクラスを使用するすべてのデバイスのListをループ:

int maxDevices = 10; 
List<Device> devices = new List<Device>(); 
BluetoothClient bc = new BluetoothClient(); 
BluetoothDeviceInfo[] array = bc.DiscoverDevices(maxDevices); 
int count = array.Length; 
for (int i = 0; i < count; i++) 
{ 
    Device device = new Device(array[i]); 
    devices.Add(device); 

    // the variable device will now hold a detected BT device. 
    // Now you can connect to the device: 
    bc.Connect(new BluetoothEndPoint((BluetoothAddress)adres,service)); 

    // Send a message to the device 
    System.Net.Sockets.NetworkStream stream = bc.GetStream(); 
    StreamWriter streamWriter = new StreamWriter(stream); 
    streamWriter.WriteLine("! 0 200 200 210 1"); 
} 
// the variable devices will now hold an array of all detected BT devices. 

注:DiscoverDevicesが完了するまでに約20〜30秒かかります。

+0

以上で、配列をループして情報を送ることができますか? –

+0

@ B.kどういう意味ですか? –

+0

申し訳ありません。 私はすべてのデバイスにmessegeを送信したいので、リスト "デバイス"をループする必要がありますか? どうすればデバイスに情報を送信できますか? –

関連する問題