【问题标题】:Bluetooth C# using 32feet.net to connect to a speaker蓝牙 C# 使用 32feet.net 连接到扬声器
【发布时间】: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();

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

【问题讨论】:

  • 您将不得不提供更多细节。没有人能够回答您的问题。

标签: c# bluetooth


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多