07-16-2015 11:30 AM
//Initialize component
this.waveformGraph.Caption = "Oscilloscope";
this.waveformGraph.Location = new System.Drawing.Point(119, 21);
this.waveformGraph.Name = "waveformGraph";
this.waveformGraph.Plots.AddRange(new NationalInstruments.UI.WaveformPlot[] {
this.waveformPlot});
this.waveformGraph.Size = new System.Drawing.Size(505, 227);
this.waveformGraph.TabIndex = 0;
this.waveformGraph.XAxes.AddRange(new NationalInstruments.UI.XAxis[] {
this.xAxis});
this.waveformGraph.YAxes.AddRange(new NationalInstruments.UI.YAxis[] {
this.yAxis});
// waveformPlot
this.waveformPlot.DefaultWaveformPlotOptions = new NationalInstruments.UI.AnalogWaveformPlotOptions(NationalInstruments.UI.AnalogWaveformPlotDisplayMode.Samples, NationalInstruments.UI.AnalogWaveformPlotScaleMode.Raw, NationalInstruments.UI.AnalogWaveformPlotTimingMode.Auto);
this.waveformPlot.PointStyle = NationalInstruments.UI.PointStyle.SolidTriangleRight;
07-16-2015 03:24 PM
Hi, Priyanka
Thank you for posting the code. I'm taking a look at it now. I also noticed that you opened a stack overflow question, and I have a question about that code. In the question you posted the following:
static void PlotWaveformsOnGraph(AnalogWaveformCollection<double> waveforms)
{
List<AnalogWaveform<double>> waveformList = new List<AnalogWaveform<double>>(waveforms);
MainWindow main = new MainWindow();
main.waveformGraph.PlotWaveforms(waveformList.ToArray());
}
Is there a reason you are creating a new window in the PlotWaveformsOnGraph method? Do you eventually show the window using Application.Run?
Is your project WPF or Windows Forms? Up until this point, I was working under the assumption that you were using Windows Forms because of the classes you were using and the title of your thread. I apologize for not verifying this earlier.
07-16-2015 03:34 PM
Hi Daniel,
I posted this before even I could get the example code of Measurement studio. Since then , the latest code is the code I posted in last message and I am working on that.
I am using Windows Forms and sorry for the confusion about the new Window. The code you see is in a different class called NiScope , so I am creating object of my main window to plot the graph as I have my WaveformGraph on it. In short - from class NiScope I am accessing the objects of my main window.
07-16-2015 04:09 PM
Hi Priyanka
Thanks for explaining that a bit more. Let's try a different approach here. I have modified one of the shipping examples to demonstrate plotting on the waveform, and I attached it to this post. I have pasted some code here for convenience as well. If your application structure is significantly different than this example, please let me know.
public partial class MainForm : Form
{
NIScope scopeSession;
public MainForm()
{
InitializeComponent();
LoadScopeDeviceNames();
ChangeControlState(true);
}
// ...
void LoadScopeDeviceNames()
{
using (ModularInstrumentsSystem scopeDevices = new ModularInstrumentsSystem("NI-Scope"))
{
foreach (DeviceInfo device in scopeDevices.DeviceCollection)
{
resourceNameComboBox.Items.Add(device.Name);
}
}
if (resourceNameComboBox.Items.Count > 0)
{
resourceNameComboBox.SelectedIndex = 0;
}
}
// ...
void acquireButton_Click(object sender, EventArgs e)
{
StartAcquisition();
}
void InitializeSession()
{
scopeSession = new NIScope(ResourceName, false, false);
scopeSession.DriverOperation.Warning += new EventHandler<ScopeWarningEventArgs>(DriverOperation_Warning);
}
void StartAcquisition()
{
ChangeControlState(false);
PrecisionTimeSpan timeout = new PrecisionTimeSpan(5.0);
AnalogWaveformCollection<double> waveforms = null;
try
{
InitializeSession();
scopeSession.Measurement.AutoSetup();
long recordLength = scopeSession.Acquisition.RecordLength;
double sampleRate = scopeSession.Acquisition.SampleRate;
waveforms = scopeSession.Channels[ChannelName].Measurement.Read(timeout, recordLength, waveforms);
DisplayResults(recordLength, sampleRate);
PlotWaveforms(sampledDataGridView, waveforms);
}
catch (Exception ex)
{
ShowError(ex);
}
finally
{
CloseSession();
ChangeControlState(true);
}
}
// ...
void PlotWaveforms(DataGridView dgv, AnalogWaveformCollection<double> waveforms)
{
var waveformsList = new List<AnalogWaveform<double>>(waveforms);
this.waveformGraph.PlotWaveformsAppend(waveformsList.ToArray());
}
// ...
}
I added ellipses where I cut out code. I tested this code with a simulated 5122, and I was able to plot waveforms.
07-16-2015 04:42 PM
Thank you so much Daniel.
It was not working since I was trying to create object of the main window and plot it. When I moved the code to Main window's code, it works perfectly fine now 🙂
07-16-2015 04:58 PM
I'm glad to help
Good luck!