- Есть ли какие-либо другие технологии Bluetooth Low Energy, на которые мне следует обратить внимание? (Мне бы хотелось, чтобы платформа была кросс-платформенной, но я ориентируюсь на Windows 10 и более поздние версии)
- Я делаю что-то не так?
- Должен ли я вообще использовать Bluetooth?
Код: Выделить всё
using wclBluetooth;
using wclCommon;
using System.Text;
public class BluetoothManager
{
// BTFramework objects
private readonly wclBluetoothManager _wclBluetoothManager = new wclBluetoothManager();
private wclBluetoothRadio? _radio;
private wclGattServer? _gattServer;
private readonly List _clients = new List();
private bool _btReady;
private byte[]? _recvBuffer;
private int? _lastClientToWriteId;
public void Init()
{
_wclBluetoothManager.Open();
_radio = GetRadio();
if (!_radio.LeSupported)
{
Console.WriteLine("This device does not support Bluetooth Low Energy.");
return;
}
_radio.GetName(out string radioName);
_radio.SetConnectable(true);
_radio.SetDiscoverable(true);
Console.WriteLine($"Bluetooth radio name: {radioName}");
_gattServer = new wclGattServer();
// define callbacks
_gattServer.OnClientConnected += OnClientConnected;
_gattServer.OnWrite += OnWrite;
_gattServer.Initialize(_radio);
if (!_gattServer.Initialized)
{
Console.WriteLine("Gatt server was not initialized.");
return;
}
_btReady = true;
Console.WriteLine("Bluetooth Initialization completed.");
}
private wclBluetoothRadio GetRadio()
{
Int32 res = _wclBluetoothManager.GetLeRadio(out wclBluetoothRadio bluetoothRadio);
if (res != wclErrors.WCL_E_SUCCESS)
{
throw new BluetoothNotAvailableException("Error getting bluetooth radio.");
}
return bluetoothRadio;
}
private void OnClientConnected(object sender, wclGattServerClient client)
{
_clients.Add(client);
Console.WriteLine($"New client connected.");
}
private void OnWrite(object sender, wclGattServerClient client, wclGattLocalCharacteristic characteristic, byte[] data)
{
_recvBuffer = data;
_lastClientToWriteId = _clients.IndexOf(client);
}
- 32Feet.Net Bluetooth Classic: хотя при тестировании на другом ноутбуке с Windows это работало, Поддержка iPhone Classic Bluetooth очень ограничена.
- 32Feet.Net Bluetooth Low Energy: невозможно понять, как использовать платформу.
- BTFramework Bluetooth Low. Energy: Не удалось получить обратные вызовы для получения звонил/не смог распознать новые подключенные телефоны.
Подробнее здесь: https://stackoverflow.com/questions/758 ... y-on-net-c
Мобильная версия