/// <summary> /// 每隔10ms刷新用户界面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; samplesToPreview = int.Parse(textBox_previewSamples.Text); double length = 0; bool recordDone = false; //步骤5:获取流盘状态,包括已流盘长度和流盘是否结束标志位 dstask.GetRecordStatus(out length, out recordDone); if (recordDone) { //流盘已结束 buttonStop_Click(null, null); progressBar1.Value = progressBar1.Maximum; } else { //步骤6:流盘仍在进行中,预览最新流盘数据并显示 dstask.ReadLatestData(ref priewData); ArrayManipulation.Transpose(priewData, ref transposedData); easyChart_signal.Plot(transposedData); for (int i = 0; i < channelNumbers.Count; i++) { ArrayManipulation.GetArraySubset(transposedData, i, ref singleChannelPriewData, ArrayManipulation.IndexType.row); Spectrum.PowerSpectrum(singleChannelPriewData, double.Parse(textBox_sampleRate.Text), ref singleChannelSpectrumData, out spectrumInterval[i], SpectrumUnits.V2); ArrayManipulation.ReplaceArraySubset(singleChannelSpectrumData, ref previewSpectrumBufferTransposed, i, ArrayManipulation.IndexType.row); } easyChart_spectrum.Plot(previewSpectrumBufferTransposed, 0, spectrumInterval[0]); progressBar1.Value = (int)(length / double.Parse(textBox_recordLength.Text) * progressBar1.Maximum); timer1.Enabled = true; } }
public void Start() { if (null == tableLayoutPanel_waveConfig.Controls[0]) { return; } double sampleRate = (double)numericUpDown_sampleRate.Value; Generator waveGenerator = tableLayoutPanel_waveConfig.Controls[0] as Generator; AITask.AITask input = _globalInfo.AITask; AOTask.AOTask output = _globalInfo.AOTask; output.SetUpdateRate(sampleRate); input.SetSampleRate(sampleRate); double channelRange = waveGenerator.GetAmplitude(); output.AddChannel(comboBox_aoChannel.SelectedIndex, -1 * channelRange, channelRange); input.AddChannel(comboBox_refChannel.SelectedIndex, -1 * channelRange, channelRange); input.AddChannel(comboBox_testChannel.SelectedIndex, -1 * channelRange, channelRange); double[] outData = waveGenerator.Generate(); output.SetSamplesToUpdate(outData.Length); double outTime = outData.Length / output.GetUpdateRate(); input.SetSamplesToAcquire((int)(outTime * input.GetSampleRate() * GlobalInfo.ExtraReadTime)); output.WriteData(outData, -1); input.Start(); output.Start(); double[,] readWaveform = new double[input.GetSamplesToAcquire(), 2]; input.ReadData(ref readWaveform, readWaveform.GetLength(0), GlobalInfo.ReadTimeOut); double[,] plotData = new double[readWaveform.GetLength(1), readWaveform.GetLength(0)]; ArrayManipulation.Transpose(readWaveform, ref plotData); // easyChart_data.Plot(plotData); _globalInfo.Mainform.Invoke(new Action <double[, ], double, double>(easyChart_data.Plot), plotData, 0, 1); _refData = new double[plotData.GetLength(1)]; _testData = new double[plotData.GetLength(1)]; Buffer.BlockCopy(plotData, 0, _refData, 0, _refData.Length * sizeof(double)); Buffer.BlockCopy(plotData, _testData.Length * sizeof(double), _testData, 0, _testData.Length * sizeof(double)); double[] spectrum = new double[_testData.Length / 2]; double df; Spectrum.PowerSpectrum(_testData, input.GetSampleRate(), ref spectrum, out df); // easyChart_spectrum.Plot(spectrum.Take(1000).ToArray(), 0, df); _globalInfo.Mainform.Invoke(new Action <double[], double, double>(easyChart_spectrum.Plot), spectrum, 0, df); _analyzeSize = (uint)Math.Ceiling(outTime * _globalInfo.AITask.GetSampleRate()); }
/// <summary> /// 定时器,每秒钟刷新一次 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { try { //如果本地缓冲区数据足够则读取数据并显示,如果不够,返回 if (aitask.AvailableSamples < readValue.Length) { return; } timer1.Enabled = false; aitask.ReadData(ref readValue, -1); toolStripStatusLabel.Text = "正在读取数据中..."; ArrayManipulation.Transpose(readValue, ref displayValue); int size = displayValue.Length / 3; double[] buf1 = new double[size]; double[] buf2 = new double[size]; double[] buf3 = new double[size]; Buffer.BlockCopy(displayValue, 0, buf1, 0, size * sizeof(double)); Buffer.BlockCopy(displayValue, size * sizeof(double), buf2, 0, size * sizeof(double)); Buffer.BlockCopy(displayValue, size * sizeof(double), buf3, 0, size * sizeof(double)); stripChart_position.Plot(_displacementsensor.Convert(buf2)); //stripChart_position.Plot(Conversion.resistance(buf2, RMax, 10, "cm")); //stripChart_weight.Plot(Conversion.Weight(buf1, 12, 250, 2000, 350, 500, "kg")); stripChart_weight.Plot(_loadCell.Convert(buf1)); stripChart1.Plot(_thermistor.Convert(buf3)); timer1.Enabled = true; } catch (JYDriverException ex) { if (ex.ErrorCode == -2 || ex.ErrorCode == -4 || ex.ErrorCode == -304) { led1.Value = false; button1.Enabled = true; } else { MessageBox.Show(ex.Message); } } catch (Exception ex) { aitask?.Stop(); Start.Enabled = true; toolStripStatusLabel.Text = "读取数据失败"; MessageBox.Show(ex.Message); } }
private void timer_measure_Tick(object sender, EventArgs e) { timer_measure.Enabled = false; if (dataAvailable) { MathEngineHandler.WfmSubset(readData, device.SelectedChannels.ToList(), (double)numericUpDown_sampleRate.Value); ArrayManipulation.Transpose(readData, ref displayData); MathEngineHandler.Process(); if (spectrumMode) { for (int i = 0; i < readData.GetLength(1); i++) { ArrayManipulation.GetArraySubset(readData, i, ref tempData, ArrayManipulation.IndexType.column); Spectrum.PowerSpectrum(tempData, _sampleRate, ref tempSpecData, out df); ArrayManipulation.ReplaceArraySubset(tempSpecData, ref displayData, i, ArrayManipulation.IndexType.row); } easyChart1.Plot(displayData, 0, df); } else { if (checkBox_timeDisplay.Checked) { easyChart1.Plot(displayData, 0, 1.0 / (double)numericUpDown_sampleRate.Value); } else { easyChart1.Plot(displayData); } } easyChart1.SeriesNames = _seriesDefaultNames; easyChart1.SeriesNames = _chNames.ToArray(); dgv_mathEngine.Invalidate(); if (isSingleRun) { easyButton_stop_Click(null, null); } else { device.Stop(); easyButton_contStart_Click(null, null); } } else { timer_measure.Enabled = true; } }
public void Start() { if (null == tableLayoutPanel_waveConfig.Controls[0]) { return; } double sampleRate = (double)numericUpDown_sampleRate.Value; Generator waveGenerator = tableLayoutPanel_waveConfig.Controls[0] as Generator; dataGridView_result.Rows.Clear(); AITask.AITask input = _globalInfo.AITask; AOTask.AOTask output = _globalInfo.AOTask; output.SetUpdateRate(sampleRate); input.SetSampleRate(sampleRate); double channelRange = waveGenerator.GetAmplitude(); output.AddChannel(comboBox_aoChannel.SelectedIndex, -1 * channelRange, channelRange); input.AddChannel(comboBox_refChannel.SelectedIndex, -1 * channelRange, channelRange); input.AddChannel(comboBox_testChannel.SelectedIndex, -1 * channelRange, channelRange); double[] outData = waveGenerator.Generate(); output.SetSamplesToUpdate(outData.Length); double outTime = outData.Length / output.GetUpdateRate(); input.SetSamplesToAcquire((int)(outTime * input.GetSampleRate() * GlobalInfo.ExtraReadTime)); output.WriteData(outData, -1); input.Start(); output.Start(); double[,] readWaveform = new double[input.GetSamplesToAcquire(), 2]; input.ReadData(ref readWaveform, readWaveform.GetLength(0), GlobalInfo.ReadTimeOut); double[,] plotData = new double[readWaveform.GetLength(1), readWaveform.GetLength(0)]; ArrayManipulation.Transpose(readWaveform, ref plotData); _globalInfo.Mainform.Invoke(new Action <double[, ], double, double>(easyChart_waveform.Plot), plotData, 0, 1); _testData = new double[plotData.GetLength(1)]; Buffer.BlockCopy(plotData, 0, _testData, 0, _testData.Length * sizeof(double)); _refWaveform = waveGenerator.GetRefWaveform() as SteppedLevelSineWaveform; // double[] peakToPeak, thd, nr, thdPlusNr, rms; // SeeSharpTools.JY.Audio.AudioAnalyzer.AnalyzeSteppedLevelSineWaveform(testWaveData, refWaveform, // out peakToPeak, out thd, out nr, out thdPlusNr, out rms); _analyzeSize = _refWaveform.GetTotalPoints(); }
// 设置定时器 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; if (mutilAiTask.AvailableSamples >= readValue.Length) { try { mutilAiTask.ReadData(ref readValue, -1); toolStripStatusLabel.Text = "数据读取中..."; } catch (JYDriverException ex) { timer1.Enabled = true; toolStripStatusLabel.Text = "数据读取错误"; MessageBox.Show(ex.Message); } // 绘制图像 ArrayManipulation.Transpose(readValue, ref displayValue); easyChart_wave.Plot(displayValue); } timer1.Enabled = true; }
public virtual void Transpose <T>(T[,] src, ref T[,] dest) { ArrayManipulation.Transpose(src, ref dest); }