英文:
I can't use BluetoothLEAdvertisementPublisher.UseExtendedAdvertisement in my c# program
问题
我尝试创建一个发出自定义公司ID和制造商数据的BLE服务器的广告。公司ID工作正常,我可以在制造商数据中发送文本缓冲区。但是,当我尝试启用UseExtendedAdvertisement时,我的服务器不再发布。
如您所见,我的计算机支持BLE 5.0,所以我不明白为什么不能使用扩展广告功能。
这是我用来创建我的BLE服务器的代码。
英文:
I try to create a BLE server that emit an advertisement with a custom company id and manufacturer data. The company id work fine and I can send a text buffer in my manufacturer data.
but when I try to enable the UseExtendedAdvertisement, my server won't publish anymore.
As you can see my computer can handle BLE 5.0 so I don't understand why can't I use the extended Advertisement feature
publisher = new BluetoothLEAdvertisementPublisher();
//publisher.Advertisement.ManufacturerData.Add()
// We need to add some payload to the advertisement. A publisher without any payload
// or with invalid ones cannot be started. We only need to configure the payload once
// for any publisher.
// Add a manufacturer-specific section:
// First, let create a manufacturer data section
var manufacturerData = new BluetoothLEManufacturerData();
// Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
manufacturerData.CompanyId = 0xCA21;
// Finally set the data payload within the manufacturer-specific section
// Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
var writer = new DataWriter();
string author = "abcefghij";
// Convert a C# string to a byte array
byte[] test = Encoding.ASCII.GetBytes(author);
writer.WriteBytes(test);
// Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
manufacturerData.Data = writer.DetachBuffer();
// Add the manufacturer data to the advertisement publisher:
//publisher.UseExtendedAdvertisement = true;
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
Here the code I have to create my BLE server
答案1
得分: 0
即使硬件是蓝牙 LE 5.0 硬件,这并不意味着所有新的蓝牙 LE 5.0 功能都得到支持。您的应用程序应该通过 BluetoothAdapter.IsExtendedAdvertising 进行检查,以确保在开始使用这样的接口之前。
根据讨论的结果:
还应确保用于测试自己软件的测试环境具有必要的功能/特性
英文:
Even if the hardware is Bluetooth LE 5.0 hardware, this does not mean that all new Bluetooth LE 5.0 functions are supported. Your application should check this via BluetoothAdapter.IsExtendedAdvertising before it starts using such interfaces.
And as a result of the discussion:
It should also be ensured that the test environment with which one tests one's own software has the necessary functions/features
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论