Hello and welcome to a new guide on how to best use Movicon.NExT™.
In this technote, we are going to create an example to show you how to add and change a pen in the Realtime Trend object using a script.
In this example we shall define three tags to link to the Demo driver
offered by the Movicon.NExT platform.
These three tags will be added to the trends using a script associated
with a button.
Each trend will have their own screen with buttons and Display objects
to display the tag’s value in realtime.
After having started up the Movicon.NExT editor and created, or loaded, a project, insert the Demo driver by following these steps below:
Now that the driver has been added, we shall proceed with creating the tags that will be needed for simulation purposes:
Name | Counter |
Model Type | Variable |
Data Type | Int32 |
Once the Counter tag has been created, create another two tags and configure them in this way:
Name | Random |
Model Tyoe | Variable |
Data Type | Int32 |
Demo Tyoe | Random |
Minimum Value | 0 |
Maximum Value | 100 |
Station | Station0 |
Name | Triangle |
Model Type | Variable |
Data Type | Int32 |
Demo Type | Triangular Wave/Up Down Counter |
Minimum Value | 0 |
Maximum Value | 100 |
Delta | 1 |
Station | Station0 |
When you have finished configuring the tags, click on the Save All icon located on the Movicon.NExT editor’s toolbar at the top to save the project.
Now that the driver and tags have been instantiated, we can go ahead and define the Data Logger to assign the tags to. To do this, open the I/O Data Server:
Name | DL_1sec |
Recording Frequency | 0 (Days) 00:00:01:000 |
Assign the Counter, Random and Triangle tags to the Data Logger you have just created:
Now, we will need to create a screen:
Once the screen has been created, you can then change the project's properties by inserting the screen as the project's Main screen which will show when the project starts up. To do this:
Once you have finished configuring the project startup page, click on the Save All icon located on the toolbar at the top to save the project.
Now, open the Main screen and click on the Toolbox tab, which is
located on the far right of the editor window, next to the properties
window, to open the Toolbox library provided by Movicon.NExT.
Drag three Display objects, three Standard Metro Style buttons, and
a RealTime Trend object on screen. These are found in the Display,
Buttons/Standard and Trends folders, respectively.
Assign the Counter tag to one of the Display objects in this way:
Repeat this procedure to assign the Random and Triangle tags to the other two object.
Click on the Save All icon located on the Movicon.NExT editor’s toolbar at the top to save the project.
At this point, we can configure one of the buttons by changing its
Text property with the Set Counter as Pen string.
Once you have entered this string, confirm the change, and make sure
the button is still selected and open the Script tab. Once the Script
tab opens, insert the reference to TrendRealTimeSlim.dll. To do this:
Now that the reference to the RealTime Trend’s dll has been inserted,
copy and paste the following script in the button:
'#Language
"WWB.NET"
'This script use reference: <Movicon.NExT Folder>\Toolbox\TrendRealTimeSlim.dll
'Script to insert into a button
Public Sub Control_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Handles Control.Click
Dim myInterval As System.TimeSpan
Dim fElement As System.Windows.FrameworkElement
Dim rtControl As TrendRealTimeSlim.RealTimeTrendControl
Dim newPen As TrendRealTimeSlim.PenItem
Dim tagName As String
Dim penName As String
Dim penType As Integer
Dim myScaleMin As Double
Dim myScaleMax As Double
Dim i As Integer
Try
fElement = Document.MapScreenEntities("RTTrendControl").Element
rtControl = TryCast(fElement,
TrendRealTimeSlim.RealTimeTrendControl)
'remove all pens
from the Trend
If rtControl.GetPensNumber
> 0 Then
For i = 0 To
rtControl.GetPensNumber
rtControl.RemovePen(i)
DoEvents
Next
End If
'Initializing pen
If Not IsNothing(rtControl) Then
tagName = "Counter"
penName = "Counter"
penType = 1
myScaleMin =
-1
myScaleMax =
101
End If
'Add new pen
newPen = rtControl.AddPen(penName, tagName,
System.Windows.Media.Color.FromRgb(255,0,0), myScaleMin, myScaleMax,
False, penType)
'Update pen properties
If Not IsNothing(newPen) Then
newPen.StrokeThickness
= 2
newPen.ShowAxis
= True
newPen.Visible
= True
rtControl.ReloadPens()
End If
'Set Trend Time
myInterval = New System.TimeSpan(0,1,0)
rtControl.SetTimeRange(myInterval)
'Reload Trend Data
rtControl.ReloadRuntimeSettings()
Catch ex As System.Exception
MsgBox(ex.Message)
'MsgBox(ex.InnerException)
Finally
rtControl = Nothing
fElement = Nothing
End Try
End Sub
After this has been done, the code will delete all the Trend’s pens,
if any, and then add the Counter tag alone with its parameters.
Repeat this procedure for the other two buttons by changing the text
to Set Random as Pen and Set Triangle as Pen. Also change the tag
reference in the script from Counter to Random and Triangle respectively.
Once the buttons have been configured, select the RealTime Trend object, and change its name to RTTrendControl. To do this, select the object and:
Once the application is started and the synoptic appears, and as soon as the project has been fully loaded and the driver started working, click on the Set Pen button to assign the specific pen to the trend.