Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

2D Array into a Waveform Graph

I am working in Visual Studio Visual Basic 2005.
I have the Measurement Studio add-in.
I have a serial port collecting data and I am writing the data into an array.
Each time I get data I pump it in to an array dimensioned as ReDim arrData1(0 To 47, 0 To 10).
I have dropped a Waveform Graph on a form.
I want to continuously append the graph with the array.
The array is generated about every second.
The 0 to 47 represents 48 rows of data.
0 to 10 represents a TimerTick, a Second time-stamp, a Nano-second time-stamp and 8 channels of data.
I want to point the TimerTick at the X axis as a time incrementer; the TimerTick intervals are not always the same.
I want to point the 8 channels at the Y axis and plot 8 separate lines in the graph.
I have experimented with .PlotYAppendMultiple where I send in my 2D array; it plots but I don't see how i can break out the time and the data to point it at the correct axis.
I have experimented with .PlotYAppend and I see how I could make it work in a very laborious fashion if I pick apart the array element by element.
Is there a better way? I can refashion my array.
Thanks.
 
 
 
 
0 Kudos
Message 1 of 4
(3,677 Views)

Hi VBRules,

I am a little unclear of what you are wanting to display on your graph. Are you trying to display data against time? Was the data acquired at some regular time interval?  There is two examples that come to my mind that may be of some use to you.  I would take a look at the PlotWaveforms and the PlotDateTime example (maybe others in the Graph directory).  These examples are located in Documents and Settings\All Users\Documents\National Instruments\MStudioVS2005\DotNET\Examples\WindowsForms\Graph.  

You also might want to look at the different overloads for the PlotYAppendMultple and PlotYAppend which take in some timing information (i.e. some take a start time and increment value). You could also look at the PlotWaveformAppend method which plots a AnalogWaveform<TData> type. The PlotWaveforms example shows how to appropriately set up timing information and use that to plot against your data.

Look over these examples and the help and see if that helps!

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 2 of 4
(3,642 Views)

Jonathan:

Thanks so much for the quick response. Your suggestions were very helpful. Here's how I accomplished my goal:

I have an application that  samples the serial port every 100ms (timer function) and sucks any bytes out into a byte array. The array is passed to a parsing function that finds data packets, does checksum, puts the finished data into an array (arrData1(0 to 47, 0 to 10), graphs the data and writes the data to a file. The data array has 0 to 47 rows of data with 0 to 10 datapoints per row. The datapoints are laid out in this order, starting with 0: TimerTick, Seconds, NanoSeconds, Channel 1 data, CH2 data, CH3 data, CH4 data, CH5 data, CH6 data, CH7 data, CH8 data. My problem was trying to figure out how to point the data array at a waveform graph. Here's the code that i came up with which works wonderfully:

Private

Function GraphData()

'dim

Dim X As Integer

Dim MySampleInterval As Double

Dim MyIncrementedTimeStamp As Double

'set sample interval

MySampleInterval = GetSampleRate(MySampleRate)

'set inital value

MyIncrementedTimeStamp = My64BitTimeStampInSeconds + (My64BitTimeStampInNanos / 1000000000)

'determine which graph gets which array

If NodeAddress1 = MyNodeAddress Then

'GraphWireless1

For X = 0 To NumberOfRows - 1

Wireless1CH1.PlotYAppend(arrData1(X, 3), MyIncrementedTimeStamp)

Wireless1CH2.PlotYAppend(arrData1(X, 4), MyIncrementedTimeStamp)

Wireless1CH3.PlotYAppend(arrData1(X, 5), MyIncrementedTimeStamp)

Wireless1CH4.PlotYAppend(arrData1(X, 6), MyIncrementedTimeStamp)

Wireless1CH5.PlotYAppend(arrData1(X, 7), MyIncrementedTimeStamp)

Wireless1CH6.PlotYAppend(arrData1(X, 8), MyIncrementedTimeStamp)

Wireless1CH7.PlotYAppend(arrData1(X, 9), MyIncrementedTimeStamp)

Wireless1CH8.PlotYAppend(arrData1(X, 10), MyIncrementedTimeStamp)

'increment time stamp

MyIncrementedTimeStamp = MyIncrementedTimeStamp + MySampleInterval

Next X

ElseIf NodeAddress2 = MyNodeAddress Then

'GraphWireless2

For X = 0 To NumberOfRows - 1

Wireless2CH1.PlotYAppend(arrData2(X, 3), MyIncrementedTimeStamp)

Wireless2CH2.PlotYAppend(arrData2(X, 4), MyIncrementedTimeStamp)

Wireless2CH3.PlotYAppend(arrData2(X, 5), MyIncrementedTimeStamp)

Wireless2CH4.PlotYAppend(arrData2(X, 6), MyIncrementedTimeStamp)

Wireless2CH5.PlotYAppend(arrData2(X, 7), MyIncrementedTimeStamp)

Wireless2CH6.PlotYAppend(arrData2(X, 8), MyIncrementedTimeStamp)

Wireless2CH7.PlotYAppend(arrData2(X, 9), MyIncrementedTimeStamp)

Wireless2CH8.PlotYAppend(arrData2(X, 10), MyIncrementedTimeStamp)

'increment time stamp

MyIncrementedTimeStamp = MyIncrementedTimeStamp + MySampleInterval

Next X

ElseIf NodeAddress3 = MyNodeAddress Then

'GraphWireless3

For X = 0 To NumberOfRows - 1

Wireless3CH1.PlotYAppend(arrData3(X, 3), MyIncrementedTimeStamp)

Wireless3CH2.PlotYAppend(arrData3(X, 4), MyIncrementedTimeStamp)

Wireless3CH3.PlotYAppend(arrData3(X, 5), MyIncrementedTimeStamp)

Wireless3CH4.PlotYAppend(arrData3(X, 6), MyIncrementedTimeStamp)

Wireless3CH5.PlotYAppend(arrData3(X, 7), MyIncrementedTimeStamp)

Wireless3CH6.PlotYAppend(arrData3(X, 8), MyIncrementedTimeStamp)

Wireless3CH7.PlotYAppend(arrData3(X, 9), MyIncrementedTimeStamp)

Wireless3CH8.PlotYAppend(arrData3(X, 10), MyIncrementedTimeStamp)

'increment time stamp

MyIncrementedTimeStamp = MyIncrementedTimeStamp + MySampleInterval

Next X

Else

'event

Call EventLog("Node Address " + Trim(Str(MyNodeAddress)) + " isn't recognized by GraphData function")

End If

End Function

If you look carefully at this code you will see that I am not using the datapoints 0, 1 and 2 in my data array to timestamp the data (for the X axis). Earlier in my parsing I create the timestamp info as public variables and use them in the graph function. I could just as well be using 0, 1 and 2 to drive the time on the X axis and a good coder would do just that; I didn't see that method until after I got the Y data plotting. In the future that is the way I will do it. I am new to Visual Studio so my mind is working on that curve; I have used Measurement Studio in VB6 for years with great satisfaction. This first .Net Measurement Studio work for me clicked right into place after I did the proverbial start-up struggle. I love Measurement Studio!

Barry

 

0 Kudos
Message 3 of 4
(3,630 Views)
That's great Barry. I'm glad you enjoy working with Measurement Studio. 

Good luck with future projects!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 4
(3,628 Views)