[英]Bluetooth C# using 32feet.net to connect to a speaker
我目前正在尝试使用32feet.net连接蓝牙扬声器,一旦关闭(计算机或扬声器),他们保持配对,但他们不会自动重新连接。 因此,我想制作一个Windows服务,尝试每隔很长时间重新连接一次(如果未连接并且无法找到它)。
我努力了
C#32feet.Net:在单独的线程中处理两个蓝牙连接,给出SocketException
代码,但由于某些原因,有些东西会亮红色。
我也试图找出并使这个代码同时工作以达到同样的目的
public void btconnect()
{
List<Device> devices = new List<Device>();
InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices();
int count = array.Length;
for (int i = 0; i<count; i++)
{
Device device = new Device(array[i]);
devices.Add(device);
}
foreach(Device d in devices)
{
if (d.DeviceInfo.ToString().Equals("myphonesdevicenumber"))
{
Guid MyServiceUuid
= new Guid("{00112233-4455-6677-8899-aabbccddeeff}"); // found this somewhere not sure what the string represents.
byte[] guidbytearray = d.DeviceInfo.ToByteArray(); // guid as a byte array.
string guidstring = d.DeviceInfo.ToString(); //guid as a string.
Int64 guid64 = d.DeviceInfo.ToInt64(); // guid as an int64.
Guid g = new Guid(guidbytearray);
bc.Connect(d.DeviceInfo,MyServiceUuid);
// turnoff = false;
}
}
}
List devices = new List();
在原始代码中,这不是在那里,我不知道他是否从外部参考中使用(设备)它。
在32feet的文章中,他们列出了一个名为Device
的内部类。 你应该在你的程序中使用它。 Guid是用于连接到BT设备的插槽的标识符。 格式是一个32位长的十六进制数,分为8,4,4,4和12组。组之间有一个' - '。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.