private async Task DoReadDistance() { SetStatusActive(true); // the false happens in the bluetooth status handler. ncommand++; try { var valueList = await bleDevice.ReadDistance(); if (valueList == null) { SetStatus($"Error: unable to read Distance"); return; } var record = new DistanceRecord(); var Distance = valueList.GetValue("Distance"); if (Distance.CurrentType == BCBasic.BCValue.ValueType.IsDouble || Distance.CurrentType == BCBasic.BCValue.ValueType.IsString) { record.Distance = (double)Distance.AsDouble; Distance_Distance.Text = record.Distance.ToString(); // "N0"); // either N or F3 based on DEC HEX FIXED. hex needs conversion to int first? } DistanceRecordData.Add(record); } catch (Exception ex) { SetStatus($"Error: exception: {ex.Message}"); } }
private async void BleDevice_DistanceEvent(BleEditor.ValueParserResult data) { if (data.Result == BleEditor.ValueParserResult.ResultValues.Ok) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { var valueList = data.ValueList; var record = new DistanceRecord(); var Distance = valueList.GetValue("Distance"); if (Distance.CurrentType == BCBasic.BCValue.ValueType.IsDouble || Distance.CurrentType == BCBasic.BCValue.ValueType.IsString) { record.Distance = (double)Distance.AsDouble; Distance_Distance.Text = record.Distance.ToString(); // "N0"); // either N or F3 based on DEC HEX FIXED. hex needs conversion to int first? } var addResult = DistanceRecordData.AddRecord(record); }); } }