Пример #1
0
        protected override void OnReceive(object message)
        {
            switch (message)
            {
            case RespondTemperature m when m.RequestId == TemperatureRequestCorrelactionId:
                if (m.Temperature.HasValue)
                {
                    var temperatureAvailable = new TemperatureAvailable(m.Temperature.Value);
                    RecordTemperatureReading(Context.Sender, temperatureAvailable);
                }
                else
                {
                    RecordTemperatureReading(Context.Sender, NoTemperatureAvailable.Instance);
                }
                break;

            case Terminated m:
                RecordTemperatureReading(Context.Sender, SensorNotAvailable.Instance);
                break;

            case TemperatureQueryCanceled m:
                foreach (var sensorActor in ActorRefToSensorId.Keys)
                {
                    Readings.Add(ActorRefToSensorId[sensorActor], SensorTimedOut.Instance);
                }
                Requester.Tell(new RespondFloorTemperatures(RequestId, Readings.ToImmutableDictionary()));
                Context.Stop(Self);
                break;

            default:
                Unhandled(message);
                break;
            }
        }
Пример #2
0
        public void Read()
        {
            try
            {
                // Changes from idle to wait-for-trigger state.
                // May want to move to "Open". Unsure if state is changed back to idle upon scan completion.
                _v3497x.SCPI.INITiate.Command();

                // Sends trigger via bus source.
                _v3497x.SCPI.TRG.Command();

                // Transfers NVM readings to output buffer.
                _v3497x.SCPI.FETCh.QueryAllData(out string data);

                string[] dataSeparated = data.Split(',');

                // Remove previous readings.
                Readings.Clear();

                for (int i = 0; i < dataSeparated.Length; i += 2)
                {
                    // Parse sensor output from string into double and add to list of readings.
                    uint   key   = uint.Parse(dataSeparated[(i + 1)]) % 100;
                    double value = double.Parse(dataSeparated[i], System.Globalization.NumberStyles.Any);
                    Readings.Add(key, value);
                }
            }
            catch (Exception ex)
            {
                throw new DeviceCommandFailedException("Could not read from Keysight datalogger."
                                                       + Environment.NewLine + ex.Message);
            }
        }
Пример #3
0
        private async Task ReadSensorAsync()
        {
            GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(async() =>
            {
                DateTime ReadingTime = DateTime.Now;

                //Get PhotoResistor
                byte[] readBuffer  = new byte[3]; /* Buffer to hold read data*/
                byte[] writeBuffer = new byte[3] {
                    StartByte, Channel0, 0x00
                };

                SpiADC.TransferFullDuplex(writeBuffer, readBuffer); /* Read data from the ADC                           */
                Light = convertToInt(readBuffer);                   /* Convert the returned bytes into an integer value */

                //Get Temperature
                readBuffer  = new byte[3]; /* Buffer to hold read data*/
                writeBuffer = new byte[3] {
                    StartByte, Channel1, 0x00
                };

                SpiADC.TransferFullDuplex(writeBuffer, readBuffer); /* Read data from the ADC                           */
                int adcTemp = convertToInt(readBuffer);             /* Convert the returned bytes into an integer value */
                                                                    // millivolts = value * (volts in millivolts / ADC steps)
                double millivolts = adcTemp * (3300.0 / 1024.0);
                Temperature       = (millivolts - 500) / 10.0;      //given equation from sensor documentation

                if (Temperature > AlertTemperature)
                {
                    string m       = string.Format("Temperature {0} exceeds Alert Temperature {1}", Temperature, AlertTemperature);
                    Alert alertMsg = new Alert {
                        AlertMsg = m
                    };

                    //turn on alert LED, only way to clear it is IoT Central Command)
                    ledAlertValue = GpioPinValue.High;
                    ledAlert.Write(ledAlertValue);
                    Alert = redBrush;
                }

                Reading reading = new Reading
                {
                    ReadingDateTime = ReadingTime,
                    Temperature     = Temperature,
                    Light           = Light,
                    Control         = ledControlValue == GpioPinValue.High ? true : false
                };

                //limit the amount of data we are charting
                while (Readings.Count > 60)
                {
                    Readings.RemoveAt(0);
                }

                Readings.Add(reading);
            });
        }
