private async ValueTask Read(IReadOnlyList <S7Tag> tagList) { await ReadSemaphore.WaitAsync(); Task <List <DataItem> > result = null; try { result = ClientRead.ReadMultipleVarsAsync(tagList.Select(t => t.DataItemTag).ToList()); await result.ConfigureAwait(false); } catch (Exception ex) { Logger.LogError("Read: " + ex.Message + " - " + ex.StackTrace); } finally { ReadSemaphore.Release(); } if (result != null) { var currentTime = DateTime.Now; for (int i = 0; i < tagList.Count; i++) { await tagList[i].SetReadValue(result.Result[i].Value.ToString(), currentTime) .ConfigureAwait(false); //ToDo } } }//Read
public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status) { base.OnCharacteristicRead(gatt, characteristic, status); ReadSemaphore.Release(); if (characteristic.Uuid == BcoreUuid.BatteryVol) { ReadBatteryResult?.Invoke(this, new ReadBatteryVoltageEventArgs(characteristic.GetValue())); } else if (characteristic.Uuid == BcoreUuid.GetFunctions) { ReadFunctionResult?.Invoke(this, new ReadFunctionsEventArgs(characteristic.GetValue())); } }
private async Task ReadCharacteristic(UUID uuid) { if (!BcoreCharacteristics.ContainsKey(uuid.ToString().ToLower())) { return; } var characteristic = BcoreCharacteristics[uuid.ToString().ToLower()]; if (!characteristic.Properties.HasFlag(GattProperty.Read)) { return; } await ReadSemaphore.WaitAsync(); DeviceGatt.ReadCharacteristic(characteristic); }