|
|
Rank: Newbie Groups: Member
Joined: 1/24/2011 Posts: 4 Location: Delfzijl
|
I am working on a emergency overview display (gas, fire, weather) and I am trying to show the wind direction with an arrow. In a DCS display I have (mis)used a dial symbol but in PB I have yet to find something I can use. Alternatively I could put the tag value in the "Rotation" property of a line to show the direction. Is there some snippet of code I could use as basis? It would have to update continuously. tia, Peter
|
|
|
|
|
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.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
Hello and welcome to the forum. Take a look at this thread where there is an example of using a "Line" symbol as the wind direction from an updating PI tag (that contains the degree of the direction): Wind DirectionPrincipal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 1/24/2011 Posts: 4 Location: Delfzijl
|
RJK Solutions wrote:Hello and welcome to the forum. Take a look at this thread where there is an example of using a "Line" symbol as the wind direction from an updating PI tag (that contains the degree of the direction): Wind Direction That was exactly what I needed, thanks! Glad I found this forum. VBA is starting to come back to me a bit now... it has been a while. I want the macro to run every couple of seconds so I tried Display_DataUpdate() but that does not seem to work. Calling the Sub with a button gives "Failed to execute OS command Display_DataUpdate". What am I doing wrong? Code:
Private Sub Display_DataUpdate()
Dim MyLine As Line Set MyLine = ThisDisplay.MyLine
Dim D As Value, vTime As Variant, vStat As Variant Set D = ThisDisplay.Value1
With MyLine .Name = "MyLine"
'Changes direction of arrow based on winddir value .Endpoints(1).X = -12000 'left .Endpoints(1).y = 14800 'top .Endpoints(2).X = (-12000) + (Sin(D.GetValue(vTime, vStat) / 180 * 3.14159) * 185) .Endpoints(2).y = 14800 + (Cos(D.GetValue(vTime, vStat) / 180 * 3.14159) * 185) 'set line color and styles .LineColor = pbBlack .LineStyle.Style = 0 .LineStyle.Weight = 2 'add arrow on right. .LineStyle.End = 3 End With
End Sub
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
You are best to run the code when the data for the Symbol housing your wind direction is updated. So the symbol from the code is "Value1" and the event is "DataUpdate". Code: Private Sub Value1_DataUpdate() ' Paste your code in here... End Sub
This is executed each time the symbol is updated from it's DataPoint (PI tag). The "Display_DataUpdate" event typically runs every 5 seconds but depends what refresh rate you have set for the ProcessBook application. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 1/24/2011 Posts: 4 Location: Delfzijl
|
RJK Solutions wrote:You are best to run the code when the data for the Symbol housing your wind direction is updated. So the symbol from the code is "Value1" and the event is "DataUpdate". Code: Private Sub Value1_DataUpdate() ' Paste your code in here... End Sub
This is executed each time the symbol is updated from it's DataPoint (PI tag). The "Display_DataUpdate" event typically runs every 5 seconds but depends what refresh rate you have set for the ProcessBook application. I simplified the code based on you example and it works as intended when I run it as a normal Sub. The call "Private Sub Value1_DataUpdate()" or "Private Sub Display_DataUpdate()" does not work on my machine. Is it possible that the function is blocked somehow? My corporate machine has all kinds of security blocks... Code: Private Sub Value1_DataUpdate()
'Sub Test()
Dim MyLine As Line Set MyLine = ThisDisplay.MyLine
Dim D As Value, vTime As Variant, vStat As Variant Set D = ThisDisplay.Value1 MyLine.Rotation = -(D.GetValue(vTime, vStat))
End Sub
|
|
|
Rank: Newbie Groups: Member
Joined: 1/24/2011 Posts: 4 Location: Delfzijl
|
Figured it out now. The "Value1_DataUpdate()" code needs to be in the ThisDisplay object. I still have a bit to learn about VBA. Thanks for your help.
|
|
|
|
Guest
|