Bonjour,
Je test l'acquisition d'un signal en utilisant comme support le C#, donc j'arrive à acquirir mon signal
Par la suite je cherche le max de mon signal (amplitude) et l'abssice de ce max
mais je ne voix pas à quel moment je peux acceder aux valeurs du tableau des échantillons, afin d'effectuer ma routine calcul.
en fin je souhaite afficher cette valeur dans un text du form1, donc dois-je utiliser l'héritage ou autre chose...
voilà le code où figure une partie dont on cherche la FFT et pour mon max je doit faire comment
j'éspere que je suis claire et je vous remetci beaucoup....
// Description:
// You can use this DAQmx user
control to perform a continuous N-sample multichannel analog read.
// N is the number of samples per channel configured in the task.
//
// How to use the DAQmx user control on a Windows Form
// 1. Build the project.
// 2. Open the Toolbox and select My User Controls.
// 3. Drop your DAQmx user control on a form.
// 4. Call the Start method to run the task, as shown in the following example:
//
// userControl.Start();
//
// 5. Call the Stop method to end the task, as shown in the following example:
//
// userControl.Stop();
//
// How to use the DAQmx user control programmatically
// 1. Declare an instance of the class in your code without initializing its UI.
// Call its Start
method to run the task, as shown in the following example:
//
// DAQmxControl userControl = new DAQmxControl(false);
// userControl.Start();
//
// 2. Call the Stop method to end the task, as shown in the following example:
//
// userControl.Stop();
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using NationalInstruments.Analysis.Dsp;
namespace Data_Acquisition_in_CSharp
{
public class DAQmxControl : System.Windows.Forms.UserControl
{
public class TaskEventArgs : System.EventArgs
{
double[,] data;
public TaskEventArgs(double[,] d)
{
data = d;
}
public double[,] GetData() { return data; }
}
public delegate void EventHandler(object sender, TaskEventArgs args);
public event EventHandler DataReady;
private Data_Acquisition_in_CSharp.DAQmxTask1 daqmxTask;
private NationalInstruments.DAQmx.AnalogMultiChannelReader daqmxReader;
private System.AsyncCallback dataReadyHandler;
#region Fields
private bool stopped = true;
private NationalInstruments.UI.XAxis xAxis1;
private NationalInstruments.UI.YAxis yAxis1;
private NationalInstruments.UI.WaveformPlot waveformPlot1;
private NationalInstruments.UI.WindowsForms.WaveformGraph waveformGraph1;
private NationalInstruments.UI.WaveformPlot waveformPlot2;
private NationalInstruments.Net.DataSocket dataSocket1;
private NationalInstruments.UI.YAxis yAxis2;
private NationalInstruments.UI.XAxis xAxis2;
private System.ComponentModel.IContainer components = null;
#endregion
#region Constructors/Finalizers
public DAQmxControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
this.DataReady += new EventHandler(this.OnDataReady);
}
public DAQmxControl(bool initializeUI)
{
if(initializeUI)
{
InitializeComponent();
}
this.DataReady += new EventHandler(this.OnDataReady);
CreateTask();
}
public DAQmxControl(IContainer container) : this()
{
container.Add(this);
CreateTask();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
CleanupTask();
}
base.Dispose( disposing );
}
#endregion
private void CreateTask()
{
if(daqmxTask != null)
return;
if(dataReadyHandler == null)
dataReadyHandler = new
System.AsyncCallback(DataReadyHandler);
daqmxTask = new Data_Acquisition_in_CSharp.DAQmxTask1();
daqmxReader =
new
NationalInstruments.DAQmx.AnalogMultiChannelReader(daqmxTask.Stream);
daqmxReader.SynchronizingObject = this;
}
private void CleanupTask()
{
if(daqmxTask != null)
{
Stop();
daqmxTask.Dispose();
}
}
public void Start()
{
if(!stopped)
return;
if(daqmxTask == null)
CreateTask();
daqmxTask.Start();
stopped = false;
daqmxReader.BeginReadMultiSample(100, dataReadyHandler, null);
}
public void Stop()
{
if(this.daqmxTask != null)
this.daqmxTask.Stop();
stopped = true;
}
public void DataReadyHandler(IAsyncResult result)
{
if(stopped)
return;
try
{
double[,] data =
daqmxReader.EndReadMultiSample(result);
DataReady(this, new TaskEventArgs(data));
}
catch(NationalInstruments.DAQmx.DaqException e)
{
MessageBox.Show(e.Message);
}
}
public virtual void OnDataReady(object sender, TaskEventArgs e)
{
double[,] data = e.GetData();
double[] SingleChannel = new double[100];
double[] FFTData = new double[50];
for(int i=0; i<100; i++)
SingleChannel[i] = data[0,i];
Transforms.PowerSpectrum(SingleChannel);
for(int i=0; i<50; i++)
FFTData[i] = SingleChannel[i];
#region Update UI
if(waveformGraph1 != null)
{
waveformGraph1.PlotYMultiple(data);
waveformPlot2.PlotY(FFTData, 0, 10);
}
#endregion
dataSocket1.Data.Value = data;
if(!stopped)
daqmxReader.BeginReadMultiSample(100,
dataReadyHandler, null);
}
#region Methods
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.waveformGraph1 = new
NationalInstruments.UI.WindowsForms.WaveformGraph();
this.waveformPlot1 = new NationalInstruments.UI.WaveformPlot();
this.xAxis1 = new NationalInstruments.UI.XAxis();
this.yAxis1 = new NationalInstruments.UI.YAxis();
this.waveformPlot2 = new NationalInstruments.UI.WaveformPlot();
this.dataSocket1 = new
NationalInstruments.Net.DataSocket(this.components);
this.yAxis2 = new NationalInstruments.UI.YAxis();
this.xAxis2 = new NationalInstruments.UI.XAxis();
((System.ComponentModel.ISupportInitialize)(this.waveformGraph1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSocket1)).BeginInit();
this.SuspendLayout();
//
// waveformGraph1
//
this.waveformGraph1.Dock = System.Windows.Forms.DockStyle.Fill;
this.waveformGraph1.Location = new System.Drawing.Point(0, 0);
this.waveformGraph1.Name = "waveformGraph1";
this.waveformGraph1.Plots.AddRange(new
NationalInstruments.UI.WaveformPlot[] {
this.waveformPlot1,
this.waveformPlot2});
this.waveformGraph1.Size = new System.Drawing.Size(192, 168);
this.waveformGraph1.TabIndex = 0;
this.waveformGraph1.XAxes.AddRange(new NationalInstruments.UI.XAxis[] {
this.xAxis1,
this.xAxis2});
this.waveformGraph1.YAxes.AddRange(new NationalInstruments.UI.YAxis[] {
this.yAxis1,
this.yAxis2});
//
// waveformPlot1
//
this.waveformPlot1.XAxis = this.xAxis1;
this.waveformPlot1.YAxis = this.yAxis1;
//
// xAxis1
//
this.xAxis1.Caption = "# of Samples/Frequency";
//
// waveformPlot2
//
this.waveformPlot2.LineColor = System.Drawing.Color.Red;
this.waveformPlot2.XAxis = this.xAxis2;
this.waveformPlot2.YAxis = this.yAxis2;
//
// dataSocket1
//
this.dataSocket1.AccessMode =
NationalInstruments.Net.AccessMode.WriteAutoUpdate;
this.dataSocket1.SynchronizingObject = this;
this.dataSocket1.Url = "dstp://localhost/data";
//
// yAxis2
//
this.yAxis2.Visible = false;
//
// xAxis2
//
this.xAxis2.Mode = NationalInstruments.UI.AxisMode.Fixed;
this.xAxis2.Range = new NationalInstruments.UI.Range(0, 100);
this.xAxis2.Visible = false;
//
// DAQmxControl
//
this.Controls.Add(this.waveformGraph1);
this.Name = "DAQmxControl";
this.Size = new System.Drawing.Size(192, 168);
((System.ComponentModel.ISupportInitialize)(this.waveformGraph1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSocket1)).EndInit();
this.ResumeLayout(false);
}
#endregion
}
}
RED1

