From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-08-2015 07:39 PM
Hi Everyone,
I have list of values of type AnalogWaveformCollection<double> and I wish to plot these values onto a graph. According to some sources from the website I used the following method inorder to do but I get an error which says : Type arguments cannot be inferred from the usage. Try specifying them explicitly.
Here is the code:
void StartAcquisition()
{
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);
//waveformGraph1.PlotWaveforms(waveforms); // error
}
Can anyone please help ?
Regards,
Priyanka
Solved! Go to Solution.
07-09-2015 03:36 PM
07-09-2015 05:00 PM
Hi, Priyanka
Can you help us understand your code better? As far as I understand, your code should not work for a different reason: PlotWaveforms expects an array of AnalogWaveform<T> objects, and you're providing it with an AnalogWaveformCollection<T>. I wrote a quick snippet to illustrate my point better:
// Can be plotted using PlotWaveform(s). var singleWaveform = AnalogWaveform<double>.FromArray1D(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0 }); var waveformArray = new AnalogWaveform<double>[] { singleWaveform, singleWaveform }; // Cannot be plotted using PlotWaveform(s). var waveformCollection = new AnalogWaveformCollection<double>(); _waveformGraph.PlotWaveform<double>(singleWaveform); _waveformGraph.PlotWaveforms<double>(waveformArray); // This shouldn't work because PlotWaveforms expects an array of AnalogWaveform<T> objects. // _waveformGraph.PlotWaveforms<double>(waveformCollection);
Can you post an image of the exception you're seeing?
Thanks
07-13-2015 01:44 PM
Hi,
Thank you Daniel. As per your suggestion, I have made sure that I plot AnalogWaveform<double> data. Here is the error free code:
static void PlotWaveformsOnGraph(AnalogWaveformCollection<double> waveforms)
{
AnalogWaveform<double> SampledWaves = null ;
double[] waves = new double[waveforms[0].SampleCount];
int count = 0;
for (int row = 0; row < waveforms[0].SampleCount; row++)
{
foreach (AnalogWaveform<double> waveform in waveforms)
{
waves[count] = waveform.Samples[row].Value;
count++;
}
}
MainWindow main = new MainWindow();
SampledWaves = AnalogWaveform<double>.FromArray1D(waves);
main.waveformGraph.PlotWaveform<double>(SampledWaves);
}
But , even after successful execution, I do not see the Waveform plotted on the graph. The graph is empty without any waves. What could be the reason.? Any suggestions?
07-13-2015 09:10 PM
Hi, Priyanka
I think you can do what you are trying to do in a simpler way. Please see the following snippet:
void PlotWaveformsOnGraph(AnalogWaveformCollection<double> waveforms) { List<AnalogWaveform<double>> waveformsList = new List<AnalogWaveform<double>>(waveforms); waveformGraph.PlotWaveforms(waveformsList.ToArray()); }
07-14-2015 12:58 PM
Awesome !! thank you for making it compact. But I still don see the graph on screen. Ideally when I click on "Start Analysis" Button, the waveform should appear in the area. Please refer to the screenshot attached with this message. I really appreciate your time and inputs. Please help me with this.
07-14-2015 01:44 PM
07-14-2015 03:52 PM
Yes, Daniel. I also verified it by printing the values onto the console and I did get the values :
List<AnalogWaveform<double>> waveformList = new List <AnalogWaveform<double>>(waveforms);
MainWindow main = new MainWindow();
main.waveformGraph.PlotWaveforms(waveformList.ToArray());
for (int row = 0; row < waveforms[0].SampleCount; row++)
{
foreach (AnalogWaveform<double> wave in waveformList)
{
Console.WriteLine("samplessss"+wave.Samples[row].Value.ToString());
}
}
output:
samplessss---->1.48847971245414
samplessss---->1.49389002792304
samplessss---->1.49253744905582
samplessss---->1.4918611596222
samplessss---->1.49118487018859
samplessss---->1.48780342302052
samplessss---->1.4864508441533
samplessss---->1.49118487018859
samplessss---->1.49389002792304
samplessss---->1.48847971245414
samplessss---->1.48983229132136
samplessss---->1.48983229132136
samplessss---->-1.51627424109029
samplessss---->-1.51221650448861
samplessss---->-1.50612989958609
samplessss---->-1.50951134675415
samplessss---->-1.51086392562138
samplessss---->-1.51356908335583
samplessss---->-1.51289279392222
samplessss---->-1.51356908335583
samplessss---->-1.51221650448861
samplessss---->-1.51289279392222
samplessss---->-1.51018763618777
samplessss---->-1.51356908335583
n so on......
I don't know why its not plotting it on the graph.
07-14-2015 08:00 PM
07-16-2015 11:26 AM
Yes Daniel,
//some code
sampledWaves.ScaleMode = WaveformScaleMode.CreateLinearMode(2, 0);
main.xAxis.MajorDivisions.LabelFormat = new FormatString(FormatStringMode.Numeric, "G5");
sampledWaves.Timing = WaveformTiming.CreateWithRegularInterval(main.waveformPlot.DefaultTiming.SampleInterval);
main.waveformGraph.PlotWaveform(sampledWaves, plotOptions);
-------------
public AnalogWaveformPlotOptions initialPlotConfiguration(){
plotOptions = new AnalogWaveformPlotOptions(AnalogWaveformPlotDisplayMode.Samples, AnalogWaveformPlotScaleMode.Raw);
return plotOptions;
}
public AnalogWaveform<double> PlotWaveform(AnalogWaveformCollection<double> waveforms)
{
double[] waves = new double[waveforms[0].SampleCount];int count = 0;
for (int row = 0; row < waveforms[0].SampleCount; row++)
{
foreach (AnalogWaveform<double> waveform in waveforms)
{
waves[count] = waveform.Samples[row].Value;
count++;
}}
AnalogWaveform<double> SampledWaves = AnalogWaveform<double>.FromArray1D(waves);
SampledWaves.ScaleMode = WaveformScaleMode.CreateLinearMode(2, 0);
return SampledWaves;
}