Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Plots

Hey,im currently reading in a continuosly changing voltage and plotting it using CWGraph.However i want to plot the votage aginst time using the Timer function.Any suggestions on how to put together the code to manage this?
Thanks
0 Kudos
Message 1 of 4
(6,295 Views)
First, you need to configure the labels of the axes on the graph to display in date/time format. You can do this by going to the Format tab of the graph's property pages at design-time, then select either Time or Date from the built-in format styles list, then select a format string from the format strings list. If you do not see the format that you want in the list, you can create your own format. For more information, see the documentation for the CWAxis.FormatString property in the Measurement Studio reference.

Next, you need to convert the value that's associated with the axis to a date/time representation before you plot it. This conversion factor is also described in the documentation for the CWAxis.FormatString property in the Measurement Studio reference:

"With ActiveX controls, the date is implemented as a floating-point value, measuring days from midnight, 30 December 1899. So, midnight, 31 December 1899, is represented by 1.0. Similarly, 6 AM, 1 January 1900, is represented by 2.25, and midnight, 29 December 1899, is -1.0. However, 6 AM, 29 December 1899, is -1.25. To interpret the time portion, take the absolute value of the fractional part of the number. Thus, 1 second equals 1 / 24 hours / 60 minutes / 60 seconds, which is 1/86400 or approximately 1.157407e-5."

Once you have the value converted to a date/time representation, you can use the graph's PlotXvsY method to plot the data value against the date/time value.

- Elton
0 Kudos
Message 2 of 4
(6,287 Views)
Option Explicit
Private Sub Start_Click()
If CWButton2.Value Then
CWAI1.StopCondition.Type = cwaiContinuous
Else
CWAI1.StopCondition.Type = cwaiNoActiveCondition
End If

CWAI1.Configure
CWAI1.Start

End Sub
Private Sub Stop_Click()
CWAI1.Stop
CWAI1.Reset
End Sub

Private Sub CWAI1_AcquiredData(ScaledData As Variant, BinaryCodes As Variant)
GenerateData ScaledData
End Sub
Private Sub CWAI1_DAQError(ByVal StatusCode As Long, ByVal ContextID As Long, ByVal ContextDescription As String)
MsgBox "Error: " & StatusCode & vbCrLf & "Context: " & ContextDescription & vbCrLf & CWDAQTools1.GetErrorText(StatusCode)
End Sub
Private Sub CWAI1_DAQWarning(ByVal StatusCode As Long, ByVal ContextID As Long, ByVal ContextDescription As String)
MsgBox "Warning: " & StatusCode & vbCrLf & "Context: " & ContextDescription & vbCrLf & CWDAQTools1.GetErrorText(StatusCode)
End Sub
Private Sub GenerateData(Waveform As Variant)
Const Pts = 1024

Dim Spectrum As Variant
Dim dt As Variant
Dim df As Variant
Dim phase As Variant
Dim Axis As CWAxis

dt = 1 / Pts
CWDSP1.AutoPowerSpectrum Waveform, dt, Spectrum, df

WaveformGraph.Axes(1).Minimum = 0
WaveformGraph.Axes(1).Maximum = Pts - 1
WaveformGraph.Axes.Item(1).FormatString = "hh:nn:ss"
WaveformGraph.ChartY Waveform

End Sub



Private Sub CWButton1_ValueChanged(ByVal Value As Boolean)

If CWButton1.Value Then
Timer1.Enabled = True
If CWButton2.Value Then
CWAI1.StopCondition.Type = cwaiContinuous
Else
CWAI1.StopCondition.Type = cwaiNoActiveCondition
End If

CWAI1.Configure
CWAI1.Start

Else
CWAI1.Stop
Timer1.Enabled = False
End If

End Sub

Private Sub CWButton2_ValueChanged(ByVal Value As Boolean)
If Value Then
CWAI1.StopCondition.Type = cwaiContinuous
Else
CWAI1.StopCondition.Type = cwaiNoActiveCondition
End If

End Sub

Private Sub Quit_Click()
If vbYes = MsgBox("Are you sure you want to quit", vbYesNo, "Quit") Then
End
End If
End Sub
This is my code to date,Elton.I have also made the adjustments in the format section of the Graph.However the x-axis is not incrementing and im merely getting a series of 0:0:0 across the the bottom when the voltage is changing.Does the fact that i have the GenerateData array make a difference?should i have another array for time or should i have a timer in there aswell.Also i have No. of scans to acquire set to 60 and the scans/sec set to 60 also so does this coprrespnd to a read per second?
Any help would be greatly appreicated
Cheers
0 Kudos
Message 3 of 4
(6,276 Views)
You could generate an array for time and call ChartXvsY. If you do this, you will need to be sure to generate the data in the array with the conversion factor as described above. If you have a fixed interval between all of your data points, you can set the CWGraph.DefaultxInc property and not worry about generating the array of time values. If you do this, you will still need to use the conversion factor as described above to generate this value. The problem is that the default value of this property is 1, which is a very small value in terms of time. This is why you're seeing 0:0:0 across the bottom because the time interval is so small, it looks like all of your data points are at the same value.

- Elton
0 Kudos
Message 4 of 4
(6,258 Views)