-
-
Notifications
You must be signed in to change notification settings - Fork 221
Open
Description
library: InTheHand.Net.Bluetooth version 4.1.43.
framework: .net 6 (also possible to use .net 8)
target version: 10.0.22621.0
target os: windows
application: WPF
application framework: prism
I'm trying to receive information from the gatt server via CharacteristicValueChanged, but it doesn't seem to work.
Characteristic is a "indicate", so it need client to "accept" the responses coming from the gattserver before it proceed. Correct me if I'm wrong.
I'm not sure what to do with descriptor here, but maybe this is where I should do my acknowledge?
var readValueFromDescriptor = await descriptor.ReadValueAsync();
await descriptor.WriteValueAsync(readValueFromDescriptor);
readCharacteric!.CharacteristicValueChanged += Characteristic_CharacteristicValueChanged;
await readCharacteric.StartNotificationsAsync();
Rest of the code
public async Task ConnectToZd621()
{
try
{
BluetoothDevice? labelDevice =
(await _bluetoothService.GetNearbyDevicesViaBluetoothAsync()).FirstOrDefault(device =>
device.Name == "ZD621");
IEnumerable<BluetoothDevice>? labelDevices = await _bluetoothService.GetNearbyDevicesViaBluetoothAsync();
await labelDevice!.Gatt.ConnectAsync();
var service = await labelDevice!.Gatt.GetPrimaryServiceAsync(BluetoothUuid.FromGuid(Guid.Parse("38EB4A80-C570-11E3-9507-0002A5D5C51B")));
var isConnnected = labelDevice!.Gatt.IsConnected;
var read_characteric = await service
.GetCharacteristicAsync(BluetoothUuid.FromGuid(Guid.Parse("38EB4A81-C570-11E3-9507-0002A5D5C51B")));
var write_characteric = await service
.GetCharacteristicAsync(BluetoothUuid.FromGuid(Guid.Parse("38EB4A82-C570-11E3-9507-0002A5D5C51B")));
read_characteric!.CharacteristicValueChanged += Characteristic_CharacteristicValueChanged;
await read_characteric.StartNotificationsAsync();
byte[] message = Encoding.ASCII.GetBytes(GetMessageByItemNumber());
var mtu = labelDevice.Gatt.Mtu;
await write_characteric.WriteValueWithResponseAsync(message);
}
catch (Exception ex)
{
var t = ex;
throw;
}
}
Metadata
Metadata
Assignees
Labels
No labels