-
Notifications
You must be signed in to change notification settings - Fork 4
(Use case) Get and set PLC date and time
Stephan Stricker edited this page May 6, 2020
·
1 revision
- Automation Studio 4.5
- mappView 5.9.2
This example -->sample<-- shows how to get and set the PLC time and date with the DateTimeInput widget. Replace the task name "Program" with the task name you are using or AsGlobalPV when using global variables.
- Add the library astime to the project
- Define the following PLC variables
VAR
visDateTime : DATE_AND_TIME;
DTGetTime_01 : DTGetTime;
visGetDateTime : BOOL;
DTSetTime_01 : DTSetTime;
visSetDateTime : BOOL;
END_VAR
- Add the following code to a structure text PLC task
// Get PLC time and date
IF(visGetDateTime) THEN
DTGetTime_01.enable := 1;
DTGetTime_01();
IF(DTGetTime_01.status = 0) THEN
visGetDateTime := 0;
visDateTime := DTGetTime_01.DT1;
END_IF
END_IF
// Get PLC time and date
IF(visSetDateTime) THEN
DTSetTime_01.enable := 1;
DTSetTime_01.DT1 := visDateTime;
DTSetTime_01();
IF(DTSetTime_01.status = 0) THEN
visSetDateTime := 0;
END_IF
END_IF
- Enable the variables visGetDateTime, visSetDateTime and visDateTime in the OPC UA configuration
- Add a DateTimeInput widget and two buttons to the page
- Bind the variable visDateTime to the DateTimeInput widget
<Binding mode="twoWay">
<Source xsi:type="opcUa" refId="::Program:visDateTime" attribute="value" />
<Target xsi:type="brease" contentRefId="contentStart" widgetRefId="DateTimeInput1" attribute="value" />
</Binding>
- Add the event bindings to get and set the PLC time
<!--< Event binding for get time />-->
<EventBinding id="contentStart.btnGetTimeDate.Click">
<Source contentRefId="contentStart" widgetRefId="btnGetTimeDate" xsi:type="widgets.brease.Button.Event" event="Click" />
<EventHandler>
<Action>
<Target xsi:type="opcUa.NodeAction" refId="::Program:visGetDateTime" >
<Method xsi:type="opcUa.NodeAction.SetValueBool" value="true" />
</Target>
</Action>
</EventHandler>
</EventBinding>
<!--< Event binding for set time />-->
<EventBinding id="contentStart.btnSetTimeDate.Click">
<Source contentRefId="contentStart" widgetRefId="btnSetTimeDate" xsi:type="widgets.brease.Button.Event" event="Click" />
<EventHandler>
<Action>
<Target xsi:type="opcUa.NodeAction" refId="::Program:visSetDateTime" >
<Method xsi:type="opcUa.NodeAction.SetValueBool" value="true" />
</Target>
</Action>
</EventHandler>
</EventBinding>
General Information
Direct binding
Event binding
Use cases
- General
- Widgets
- Styles
- Text
- Content