Пример #4
0
        private void RecordTemperatureReading(IActorRef sensor, ITemperatureQueryReading temperatureReading)
        {
            var sensorId = ActorRefToSensorId[sensor];

            Context.Unwatch(sensor);
            ActorRefToSensorId.Remove(sensor);
            Readings.Add(sensorId, temperatureReading);
            if (ActorRefToSensorId.Count == 0)
            {
                Requester.Tell(new RespondFloorTemperatures(RequestId, Readings.ToImmutableDictionary()));
                Context.Stop(Self);
            }
        }
        private async Task RefreshDevices()
        {
            IsLoading = true;

            var registeredDevices = (await metersDatabase.GetMetersAsync()).ToList();

            var results = registeredDevices.Select(d => DownloadDeviceDataAsync(d)).ToArray();
            await Task.WhenAll(results);

            Readings.Clear();

            results
            .SelectMany(p => p.Result)
            .ToList()
            .ForEach(i => Readings.Add(i));

            IsLoading = false;
        }
Пример #6
0
 /// <summary>
 /// Add a new reading to the collection.
 /// </summary>
 /// <param name="reading">Reading to be added.</param>
 public void Add(TemperatureReading reading)
 {
     Readings.Add(reading);
     RaisePropertyChanged("Readings", "NumberOfReadings");
 }
Пример #7
0
 public void Add(ReadingFromSensor reading)
 {
     Readings.Add(reading);
 }
Пример #8
0
        private void _sensor_ReadingComplete(object sender, ReadingArgs e)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                ReadingDateTime = e.ReadingTime;

                PM1_0Concentration_CF1  = _sensor.PM1_0Concentration_CF1;
                PM2_5Concentration_CF1  = _sensor.PM2_5Concentration_CF1;
                PM10_0Concentration_CF1 = _sensor.PM10_0Concentration_CF1;

                PM1_0Concentration_amb  = _sensor.PM1_0Concentration_amb;
                PM2_5Concentration_amb  = _sensor.PM2_5Concentration_amb;
                PM10_0Concentration_amb = _sensor.PM10_0Concentration_amb;

                PM0_3Count  = _sensor.PM0_3Count;
                PM0_5Count  = _sensor.PM0_5Count;
                PM1_0Count  = _sensor.PM1_0Count;
                PM5_0Count  = _sensor.PM5_0Count;
                PM10_0Count = _sensor.PM10_0Count;

                ProductVersion = _sensor.ProductVersion;
                ErrorCodes     = _sensor.StatusCodes;

                while (Readings.Count > GraphReadings)
                {
                    Readings.RemoveAt(0);
                }

                Reading reading = new Reading
                {
                    PM1_0Concentration  = PM10_0Concentration_CF1,
                    PM2_5Concentration  = PM2_5Concentration_CF1,
                    PM10_0Concentration = PM10_0Concentration_CF1,
                    ReadingDateTime     = ReadingDateTime
                };

                Readings.Add(reading);

                while (CountsLow.Count > GraphReadings)
                {
                    CountsLow.RemoveAt(0);
                }

                CountsLow countsLow = new CountsLow
                {
                    PM2_5Count      = PM2_5Count,
                    PM5_0Count      = PM5_0Count,
                    PM10_0Count     = PM10_0Count,
                    ReadingDateTime = ReadingDateTime
                };

                CountsLow.Add(countsLow);

                while (CountsHigh.Count > GraphReadings)
                {
                    CountsHigh.RemoveAt(0);
                }

                CountsHigh countsHigh = new CountsHigh
                {
                    PM1_0Count      = PM1_0Count,
                    PM0_5Count      = PM0_5Count,
                    PM0_3Count      = PM0_3Count,
                    ReadingDateTime = ReadingDateTime
                };

                CountsHigh.Add(countsHigh);
            });
        }