dotnet-bluetooth-le / dotnet-bluetooth-le

Bluetooth LE plugin for Xamarin/MAUI, supporting Android, iOS, Mac, Windows
Apache License 2.0
844 stars 315 forks source link

Error with GetCharacteristicsAsync method #889

Closed Nick-Blair19 closed 1 month ago

Nick-Blair19 commented 1 month ago

I am using ble.plugin 3.1.0 and ios ipad 17.7 I have error in visual studio with code var sendCharacteristic = service.GetCharacteristicsAsync(GattIdentifiers.UartGattCharacteristicSendId); I get error 'Task' does not contain a definition for 'GetCharacteristicsAsync' and no accessible extension method 'GetCharacteristicsAsync' accepting a first argument of type 'Task' could be found (are you missing a using directive or an assembly reference?) This is the code snippet public void Connect(IDevice _gattDevice) { this._adapter.ConnectToDeviceAsync(_gattDevice); var ble = CrossBluetoothLE.Current; var adapter = CrossBluetoothLE.Current.Adapter; try { var service = _gattDevice.GetServiceAsync(Guid.Parse("fefb")); if (service != null) {

            var sendCharacteristic = service.GetCharacteristicsAsync(GattIdentifiers.UartGattCharacteristicSendId); 

This should be working code and I get similar errors with read and write characteristics methods? Regards Nick.

smsissuechecker commented 1 month ago

Hi @Nick-Blair19,

I'm the friendly issue checker. It seems like (100.00 %) you haven't used our issue template :cry: I think it is very frustrating for the repository owners, if you ignore them.

If you think it's fine to make an exception, just ignore this message. But if you think it was a mistake to delete the template, please close the issue and create a new one.

Thanks!

Nick-Blair19 commented 1 month ago

bleplugin tme-5.zip

Nick-Blair19 commented 1 month ago

Just added sample project zip

M0n7y5 commented 1 month ago

This repo is dead... Use different library.

axa88 commented 1 month ago

This repo is dead... Use different library.

afraid you may be right

janusw commented 1 month ago

This repo is dead... Use different library.

Nah, it's not quite dead yet, it only smells a bit funny 😝

janusw commented 1 month ago

var service = _gattDevice.GetServiceAsync(Guid.Parse("fefb"));

The compile error you see is basically due to an await missing here.

This is a C# beginner question, not a bug report! (Please use 'Discussions' instead of 'Issues' for such things in GitLab, if at all.)

Nick-Blair19 commented 1 month ago

no the error is not with var service = _gattDevice.GetServiceAsync(Guid.Parse("fefb")); but with var sendCharacteristic = service.GetCharacteristicsAsync(GattIdentifiers.UartGattCharacteristicSendId); Also get similar errors with read and write characteristics ant StartUpdates

???

Nick-Blair19 commented 1 month ago
Screenshot 2024-10-10 at 13 19 53

This is the error

janusw commented 1 month ago

That is, as I said, because you're missing an await on the assignment of your service (so that it's of type Task instead of IService). Trust me ;)

(and please do some reading on asynchronous operations in C#, before posting further comments here)

Nick-Blair19 commented 1 month ago

oh by the way janus while youre there can I ask you a few more questions?

  1. How do I notify characteristics? Before when using xamarin corebluetooth I had SetNotifyValue but cant see anything like this here?

  2. how do I send Rx and Tx credits to 'Credit' characteristics (I have a Telit BLE module with a GATT service)? Before I had corebluetooth code this.PendingLocalUARTCreditsCount = this.MaxLocalUARTCreditsCount - this.LocalUARTCreditsCount; Byte[] byteData = new Byte[1]; byteData[0] = (Byte)((this.PendingLocalUARTCreditsCount & 0xFF)); NSData valueData = (NSData.FromArray(byteData)); peripheral.WriteValue(valueData, UartRxCreditsCharacteristic, CBCharacteristicWriteType.WithoutResponse);

  3. Lastly do you have the ability to discover bluetooth device adresses with ble.plugin?

Very many thanks. Regards Nick