Forum Home › Forums › Understanding the Software › Using Formulas › Time Off Timer
- This topic has 11 replies, 5 voices, and was last updated 7 months, 3 weeks ago by
gabeirinhas.
-
AuthorPosts
-
January 27, 2021 at 11:20 am #8182
Rich Ex
ParticipantHello friends ,
I am trying to add a delay within a formula and things are not working right .I have a graphic in Webstation that is linked to a channel and the graphic changes when the channel changes from 0 to 1 . So far no problem .
The thing is the real pulse on the channel is short , a few mS , so I want the graphic to stay ‘on’ for 10 seconds .
In my code I have tried using Task.Delay , this did not work , I then tried using the datetime.now as a timer , this worked but stopped the whole Webstation from updating .
Heres my codedouble FindStatus(int boardcnl,int transittimecnl) // get ip cnl & delay cnl
{
double boardbit = Val(boardcnl);// setup variables
double boardcnlstat = Stat(boardcnl);// setup variables
double transittimeSecs = Val(transittimecnl);// setup variables
DateTime tnow = DateTime.Now; // get current time for timer
DateTime target = DateTime.Now.AddSeconds(transittimeSecs); // timer target
int aa = 0; // setup variablesif (boardcnlstat == 1)
if (boardbit == 0 )
{aa=1;
return aa;
}
if (boardbit == 1 )
{aa=2;
Val(aa); // update the cnl
while (tnow < target) // DELAY target reached ?
{ tnow = DateTime.Now; }
return aa;
}
else
{
aa=0;
return aa;
}
}Any help please would be much appreciated .
Thank
RichJanuary 27, 2021 at 2:00 pm #8187Mikhail
ModeratorHello Rich,
I think, you need an extra channel of the calculated discrete type. A formula should check when the source input channel was changed from 0 to 1, then set the 2nd channel to 1 and remember a timestamp. After that compare current time with the timestamp to determine when to change the 2nd channel back to 0.
Formulas must be calculated as fast as possible. Avoid delays, tasks and thread in formulas.
January 27, 2021 at 3:02 pm #8188manjey73
ParticipantWill the TP timer be enough for you, similar to how it is implemented in a PLC?
Calling the formula Tp (Val(414), 10000) number of the monitored channel 414, time in milliseconds.
When 1 appears in channel 414, the timer output will turn on, after 10 seconds it will turn off for this example. The timer starts working on the signal edge, no need to hold 1 in the controlled channel.The Ticks formula is used in all the timers I’ve done. The formulas must be added to the Formula Reference.
-
This reply was modified 2 years, 4 months ago by
manjey73.
January 27, 2021 at 3:07 pm #8190manjey73
ParticipantBut this does not solve the problem of saving the pulse to the channel database when writing once per minute.
January 28, 2021 at 8:55 am #8192Rich Ex
ParticipantThank you Mikhail , thank you Manjey .
Yes I see that I should not add the delay in the formula . I will try what you said about making another channel and using a timestamp for comparison .
As always thank you.
Rich
April 5, 2021 at 2:35 am #8636hethongscada62
ParticipantDear Mr.Mikhail,
I want to use AutoControl Module on Raspberry Pi4. So Pls help me to get the Raspberry Pi4 Key for purchasing order.
Thanks and best regards
P/S: On this Raspberry Pi4 was installed the fee Extra Commponent Module. It is working perfectly.
From Hoang HanApril 6, 2021 at 1:31 pm #8649Mikhail
ModeratorHello,
This topic is named “Time Off Timer”. Please create a new topic with an appropriate name for discussing Auto Control Module.
October 15, 2022 at 9:12 am #11284gabeirinhas
ParticipantHello,
Sorry for my ignorance,
I am trying to implement the formula Tp, in the formula table,
When copying the content that it indicates in the same one,
int[] TpNum = new int[1];
long[] TpST = new long[1];
bool[] TpFlag = new bool[1];
public double Tp(double TpIn, long TpPT)
{
long ET = 0L;
bool q = Val(CnlNum) > 0;
bool tp_in = TpIn > 0;int res = Array.IndexOf(TpNum, CnlNum);
if (res == -1)
{
res = TpNum.Length;
Array.Resize(ref TpNum, res+1);
Array.Resize(ref TpST, res+1);
Array.Resize(ref TpFlag, res+1);
TpNum[res] = CnlNum;
}if (!TpFlag[res])
{
if (tp_in)
{
TpFlag[res] = true;
TpST[res] = Ticks();
if (ET < TpPT) q = true;
}
}
else
{
if (q)
{
ET = Ticks() – TpST[res];
if (ET >= TpPT) q = false;
}
else
{
if(!tp_in)
{
TpFlag[res] = false;
ET = 0L;
}
}
}
return Convert.ToDouble(q);
}The server stops working correctly,
Could you tell me how I could implement such a formula correctly,
I attach images of the process I perform
https://drive.google.com/file/d/1KWlFcQ5Y1vhg3GTUoQfnEbxQPMyw6Ls_/view?usp=sharing
Thank you, best regards
-
This reply was modified 7 months, 3 weeks ago by
gabeirinhas.
October 15, 2022 at 2:02 pm #11286manjey73
ParticipantThere should also be a Tiсks formula in the reference book, which all Timers refer to.
Also, the engine of this forum may spoil some characters when copying. See in the Server log which line in the EngineCS file the error refers to.
-
This reply was modified 7 months, 3 weeks ago by
manjey73.
October 15, 2022 at 4:12 pm #11289gabeirinhas
ParticipantI have added the ticks formula to the formula table and it works correctly,
When adding the formula Tp,
I get the following error,
https://drive.google.com/file/d/183biP4UGyLkpZVKE2CW8Y3r5WdSlOC2d/view?usp=sharing
I hope you can help me, thank you
-
This reply was modified 7 months, 3 weeks ago by
gabeirinhas.
October 15, 2022 at 5:19 pm #11291manjey73
ParticipantET = Ticks() - TpST[res];
probably the forum engine replaced the minus with a dashCheck this line and the position in the file is referenced by an error
October 16, 2022 at 8:50 am #11292gabeirinhas
ParticipantHello,
You were right,
It is working correctly,
Thank you very much
-
This reply was modified 2 years, 4 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.