Unhandled error exception

Hello, I have an error I can't find. it produces this message: System.NullReferenceException: Object reference not set to an instance of an object.
There is no code shown as it is excecuting externally.

`public async System.Threading.Tasks.Task scanAsync()
{
MainPage page1 = new MainPage();
var ble = CrossBluetoothLE.Current;
var adapter = CrossBluetoothLE.Current.Adapter;
var state = ble.State;
ble.StateChanged += (s, e) =>
{
};
adapter.DeviceDiscovered += (s, a) => deviceList.Add(a.Device);
await adapter.StartScanningForDevicesAsync();
int index = deviceList.FindIndex(item => item.Name == "CTQBLE");
if (index >= 0)
{
try
{
await adapter.ConnectToDeviceAsync(deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault());
bleRecieveAsync(); //Error occurs here
page1.deviceConnected();

                }
            catch (DeviceConnectionException e)
                {
                    page1.deviceNotConnected();
                }
        }    
        else
        {
            page1.deviceNotConnected();
            return;
        }
    }

    public async void  bleRecieveAsync()
    {
        var service1 = await deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault().GetServiceAsync(Guid.Parse("abcd0021-9c79-4ed6-a382-50946d830c3f"));
        var characteristicFirmware = await service1.GetCharacteristicAsync(Guid.Parse("abcd0022-9c79-4ed6-a382-50946d830c3f"));
        var bytesFirmware = await characteristicFirmware.ReadAsync();

        var service2 = await deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault().GetServiceAsync(Guid.Parse("abcd0021-9c79-4ed6-a382-50946d830c3f"));
        var characteristicRunState = await service2.GetCharacteristicAsync(Guid.Parse("abcd0023-9c79-4ed6-a382-50946d830c3f"));
        var bytesRunState = await characteristicRunState.ReadAsync();

        var service3 = await deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault().GetServiceAsync(Guid.Parse("abcd0021-9c79-4ed6-a382-50946d830c3f"));
        var characteristicConfig = await service3.GetCharacteristicAsync(Guid.Parse("abcd0024-9c79-4ed6-a382-50946d830c3f"));
        var bytesConfig = await characteristicConfig.ReadAsync();

        var service4 = await deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault().GetServiceAsync(Guid.Parse("abcd0021-9c79-4ed6-a382-50946d830c3f"));
        var characteristicError = await service4.GetCharacteristicAsync(Guid.Parse("abcd0025-9c79-4ed6-a382-50946d830c3f"));
        var bytesError = await characteristicError.ReadAsync();

        var service5 = await deviceList.Where(i => i.Name == "CTQBLE").FirstOrDefault().GetServiceAsync(Guid.Parse("abcd0021-9c79-4ed6-a382-50946d830c3f"));
        var characteristicCommand = await service5.GetCharacteristicAsync(Guid.Parse("abcd0026-9c79-4ed6-a382-50946d830c3f"));
        var bytesCommand = await characteristicCommand.ReadAsync();
    }
    `

Best Answer

  • blearibleari ✭✭
    Accepted Answer

    The issue was that characteristicCommand was not broadcasting any data.

Answers

Sign In or Register to comment.