【发布时间】:2016-03-16 17:54:28
【问题描述】:
我目前正在尝试使用 32feet.net 连接到蓝牙扬声器,一旦关机(计算机或扬声器)它们会保持配对但不会自动重新连接。因此,我想创建一个 Windows 服务,如果它没有连接并且可以找到它,它会经常尝试重新连接它。
我试过了
C# 32feet.Net: Handling two bluetooth connections in seperate threads, gives 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;
}
}
}
列出设备 = new List();
在原始代码中这不存在,我不知道他是否从外部参考使用(设备)它。
【问题讨论】:
-
您将不得不提供更多细节。没有人能够回答您的问题。