You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im make Windows Console Application and try communicate with BLE device by UART (by TX-trancieve RX-recieve chanels), but have 2 Issue for get TX result:
Event CharacteristicValueChanged never triggered
tx_char.Value crash (same with call ReadValueAsync())
IReadOnlyList<GattCharacteristic> characteristics = null;
GattCharacteristic rx_char = null;
GattCharacteristic tx_char = null;
// I. Get a Service
Task.Run(async () =>
{
List<GattService> availableServices = await token.device.Gatt.GetPrimaryServicesAsync(null);// .GetPrimaryServiceAsync(GattServiceUuids.Battery);
rx_service = availableServices.First(x => x.Uuid.Value == RX_SERVICE_UUID);
}).GetAwaiter().GetResult();
// II. Get a characteristic
Task.Run(async () =>
{
characteristics = await rx_service.GetCharacteristicsAsync();
}).GetAwaiter().GetResult();
for (int i = 0; i < characteristics.Count; i++)
{
if(characteristics[i].Uuid.Value.Equals(ST338BLE_Const.RX_CHAR_UUID))
{
rx_char = characteristics[i];
rx_char.CharacteristicValueChanged += RX_CharacteristicValueChanged;
//rx_char.StartNotificationsAsync();
}
else if(characteristics[i].Uuid.Value.Equals(ST338BLE_Const.TX_CHAR_UUID))
{
tx_char = characteristics[i];
tx_char.CharacteristicValueChanged += TX_CharacteristicValueChanged;
tx_char.StartNotificationsAsync();
}
}
// III. Send
Task.Run(async () =>
{
await rx_char.WriteValueWithResponseAsync(new byte[]{ /*APDU command*/ });
}).GetAwaiter().GetResult();
// IV. Try to Receive data
byte[] rec = tx_char.Value; // Crash when try read a result
// The same Crash result
//Task.Run(async () =>
//{
// rec = await tx_char.ReadValueAsync();
//}).GetAwaiter().GetResult();
I was able to get reproduce this error; it seems related to characteristics that produce a zero byte response.
This quick example illustrates the cause (I think):
uintcapacity=0;varbuffer=new Windows.Storage.Streams.Buffer(capacity);
buffer.ToArray();// System.ArgumentException: 'The specified buffer index is not within the buffer capacity. '
Im make Windows Console Application and try communicate with BLE device by UART (by TX-trancieve RX-recieve chanels), but have 2 Issue for get TX result:
Additional info:
Exception thrown 'System.ArgumentException'
StackTrace
"at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source, UInt32 sourceIndex, Int32 count)\r\n
at InTheHand.Bluetooth.GattCharacteristic.PlatformGetValue()\r\n
..."
The text was updated successfully, but these errors were encountered: