蓝牙C#使用32feet.net连接到扬声器

时间:2016-03-16 17:54:29

标签: c# bluetooth

我目前正在尝试使用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;
            }
        }
    }

列出设备=新列表();

在原始代码中,这不存在,我不知道他是否正在使用(设备)来自外部参考。

1 个答案:

答案 0 :(得分:0)

在32feet的文章中,他们列出了一个名为Device的内部类。你应该在你的程序中使用它。 Guid是用于连接BT设备的套接字的标识符。 格式为32位长的十六进制数,分为8,4,4,4和12组。组之间有一个' - '。

相关问题