gpt4 book ai didi

c# - 我如何使用 c# 连接多个具有蓝牙技术的设备

转载 作者:行者123 更新时间:2023-11-30 23:11:08 26 4
gpt4 key购买 nike

我尝试使用蓝牙将两台以上的设备连接到一台设备,如果我在 c# 中编程,最好的方法是什么?

public BluetoothDeviceInfo[] DiscoverDevices();

最佳答案

您可以获得可用设备的数量,然后使用 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 秒才能完成。

关于c# - 我如何使用 c# 连接多个具有蓝牙技术的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44942397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com