Exemple #1
0
        public void Execute(object parameter)
        {
            Counter counter = parameter as Counter;

            if (counter != null)
            {
                TransferData.ReadCounterMeasuredValue(counter, (byte)ModbusCommand.ReadPulsesFromCounter);
            }

            //throw new NotImplementedException();
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            DispatcherTimer tmpTimer = sender as DispatcherTimer;

            //MessageBox.Show(DateTime.Now.ToString("HH:mm:ss"));
            //CounterSystem tmpSystemDevice = systemDevice;
            int[] numberOfActiveDevices = (int[])tmpTimer.Tag;

            Debug.WriteLine(numberOfActiveDevices);
            int  index           = 0;
            bool readyToReadData = true;

            foreach (var device in numberOfActiveDevices)
            {
                if (device == 1)
                {
                    if (TransferData.DeviceFinishedMeasurements(systemDevice.device[index]))
                    {
                        //numberOfActiveDevices++;
                        numberOfActiveDevices[index] = 0;
                    }
                }
                readyToReadData &= !Convert.ToBoolean(device);
                ++index;
            }

            if (readyToReadData)
            {
                timer.Stop();
                //READ DATA from slave devices
                //systemDevice.device[0].counter[0].CounterNumber
                foreach (var device in systemDevice.device)
                {
                    foreach (var counter in device.counter)
                    {
                        if (counter.Active)
                        {
                            UInt32 resultValueFromCounter;
                            double measuredCounterValue;
                            //counter.CounterNumber
                            //Read Counter value
                            resultValueFromCounter = TransferData.ReadCounterMeasuredValue(counter, (byte)ModbusCommand.ReadPulsesFromCounter);
                            measuredCounterValue   = resultValueFromCounter * counter.CounterPulsesPerLiter;
                            measurementsResults.systemMeasurementsResults[device.DeviceNumber - 1].deviceMeasurementsResults[counter.CounterNumber - 1].counterMeasurementsResults[currentMeasurementNumber - 1].MeasuredCounterValue = measuredCounterValue;
                            //Read Examplary Counter value
                            resultValueFromCounter = TransferData.ReadCounterMeasuredValue(counter, (byte)ModbusCommand.ReadExamplaryValue);
                            measuredCounterValue   = resultValueFromCounter * counter.CounterPulsesPerLiter;
                            measurementsResults.systemMeasurementsResults[device.DeviceNumber - 1].deviceMeasurementsResults[counter.CounterNumber - 1].counterMeasurementsResults[currentMeasurementNumber - 1].MeasuredExamplaryCounterValue = measuredCounterValue;
                        }
                    }
                }
                this.mainViewModel.CurrentMeasurementNumber++;
            }
        }