Example #1
0
        async void SelectService(BLEDeviceInfo dev)
        {
            try
            {
                var service = GTTServicelist[dev.DeviceTypeInfo.ServiceID.ToString().ToLower()];
                // Ensure we have access to the device.
                var accessStatus = await service.RequestAccessAsync();

                if (accessStatus == DeviceAccessStatus.Allowed)
                {
                    var result = await service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached);

                    if (result.Status == GattCommunicationStatus.Success)
                    {
                        characteristics = result.Characteristics;
                    }
                    else
                    {
                        MainPage.mainPage.commChannel.SendMessageToMCC(string.Format(CommunicationCommands.PUSLEOXIMETERCONNECTIONMSG,
                                                                                     "Error accessing service " + result.Status.ToString()));
                        MainPage.TestresultModel.NotifyStatusMessage?.Invoke("Error accessing service " + result.Status.ToString(), 1);
                        return;
                    }
                }
                else
                {
                    MainPage.mainPage.commChannel.SendMessageToMCC(string.Format(CommunicationCommands.PUSLEOXIMETERCONNECTIONMSG,
                                                                                 "Error accessing service " + accessStatus.ToString()));
                    MainPage.TestresultModel.NotifyStatusMessage?.Invoke("Error accessing service " + accessStatus.ToString(), 1);
                    return;
                }
            }
            catch (Exception ex)
            {
                MainPage.mainPage.commChannel.SendMessageToMCC(string.Format(CommunicationCommands.PUSLEOXIMETERCONNECTIONMSG,
                                                                             "Exception " + ex.Message));
                MainPage.TestresultModel.NotifyStatusMessage?.Invoke("Exception " + ex.Message, 2);
                return;
            }

            foreach (GattCharacteristic c in characteristics)
            {
                string characteristicname = DisplayHelpers.GetCharacteristicName(c);
                if (c.AttributeHandle.ToString().Equals(dev.DeviceTypeInfo.CharacteristicAttributeid)) //MainPage.TestresultModel.OximeterHandleid)
                {
                    oxymeterCharacteristic = c;
                    break;
                }
            }

            if (oxymeterCharacteristic == null)
            {
                MainPage.mainPage.commChannel.SendMessageToMCC(string.Format(CommunicationCommands.PUSLEOXIMETERCONNECTIONMSG,
                                                                             "OxyMeter Characteristic not found."));
                MainPage.TestresultModel.NotifyStatusMessage?.Invoke("OxyMeter Characteristic not found.", 1);
                return;
            }
            // BloodPressureMeasurementCharacteristic = selectedCharacteristic;
            var resultch = await oxymeterCharacteristic.GetDescriptorsAsync(BluetoothCacheMode.Uncached);

            if (resultch.Status != GattCommunicationStatus.Success)
            {
                MainPage.mainPage.commChannel.SendMessageToMCC(string.Format(CommunicationCommands.PUSLEOXIMETERCONNECTIONMSG,
                                                                             "Descriptor read failure: " + resultch.Status.ToString()));
                MainPage.TestresultModel.NotifyStatusMessage?.Invoke("Descriptor read failure: " + resultch.Status.ToString(), 1);
                return;
            }
            presentationFormat = null;
            if (oxymeterCharacteristic.PresentationFormats.Count > 0)
            {
                if (oxymeterCharacteristic.PresentationFormats.Count.Equals(1))
                {
                    // Get the presentation format since there's only one way of presenting it
                    presentationFormat = oxymeterCharacteristic.PresentationFormats[0];
                }
                else
                {
                    // It's difficult to figure out how to split up a characteristic and encode its different parts properly.
                    // In this case, we'll just encode the whole thing to a string to make it easy to print out.
                }
            }
            SubscribeDeviceReading();
        }///
Example #2
0
        public async void SelectBPMeasureServicesAsync(BLEDeviceInfo dv)
        {
            try
            {
                var service = GTTServicelist[dv.DeviceTypeInfo.ServiceID.ToLower()];
                // Ensure we have access to the device.
                var accessStatus = await service.RequestAccessAsync();

                if (accessStatus == DeviceAccessStatus.Allowed)
                {
                    var result = await service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached);

                    if (result.Status == GattCommunicationStatus.Success)
                    {
                        characteristics = result.Characteristics;
                    }
                    else
                    {
                        SendConnectionStatusmessageToMCC("Error accessing service " + result.Status.ToString());
                        NotifyStatusMessage?.Invoke("Error accessing service " + result.Status.ToString(), 1);
                        return;
                    }
                }
                else
                {
                    SendConnectionStatusmessageToMCC("Error accessing service " + accessStatus.ToString());
                    NotifyStatusMessage?.Invoke("Error accessing service " + accessStatus.ToString(), 1);
                    return;
                }
            }
            catch (Exception ex)
            {
                SendConnectionStatusmessageToMCC("Exception " + ex.Message);
                NotifyStatusMessage?.Invoke("Exception " + ex.Message, 2);
                return;
            }
            //BloodPressureMeasurement

            foreach (GattCharacteristic c in characteristics)
            {
                string characteristicname = DisplayHelpers.GetCharacteristicName(c);
                if ((string.Compare(characteristicname, MainPage.TestresultModel.BPCharacteristicName, true) == 0))
                {
                    BloodPressureMeasurementCharacteristic = c;
                    break;
                }
            }

            if (BloodPressureMeasurementCharacteristic == null)
            {
                SendConnectionStatusmessageToMCC("BloodPressureMeasurement Characteristic not found.");
                NotifyStatusMessage?.Invoke("BloodPressureMeasurement Characteristic not found.", 1);
                return;
            }
            // BloodPressureMeasurementCharacteristic = selectedCharacteristic;
            var resultch = await BloodPressureMeasurementCharacteristic.GetDescriptorsAsync(BluetoothCacheMode.Uncached);

            if (resultch.Status != GattCommunicationStatus.Success)
            {
                SendConnectionStatusmessageToMCC("Descriptor read failure: " + resultch.Status.ToString());
                NotifyStatusMessage?.Invoke("Descriptor read failure: " + resultch.Status.ToString(), 1);
                return;
            }

            presentationFormat = null;
            if (BloodPressureMeasurementCharacteristic.PresentationFormats.Count > 0)
            {
                if (BloodPressureMeasurementCharacteristic.PresentationFormats.Count.Equals(1))
                {
                    // Get the presentation format since there's only one way of presenting it
                    presentationFormat = BloodPressureMeasurementCharacteristic.PresentationFormats[0];
                }
                else
                {
                    // It's difficult to figure out how to split up a characteristic and encode its different parts properly.
                    // In this case, we'll just encode the whole thing to a string to make it easy to print out.
                }
            }
            SubscribeBPMeasureService();
        }