Beispiel #1
0
        private void FetchLoop()
        {
            while (isRunning)
            {
                if (device.SelectedChannels.Length != 0)
                {
                    if (device.ReadyToFetch)
                    {
                        device.Fetch(ref readData);
                        ArrayCalculation.MultiplyScale(ref readData, Double.Parse(_attenuation));

                        //isExecCompleted = true;
                        isRunning     = false;
                        dataAvailable = true;
                    }
                }
                Thread.Sleep(1);
            }
        }
 public virtual void Multiply(ref short[] srcDest, short scalar)
 {
     ArrayCalculation.MultiplyScale(ref srcDest, scalar);
 }
 public virtual void Multiply(ref double[] srcDest, double scalar)
 {
     ArrayCalculation.MultiplyScale(ref srcDest, scalar);
 }
        private void ProcessQueue()
        {
            while (start)
            {
                Thread.Sleep(1);
                if (myqueue.Count > 0)
                {
                    qoutdata = myqueue.Dequeue();
                    if (lasttime.ToString("yyy_MM_dd_HH_mm_ss") == qoutdata.logtime.ToString("yyy_MM_dd_HH_mm_ss"))
                    {
                        qoutdata.logtime = qoutdata.logtime.AddSeconds(1);
                    }
                    if (qoutdata.averageindex == 1)
                    {
                        csvfilename = qoutdata.logtime.ToString("yyy_MM_dd_HH_mm_ss");
                    }
                    lasttime = qoutdata.logtime;
                    //显示波形需要做一次转置

                    if (Chcount == 1)
                    {
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 0, ref ch0RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch0RawValue, ch0sensivity);
                        Spectrum.PowerSpectrum(ch0RawValue, aitask.SampleRate, ref ch0sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        spectrumcalculation(1, qoutdata.averageindex, ch0sprectrumValue);
                        CsvData(filepath, "CH0_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch0sprectrumValue, ch0averagesprectrumValue);

                        if (qoutdata.averageindex == averagetimes)
                        {
                            if (mqtt_client.IsConnected)
                            {
                                WriteChannelData(1);
                            }
                            copyalarmfile(filepath, qoutdata.logtime);
                        }
                    }
                    else if (Chcount == 2)
                    {
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 0, ref ch0RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch0RawValue, ch0sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 1, ref ch1RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch1RawValue, ch1sensivity);
                        Spectrum.PowerSpectrum(ch0RawValue, aitask.SampleRate, ref ch0sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch1RawValue, aitask.SampleRate, ref ch1sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        spectrumcalculation(1, qoutdata.averageindex, ch0sprectrumValue);
                        spectrumcalculation(2, qoutdata.averageindex, ch1sprectrumValue);
                        CsvData(filepath, "CH0", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch0sprectrumValue, ch0averagesprectrumValue);
                        CsvData(filepath, "CH1", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch1sprectrumValue, ch1averagesprectrumValue);
                        if (qoutdata.averageindex == averagetimes)
                        {
                            if (mqtt_client.IsConnected)
                            {
                                WriteChannelData(2);
                            }
                            copyalarmfile(filepath, qoutdata.logtime);
                        }
                    }
                    else if (Chcount == 3)
                    {
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 0, ref ch0RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch0RawValue, ch0sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 1, ref ch1RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch1RawValue, ch1sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 2, ref ch2RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch2RawValue, ch2sensivity);
                        Spectrum.PowerSpectrum(ch0RawValue, aitask.SampleRate, ref ch0sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch1RawValue, aitask.SampleRate, ref ch1sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch2RawValue, aitask.SampleRate, ref ch2sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        spectrumcalculation(1, qoutdata.averageindex, ch0sprectrumValue);
                        spectrumcalculation(2, qoutdata.averageindex, ch1sprectrumValue);
                        spectrumcalculation(3, qoutdata.averageindex, ch2sprectrumValue);
                        CsvData(filepath, "CH0_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch0sprectrumValue, ch0averagesprectrumValue);
                        CsvData(filepath, "CH1_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch1sprectrumValue, ch1averagesprectrumValue);
                        CsvData(filepath, "CH2_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch2sprectrumValue, ch2averagesprectrumValue);

                        if (qoutdata.averageindex == averagetimes)
                        {
                            if (mqtt_client.IsConnected)
                            {
                                WriteChannelData(3);
                            }
                            copyalarmfile(filepath, qoutdata.logtime);
                        }
                    }
                    else
                    {
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 0, ref ch0RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch0RawValue, ch0sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 1, ref ch1RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch1RawValue, ch1sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 2, ref ch2RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch2RawValue, ch2sensivity);
                        ArrayManipulation.GetArraySubset(qoutdata.RawData, 3, ref ch3RawValue, ArrayManipulation.IndexType.column);
                        ArrayCalculation.MultiplyScale(ref ch3RawValue, ch3sensivity);
                        Spectrum.PowerSpectrum(ch0RawValue, aitask.SampleRate, ref ch0sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch1RawValue, aitask.SampleRate, ref ch1sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch2RawValue, aitask.SampleRate, ref ch2sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        Spectrum.PowerSpectrum(ch3RawValue, aitask.SampleRate, ref ch3sprectrumValue, out df, SpectrumUnits.V, WindowType.Hanning);
                        spectrumcalculation(1, qoutdata.averageindex, ch0sprectrumValue);
                        spectrumcalculation(2, qoutdata.averageindex, ch1sprectrumValue);
                        spectrumcalculation(3, qoutdata.averageindex, ch2sprectrumValue);
                        spectrumcalculation(4, qoutdata.averageindex, ch3sprectrumValue);
                        CsvData(filepath, "CH0_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch0sprectrumValue, ch0averagesprectrumValue);
                        CsvData(filepath, "CH1_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch1sprectrumValue, ch1averagesprectrumValue);
                        CsvData(filepath, "CH2_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch2sprectrumValue, ch2averagesprectrumValue);
                        CsvData(filepath, "CH3_", csvfilename, qoutdata.averageindex, qoutdata.logtime, FFTdf, ch3sprectrumValue, ch3averagesprectrumValue);

                        if (qoutdata.averageindex == averagetimes)
                        {
                            if (mqtt_client.IsConnected)
                            {
                                WriteChannelData(4);
                            }
                            copyalarmfile(filepath, qoutdata.logtime);
                        }
                    }

                    this.Invoke((MethodInvoker) delegate
                    {
                        if (radioButtonCH0.Checked == true)
                        {
                            easyChartTime.Plot(ch0RawValue);
                            easyChartFFT.Plot(ch0sprectrumValue);
                        }
                        if (radioButtonCH1.Checked == true)
                        {
                            easyChartTime.Plot(ch1RawValue);
                            easyChartFFT.Plot(ch1sprectrumValue);
                        }
                        if (radioButtonCH2.Checked == true)
                        {
                            easyChartTime.Plot(ch2RawValue);
                            easyChartFFT.Plot(ch2sprectrumValue);
                        }
                        if (radioButtonCH3.Checked == true)
                        {
                            easyChartTime.Plot(ch3RawValue);
                            easyChartFFT.Plot(ch3sprectrumValue);
                        }
                        textBox1.Text = myqueue.Count.ToString();
                    });
                }
            }
        }