private async Task Process(ISpectralСharacterizationRequest request) { Logger.Info($"Получен запрос (RequestId = {request.RequestId})"); var response = new SpectralСharacterizationResponse { RequestId = request.RequestId, Results = new List <ICharacteristicResult>() }; foreach (var characteristic in request.Characteristics) { Logger.Info($"{characteristic.CharacteristicType.GetDescription()}..."); var result = new CharacteristicResult { CharacteristicType = characteristic.CharacteristicType, Paths = _processorsDictionary[characteristic.CharacteristicType].Process(request.LeftUpper, request.RightLower, characteristic.DataFolder, characteristic.ResultFolder) }; response.Results.Add(result); } await _busManager.Send <ISpectralСharacterizationResponse>(BusQueueConstants.CharacterizationResponseQueueName, response); Logger.Info($"Запрос обработан (RequestId = {request.RequestId})"); }
void SetReadValue(CharacteristicResult result, bool fromUtf8) { Device.BeginInvokeOnMainThread(async() => { //this.IsValueAvailable = true; //this.LastValue = DateTime.Now; if (result.Data == null) { this.Value = "EMPTY"; } else { string tempval = "emp"; if (String.IsNullOrEmpty(Value)) { this.Value = System.Text.Encoding.UTF8.GetString(result.Data, 0, result.Data.Length - 1); } else { tempval = System.Text.Encoding.UTF8.GetString(result.Data, 0, result.Data.Length - 1); } if (!Value.Equals(tempval) && result.Data.Length < 5) { if (!tempval.Equals("emp")) { this.Value = tempval; } int nr = int.Parse(Value); if (nr > 107) { //await DisplayAlert("Laddar:", " Batteriet laddar.", "OK"); double resultlvl = (((double)nr / 107) * 100); progBar.BindingContext = new { w4 = App.ScreenWidth * 160 / (App.ScreenDPI * 3), theprog = 1 }; progBarText.BindingContext = new { theprogtext = "Laddar" }; } else { double resultlvl = (((double)nr / 107) * 100); progBar.BindingContext = new { w4 = App.ScreenWidth * 160 / (App.ScreenDPI * 3), theprog = (resultlvl / 100) }; progBarText.BindingContext = new { theprogtext = resultlvl.ToString("#") + "%" }; } } else if (App.dangerModeOn && result.Data.Length > 5) { postAlarm(); } } //this.Value = fromUtf8 ? Encoding.UTF8.GetString(result.Data, 0, result.Data.Length) : BitConverter.ToString(result.Data); }); }
public async Task WriteCharacteristicAsync(Tuple <Guid, Guid> gattChar, GattCharWriteType writeType, byte[] value) { var ch = await GetGattCharacteristicAsync(gattChar); if (writeType == GattCharWriteType.WRITE_WITH_RESPONSE) { CharacteristicResult resp = await ch.Write(value); //if (resp.S) // Note - whaddayou do with a failed write? } else { ch.WriteWithoutResponse(value); } }
void SetReadValue(CharacteristicResult result, bool fromUtf8) { Device.BeginInvokeOnMainThread(() => { this.IsValueAvailable = true; this.LastValue = DateTime.Now; if (result.Data == null) { this.Value = "EMPTY"; } else { this.Value = fromUtf8 ? Encoding.UTF8.GetString(result.Data, 0, result.Data.Length) : BitConverter.ToString(result.Data); } }); }
static void Write(IObserver <BleLogEvent> ob, IDevice device, CharacteristicResult result) { switch (result.Event) { case CharacteristicEvent.Notification: Write(ob, device, BleLogFlags.CharacteristicNotify, result.Characteristic.Uuid, result.Data); break; case CharacteristicEvent.Read: Write(ob, device, BleLogFlags.CharacteristicRead, result.Characteristic.Uuid, result.Data); break; case CharacteristicEvent.Write: Write(ob, device, BleLogFlags.CharacteristicWrite, result.Characteristic.Uuid, result.Data); break; } }
/// <summary> /// ///Bleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee /// </summary> /// <param name="result"></param> /// <param name="fromUtf8"></param> //public string Value { get; private set; } void SetReadValueB(CharacteristicResult result, bool fromUtf8) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { // this.IsValueAvailable = true; //this.LastValue = DateTime.Now; if (result.Data == null) { PostData(); } /* this.Value = "EMPTY"; * else * { * this.Value = fromUtf8 ? Encoding.UTF8.GetString(result.Data, 0, result.Data.Length) : BitConverter.ToString(result.Data); * if (!String.IsNullOrEmpty(this.Value)) * PostData(); * }*/ }); }