private async void btnReadData_Click(object sender, RoutedEventArgs e) { byte[] tempValue = await tempSen.ReadValue(); double ambientTemp = IRTemperatureSensor.CalculateAmbientTemperature(tempValue, TemperatureScale.Celsius); double targetTemp = IRTemperatureSensor.CalculateTargetTemperature(tempValue, ambientTemp, TemperatureScale.Celsius); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { tbTemperature.Text = ambientTemp.ToString("0.00"); tbTargetTemperature.Text = targetTemp.ToString("0.00"); }); byte[] accValue = await acc.ReadValue(); double[] accAxis = Accelerometer.CalculateCoordinates(accValue, 1 / 64.0); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { tbAccelerometer.Text = "X: " + accAxis[0].ToString("0.00") + " Y: " + accAxis[1].ToString("0.00") + " Z: " + accAxis[2].ToString("0.00"); }); byte[] humValue = await hum.ReadValue(); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { tbHumidity.Text = HumiditySensor.CalculateHumidityInPercent(humValue).ToString("0.00") + "%"; }); }
public async Task <string> GetSensorDataNew() { byte[] x = await hum.ReadValue(); SensorValues.Humidity = HumiditySensor.CalculateHumidityInPercent(x).ToString("0.00");; x = await temp.ReadValue(); SensorValues.AmbientTemperature = IRTemperatureSensor.CalculateAmbientTemperature(x, TemperatureScale.Farenheit); SensorValues.TargetTemperature = IRTemperatureSensor.CalculateTargetTemperature(x, TemperatureScale.Farenheit); return("done"); }
private async void ReadDeviceData() { Sensor S = new Sensor(); // deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey("SensorTag", deviceKey)); Exception exc = null; try { byte[] tempValue = await tempSen.ReadValue(); double ambientTemp = IRTemperatureSensor.CalculateAmbientTemperature(tempValue, TemperatureScale.Farenheit); double targetTemp = IRTemperatureSensor.CalculateTargetTemperature(tempValue, ambientTemp, TemperatureScale.Farenheit); byte[] tempValue1 = await humidSen.ReadValue(); string humidity = HumiditySensor.CalculateHumidityInPercent(tempValue1).ToString("0.00") + "%"; humidityRes.Text = humidity; humidityBlock.Visibility = Visibility.Visible; humidityRes.Visibility = Visibility.Visible; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AmbientRes.Text = ambientTemp.ToString("0.00"); TargetRes.Text = targetTemp.ToString("0.00"); AmbientRes.Visibility = Visibility.Visible; TargetRes.Visibility = Visibility.Visible; temp1_Copy1.Visibility = Visibility.Visible; temp2_Copy.Visibility = Visibility.Visible; }); } catch (Exception ex) { exc = ex; await new MessageDialog(exc.Message).ShowAsync(); } }