>>Message imported from previous forum - Category:Scripts and Tips<< User: admin, originally posted: 2018-10-19 19:37:43 Id:159 This is a re-posting from the obsoleted (October 2018) "Schneider Electric Telemetry & SCADA" forum.
**_NIWTelemetry: Hi everyone. Looking for some help if possible. I have a ST program which generates a future time from current time using the following:_**
_Futuretime := ADD_DT_TIME(NOW(),T#15m)_
**_The T#15m is hard coded as you know. Is there any way I can create a way for a end user to input a time value in hours or minutes and then have it referenced within the calculation above without having to hard code the script 'T#15m' each time?? Thank you all in advance._**
geoffpatton: You can use a variable, constant variable, or a internal point to hold the numeric value, Variables and Internal points are easy to write to. Internal points you can keep history on, but they do count against the point count, Variables are not points so they don't count. Constant Variables hold the value in a configuration property so you cannot just write to it using a method, you have to write a script on a graphic to set the property. The plus side, for me anyway, of a constant variable is you can preset the value in your template, and when you copy or do an export the value is retained. I have used all three depending on the overall need.
I did this using a Constant Variable to set variables on a timer. Here is the relevant ST:
I have not used this with the ADD_DT_Time but I think that will be:
_Futuretime := ADD_DT_TIME(NOW(),CPA_Time)_
This was the script on my mimic:
_Function CPADelaySec Dim frmEditBox, frmOKButton, frmCancelButton Form.Init "Set Control Power Alarm Delay" Form.AddStaticText 2,1, "Control Power ''Alarm Delay'' Setting" Set frmEditBox = Form.AddEditBox(2,3,10,1) frmEditBox.MaxLength = 10 frmEditBox.Align = 0 frmEditBox.Value = Server.GetOPCValue("...IO.Power Email Alarm.CPA Delay.ConstantValue") Form.AddStaticText 14,3, "Seconds" Set frmOKButton = Form.AddPushButton(25,3,"OK") frmOKButton.Default = True Set frmCancelButton = Form.AddPushButton(40,3,"Cancel") Form.Show If Form.Selection = "OK" Then IF isNumeric(frmEditBox.Value) = True Then Server.SetOPCValue "...IO.Power Email Alarm.CPA Delay.Value", Round(Cint(frmEditBox.Value)) Else iResponse = MsgBox("Value is not a Number." , vbOK + vbDefaultButton2, "Set Control Power Alarm Delay") End If End If End Function_
**_NIWTelemetry: Thank you very much for taking the time and trouble to respond. This response was very detailed. I will try this._**
Author Icon dmercer: Hi Tony. The answer that Geoff gave you is for a mimic script, which is different to an ST program. Either can work, but it depends on exactly what you're trying to acchieve.
Mimic scripts run on the client side, and only run when a particular mimic is open. ST programs run on the server side.
In the ST programs you can define some input variables and use those:
_VAR_INPUT Input1 : TIME; END_VAR_
Or you can use a direct variable:
_VAR Input AT %I(..TimeDelay.CurrentValue): TIME; END_VAR;_
**_NIWTelemetry: Hi Dean. Very interesting response. Would you mind elaborating please? I'd like the end user to have the ability to handdress say for example with a value from 1 to 360 on a mimic and have that value stored and added to NOW() as minutes to create a future date time once the ST program executes therefore replacing the hard coded T#15m if you understand. I thought something like this should be a fundamental part of ClearSCADA such as using an internal time point or variable in the data tree then reference it within the script, however it does not appear to be so straightforward. Could you give me an example? It would be fantastic if I was able to get something to work. Thanks._**
AWoodland: You could also pass them in as individual components (hours, mins, secs) and use the MAKE_TIME function.
**_NIWTelemetry: Hi Adam. Thank you for this suggestion. Tony_**
dmercer: Whether you do it in ST or mimic script depends mostly on whether you want to run the logic once; or if the user enters the time once, and then the logic runs in the background on a schedule or a point changing.
If it's the latter, then I would allow some points from the database to be controlled from a mimic, then bring them in as direct variables.
Attached is a zipped export with an extremely quick example. (Time Offset Example 1.zip) Note that the value of the integer point will be lost if the system is exported and re imported. To avoid this you can use a parameter, but then you need to create a custom form in a mimic script.
**_NIWTelemetry: Hi Dean. Amazing Sir! Thank you very much for taking the time and effort to respond. I wish to store a time variable in the data tree and allow it to be handressed by a user from a mimic. On the same mimic there is a button to launch a ST program which disables alarms on a series of analogue points. Part of this ST program is to set a future time which will trigger further ST to re enable the same point alarms once The current date time exceeds that future time. So I'm looking for a way to permit control room staff enter a value in minutes..or hours have that value stored then referenced by the ST program when executed to create a time out. if that makes sense. I will import your attachment into my T&D server and try it out. Thank you once again._**
**_NIWTelemetry: Hi Everyone. I managed to get this working! Thank you all very much for your assistance._**
Attached file: (editor/yi/mqtirw4u9hda.zip), Time Offset Example 1.zip File size: 236878