Esempio n. 1
0
 public void AddPacket(DataPacketPoco packetPoco)
 {
     lock (this)
     {
         Packets.Add(packetPoco);
     }
 }
Esempio n. 2
0
 private static void OnData(DataPacketPoco dataPacket)
 {
     Console.WriteLine("count = "+ dataPacket.DataSize);
     Console.WriteLine("Напряжение питания");
     Console.WriteLine("канал 1 = " + dataPacket.Datas[0, 0]*4.9);
     Console.WriteLine("канал 2 = " + dataPacket.Datas[1, 0]*1.9);
     Console.WriteLine("канал 3 = " + dataPacket.Datas[2, 0]*1.8);
     Console.WriteLine("канал 4 = " + dataPacket.Datas[3, 0]);
 }
        public void UpdateData(DataPacketPoco dataPacket)
        {
            
            if (!_deviceManager.IsCheckingBlockAdapter)
            {
                dataService?.AddPacket(dataPacket);

                //if ((DateTime.UtcNow - LastUpdateTime).TotalSeconds > 5)
                {
                    //Task.Factory.StartNew(() =>
                    {
                        Debug.WriteLine("block number = " + dataPacket.NumberBlock);
                        Debug.WriteLine("Timeout = " + dataPacket.Timeout);
                        Debug.WriteLine("Timeout = " + (DateTime.UtcNow - StartDate).TotalMilliseconds);
                        Debug.WriteLine("DataSize = " + dataPacket.DataSize);
                        StartDate = DateTime.UtcNow;
                        LastUpdateTime = DateTime.Now;
                        var interCadrDelay = (double) 1024*1024/(_deviceManager.mE2010.InputRateInKhz*1000.0);
                        var stepOfPoint = 2000;

                        var firstEnabledIndex = 3;
                        for (var j = 0; j < dataPacket.NumberOfChannels; j++)
                        {
                            if (IsChannelEnabled(j))
                            {
                                for (int i = 0; i < dataPacket.DataSize; i += stepOfPoint)
                                {
                                    var value = dataPacket.Datas[j, i];
                                    datas[j].Add(
                                        Convert.ToDouble((double) i/dataPacket.DataSize + dataPacket.NumberBlock)*
                                        interCadrDelay,
                                        dataPacket.Datas[j, i]);
                                    maxY = Math.Max(value, maxY);
                                    minY = Math.Min(value, minY);
                                }
                                firstEnabledIndex = Math.Min(firstEnabledIndex, j);
                            }
                        }
                        var graphPane = zedGraphControlData.GraphPane;
                        // Устанавливаем интересующий нас интервал по оси X

                        graphPane.XAxis.Scale.Min = datas[firstEnabledIndex][0].X;
                        graphPane.XAxis.Scale.Max = datas[firstEnabledIndex][datas[firstEnabledIndex].Count - 1].X +
                                                    (graphPane.XAxis.Scale.Max - graphPane.XAxis.Scale.Min)/5.0;

                        // Устанавливаем интересующий нас интервал по оси Y
                        graphPane.YAxis.Scale.Min = minY - ((maxY - minY)*0.1 + 0.03);
                        graphPane.YAxis.Scale.Max = maxY + ((maxY - minY)*0.1 + 0.03);

                        
                        foreach (var pane in zedGraphControlData.GraphPane.CurveList)
                        {
                            int nChannel = (int)pane.Tag;
                            if (_deviceManager.Sensors[nChannel] != null)
                            {
                                pane.Label.Text = _deviceManager.Sensors[nChannel].Name;
                            }
                        }

                        // Обновим оси
                        zedGraphControlData.AxisChange();

                        // Обновим сам график
                        zedGraphControlData.Invalidate();
                    }
                    //);

                    LastUpdateTime = DateTime.UtcNow;
                }
            }
        }
