YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

dundas chart Options · View
najjarja
#1 Posted : Saturday, October 29, 2011 4:34:17 PM
Rank: Member
Groups: Member

Joined: 7/16/2009
Posts: 12
Location: saudi arabia
Can any body take a look at the below code and advice what is wrong with it?

using dundas chart, I've created a form to display mealtime and historical data. it works but it needs improvement in the following:

1- it does not refresh automatically for realtime.
2- time and date are not displayed
3- application freezes during data retrieval more than 7 days.
4-Digital state trend is not working.
5- how to display tag name.



Quote:
Public Class Trend
Dim C As New clsJasim
#Region "Properties ...'"
Public Property StartTime As Date = Date.Now.AddHours(-2)
Public Property EndTime As Date = Date.Now
Private mTagName As String = ""
Public Property TagName As String
Get
Return mTagName
End Get
Set(ByVal value As String)
mTagName = value
PointArr(0) = GetPointFromTag(mTagName)
If Not PointArr(0) Is Nothing Then
Me.lstTag.Items.Add(mTagName)
End If
End Set
End Property

Private PointArr(2) As PISDK.PIPoint

#End Region
#Region "Utility"
Private Function GetPointFromTag(ByVal TagName As String) As PISDK.PIPoint

If Not Connector.IsConnected Then
If Not Connector.Connect Then
Return Nothing
End If
End If
Dim pPoint As PISDK.PIPoint = Connector.myPIServer.PIPoints(TagName)
Return pPoint
End Function
#End Region


'Function AddNewSeries(ByVal strTagName As String) As Dundas.Charting.WinControl.Series
' If Me.TrendChart.Series.Contains(strTagName) Then
' Return Me.TrendChart.Series(strTagName)
' Dim sr As Dundas.Charting.WinControl.Series

' End If
'End Function

Private Sub ckAutoRefresh_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ckAutoRefresh.CheckedChanged
Try
Me.tmRefresh.Enabled = Me.ckAutoRefresh.Checked
Catch ex As Exception

End Try
End Sub

Private Sub tmRefresh_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmRefresh.Tick
Try
Me.dtEndTime.Value = Date.Now
Catch ex As Exception

End Try
End Sub

Private Sub dtStartTime_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtStartTime.ValueChanged
Try
Me.StartTime = Me.dtStartTime.Value
Catch ex As Exception

End Try
End Sub

Private Sub dtEndTime_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEndTime.ValueChanged
Me.EndTime = Me.dtEndTime.Value
End Sub
Private Sub RefreshValues()
Try
Dim IPoint As Integer = 0
Dim Point As Dundas.Charting.WinControl.DataPoint = Nothing
'Dim StrTrend As String = "srTrend"
For IPoint = 0 To 2
If Not PointArr(IPoint) Is Nothing Then
Dim pValues As PISDK.PIValues
If Me.ckEnableEndTime.Checked Then
pValues = PointArr(IPoint).Data.RecordedValues(Me.StartTime, _
Me.EndTime, PISDK.BoundaryTypeConstants.btAuto)
Else
pValues = PointArr(IPoint).Data.RecordedValues(Me.StartTime, _
"*", PISDK.BoundaryTypeConstants.btAuto)
End If
Me.TrendChart.Series(IPoint).Enabled = False
Me.TrendChart.Series(IPoint).Points.Clear()
'Me.TrendChart.Series(IPoint).Enabled = True
'Do More Stuff .............................
For IValue As Integer = 1 To pValues.Count '- 1
If pValues(IValue).IsGood Then
Me.TrendChart.Series(IPoint).Points.AddXY(pValues(IValue).TimeStamp.LocalDate, pValues(IValue).Value)
End If
Next
Me.TrendChart.Series(IPoint).Enabled = True
Else
Me.TrendChart.Series(IPoint).Points.Clear()
Me.TrendChart.Series(IPoint).Enabled = False
End If
Next
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Error")
End Try
End Sub

Private Sub btnAddTag_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTag.Click
Try
Dim IMax As Integer
Dim iVacant As Integer = 0
Dim blnVacant As Boolean = False
If String.IsNullOrEmpty(Me.txTagName.Text) Then
MsgBox("Please Enter Tag Name", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Missing Tag Name")
Return
End If
For IMax = 0 To 2
If PointArr(IMax) Is Nothing Then
blnVacant = True
iVacant = IMax
Exit For
End If
Next
If Not blnVacant Then
MsgBox("Maximum of Three Points is allowed for each trend.", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Not Allowed")
Return
End If

Dim PI As PISDK.PIPoint = GetPointFromTag(Me.txTagName.Text)
If PI Is Nothing Then
MsgBox("Unable To Get PIPoint From Tag (" & Me.txTagName.Text & ") , Please Make Sure Tag Exisest.", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "No Tag")
Return
End If
If PointArr.Contains(PI) Then
MsgBox("Tag Name (" & Me.txTagName.Text & ") Already exisest!!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Dublicate")
Return
End If
PointArr(iVacant) = PI
Me.lstTag.Items.Add(Me.txTagName.Text)
Catch ex As Exception

End Try
End Sub

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
If Me.lstTag.Items.Count > 0 Then
If Me.lstTag.SelectedIndex <> -1 Then
Dim Idx As Integer = (Me.lstTag.SelectedIndex)
Dim strText As String = Me.lstTag.Items(Idx)
Dim iRes As MsgBoxResult = MsgBox("Are you sure you want to remove item " & strText & " Tag?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Remove Tag")
If iRes = MsgBoxResult.Yes Then
PointArr(Idx) = Nothing
Me.lstTag.Items.RemoveAt(Me.lstTag.SelectedIndex)
End If

End If
End If

End Sub

Private Sub Trend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
C.DataForm = Me ' Very Important
C.EnableTimer = True ' To Enable Or Disable Timer ...
C.Interval = 1000 'Control Refresh Interval Each 1000 Equals 1 Second.
C.ReadData()


Try
If Not String.IsNullOrEmpty(Me.Tag) Then
Me.Text = "Trend For '" & Me.Tag & "'"
Me.dtStartTime.Value = Me.StartTime
Me.dtEndTime.Value = Me.EndTime
End If
'If Not String.IsNullOrEmpty(Me.Tag) Then
' Me.Text = "Trend For '" & Me.Tag & "'"
'End If

If Not PointArr(0) Is Nothing Then
Me.RefreshValues()
End If
Catch ex As Exception

End Try
End Sub

Private Sub ckEnableEndTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ckEnableEndTime.CheckedChanged
Try
Me.dtEndTime.Enabled = (Me.ckEnableEndTime.Checked)
Catch ex As Exception

End Try
End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
Try
Me.RefreshValues()
Catch ex As Exception

End Try
End Sub

End Class
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.