Esempio n. 4
0
        public bool StartReadData()
        {
            if (!_needReadData)
            {
                if (!OpenLDevice()) return false;
                if (!_parametersSetted)
                    SetParameters();
                System.Threading.Thread.Sleep(500);
                _taskReadData = Task.Factory.StartNew(() =>
                {
                    // передадим требуемые параметры работы АЦП в модуль
                    int i;
                    var resSET_ADC_PARS = _pModulE2010.SET_ADC_PARS(_adcParsE2010, _dataStep);
                    _logger.Info("resSET_ADC_PARS = " + resSET_ADC_PARS);

                    _logger.Info("Start read data");

                    var resStop = _pModulE2010.STOP_ADC();
                    _logger.Info("resStop = " + resStop);

                    // делаем предварительный запрос на ввод данных
                    M_IO_REQUEST_LUSBAPI[] buffers = new M_IO_REQUEST_LUSBAPI[2];
                    for (i = 0; i < 2; i++)
                    {
                        buffers[i] = new M_IO_REQUEST_LUSBAPI();
                        buffers[i].Buffer = new short[2*_dataStep];
                    }
                    _pModulE2010.InitReading();
                    var resStart = _pModulE2010.START_ADC();
                    _logger.Info("resStart = " + resStart);
                    int index = 0;
                    int k = 0;
                    if (resStart > 0)
                    {
                        _needReadData = true;
                        _numberBlock = 0;
                        while (_needReadData)
                        {
                            var resRead = _pModulE2010.ReadDataSync(ref buffers[k]);
                            if (resRead == 1)
                            {
                                Task.Factory.StartNew(() =>
                                {
                                    if (OnData != null)
                                    {

                                        var data = Array.ConvertAll(buffers[k].Buffer, x => (float)x);
                                        int countData = data.Count() / 2;
                                        var datas = new float[4, countData / 4];
                                        int j = 0;
                                        int rangeIndex = (ushort)this.InputRange;
                                        double[] A = new[] {_adcParsE2010.AdcOffsetCoefs[rangeIndex, 0], _adcParsE2010.AdcOffsetCoefs[rangeIndex, 1], _adcParsE2010.AdcOffsetCoefs[rangeIndex, 2], _adcParsE2010.AdcOffsetCoefs[rangeIndex, 3] };
                                        double[] B = new[] { _adcParsE2010.AdcScaleCoefs[rangeIndex, 0], _adcParsE2010.AdcScaleCoefs[rangeIndex, 1], _adcParsE2010.AdcScaleCoefs[rangeIndex, 2], _adcParsE2010.AdcScaleCoefs[rangeIndex, 3] };
                                        for (var t = 0; t < countData; t += 4)
                                        {
                                            datas[0, j] = (float)((data[t] + A[0]) * B[0])/ 8192 * 3.0f;
                                            datas[1, j] = (float)((data[t+1] + A[1]) * B[1]) / 8192* 3.0f;
                                            datas[2, j] = (float)((data[t+2] + A[2]) * B[2]) / 8192 * 3.0f;
                                            datas[3, j] = (float)((data[t+3] + A[3]) * B[3]) / 8192 * 3.0f;
                                            j++;
                                        }
                                        var dataPacket = new DataPacketPoco
                                        {
                                            Datas = datas,
                                            NumberOfChannels = 4,
                                            DataSize = countData / 4,
                                            NumberBlock = _numberBlock,
                                            NumberOfWordsPassed = buffers[k].NumberOfWordsPassed,
                                            Timeout = buffers[k].TimeOut
                                        };

                                        if (_numberBlock > 0)
                                        {
                                            OnData(dataPacket);
                                        }

                                        _numberBlock++;
                                    }
                                });

                            }
                            k = (k + 1)%2;
                        }
                    }
                });
            }
            return true;
        }
        private void OnData(DataPacketPoco dataPacket)
        {
            lock (this)
            {
                if (_isCheckingBlockAdapter)
                    _isBlockAdapter = true;

                for (int nChannel = 0; nChannel < 4; nChannel++)
                {
                    var valueChannel = 0f;
                    for (int dataN = 0; dataN < dataPacket.DataSize / 10; dataN++)
                    {
                        valueChannel += dataPacket.Datas[nChannel, dataN];
                    }
                    valueChannel = valueChannel / (dataPacket.DataSize / 10);

                    if (bit0 == false && bit1)
                    {

                        if (fileSensorPocos.Any(s => Math.Abs(s.ValueIdentification - Convert.ToDecimal(valueChannel)) < 0.068m))
                        {
                            SensorPoco sensorPoco =
                                fileSensorPocos.FirstOrDefault( s => Math.Abs(s.ValueIdentification - Convert.ToDecimal(valueChannel)) < 0.068m);
                            if (sensorPoco != null)
                            {
                                Sensors[nChannel].Name = (nChannel + 1) + " " + sensorPoco.Name;
                                Sensors[nChannel].ValueConvert = sensorPoco.ValueConvert;
                                Sensors[nChannel].ValueDiff = sensorPoco.ValueDiff;
                                Sensors[nChannel].ValueIdentification = sensorPoco.ValueIdentification;
                            }
                        }
                    }

                    if (bit0 && bit1)
                    {
                        var percison = 0.5;
                        BlockAdapterValues[nChannel] = valueChannel * _convertValues[nChannel];
                        Debug.WriteLine(nChannel + " Adapter Value = " + BlockAdapterValues[nChannel]);
                        _isBlockAdapter = _isBlockAdapter && (Math.Abs(BlockAdapterValues[nChannel] - _blockAdapterExpectedValues[nChannel]) < percison);
                    }
                }

            }
        }
        public void UpdateData(DataPacketPoco dataPacket)
        {
            _dataService?.AddPacket(dataPacket);

            Task.Factory.StartNew(() =>
            {
                Console.WriteLine("block number = " + dataPacket.NumberBlock);
                if((DateTime.Now - LastUpdateTime).TotalSeconds < 1.0)
                    return;
                LastUpdateTime = DateTime.Now;
                var pointLists = new List<Point>[4];
                for (var j = 0; j < 4; j++)
                {
                    _grapDataLine[j] = new ObservableDataSource<Point>();
                    pointLists[j] = new List<Point>();
                }
                var stepOfPoint = 1000;
                for (var j = 0; j < dataPacket.NumberOfChannels; j++)
                {
                    for (int i = 0; i < dataPacket.DataSize; i+= stepOfPoint)
                    {
                        pointLists[j].Add(new Point(i, Convert.ToDouble(dataPacket.Datas[j,i])));
                    }
                }

                for (var j = 0; j < 4; j++)
                {
                    _grapDataLine[j].AppendMany(pointLists[j]);
                }

                NotifyOfPropertyChange(() => GrapDataLine1);
                NotifyOfPropertyChange(() => GrapDataLine2);
                NotifyOfPropertyChange(() => GrapDataLine3);
                NotifyOfPropertyChange(() => GrapDataLine4);

            });
        }
 private void OnDataE2010(DataPacketPoco dataPacket)
 {
     LastUpdateTime = DateTime.UtcNow;
     _lastDataPacketPoco = dataPacket;
     UpdateChannelNames();
 }