Sleep() Without affecting other task

Aimin Ariff

Member
Join Date
Mar 2023
Location
Selangor
Posts
28
Hi guys.. I am using Vijeo Citect 7.4.. I am doing a function inside a function.. What I want to do is I want to put a function to sleep but want the other big function to keep runing.. How can I do that? I want the ChillerConfig function to running continuously but function ChillerStatus only run every 10 minutes, where should I put sleep() task??> This is my code example:

FUNCTION ChillerConfig()
IF lvChillerStatus1 = 1 AND lvChillerStatus2 = 1 AND lvChillerStatus3 = 1
AND lvChillerStatus4 = 0 THEN
lvChilConfig = 1
END

IF lvChillerStatus1 = 1 AND lvChillerStatus2 = 1 AND lvChillerStatus3 = 0
AND lvChillerStatus4 = 1 THEN
lvChilConfig = 2
END

IF lvChillerStatus1 = 1 AND lvChillerStatus2 = 0 AND lvChillerStatus3 = 1
AND lvChillerStatus4 = 1 THEN
lvChilConfig = 3
END

IF lvChillerStatus1 = 0 AND lvChillerStatus2 = 1 AND lvChillerStatus3 = 1
AND lvChillerStatus4 = 1 THEN
lvChilConfig = 4
END

ReadChillerStatus()

END

FUNCTION ReadChillerStatus()

IF DPMP1 > 10 THEN
lvChillerStatus1 = 1
ELSE
lvChillerStatus1 = 0
END

IF DPMP2 > 10 THEN
lvChillerStatus2 = 1
ELSE
lvChillerStatus2 = 0
END

IF DPMP3 > 10 THEN
lvChillerStatus3 = 1
ELSE
lvChillerStatus3 = 0
END

IF DPMP4 > 10 THEN
lvChillerStatus4 = 1
ELSE
lvChillerStatus4 = 0
END

END
 
If you want ChillerConfig to run continuously (i.e. repeatedly continuously), then you don't want to put a sleep() in it, because that will stop ChillerConfig from running.

I am not familiar with Citect, and I do not know how executions of routines are scheduled, but below is one clumsy approach. The TimeCurrent code could be moved into ReadChillerStatus and then ChillerConfig would call ReadChillerStatus unconditionally every time ChillerConfig runs, and ReadChillerStatus would simply return if the 10 minutes had not expired.

But that is using ChillerConfig's scan cycle, plus a time function, to schedule ReadChillerStatus. A better approach might be to schedule execution of ReadChllerStatus independently of ChillerConfig. E.g. have a 10-minute repeating event* (alarm?) that triggers a call ReadChillerStatus directly, and do not call ReadChillerStatus from ChillerConfig at all. Or maybe put a 10-minute sleep into ReadChillerStatus itself, inside a WHILE true block, so ReadChillerStatus starts running once and never exits.
Code:
FUNCTION ChillerConfig()

     itest = 8 - ((lvChillerStatus1 * 4) + (lvChillerStatus4 * 2) + lvChillerStatus)

     IF itest > 0 AND itest < 5 THEN
         lvChilConfig = itest
     END

     /* This may stop working in 2106A.D. */

     newTC = TimeCurrent()

     IF (newTC - oldTC> 599 OR newTC < oldTC THEN
         ReadChillerStatus()
     END_IF

     oldTC = newTC
 END

FUNCTION ReadChillerStatus()
    lvChillerStatus1 = DPMP1 > 10;
    lvChillerStatus2 = DPMP2 > 10;
    lvChillerStatus3 = DPMP3 > 10;
    lvChillerStatus4 = DPMP4 > 10;    
END
* I have no idea how that would be done
 
You're welcome.

Managing time is the key to programming PLCs, and the PLC scan cycle is the clock.

If you come from a Linux/Unix(tm) background, think of a PLC like the GAWK program, where each line read into GAWK is analogous to one program scan cycle in the PLC.
 
You could call a new task with the tasknew() function then have the ReadChiilerStatus() run in it's own thread with a sleep() time, however a better approach would be to use an event that triggers the ReadChiilerStatus() at the frequency you would like. Search the help for "Events". It will give you the information your looking for.
 
Yupp... I used TaskNew, so it can always run without affecting other task if its sleep.. And I check the event as well.. but right now guys, I have new problem, can u guys check my latest forum.. u guys are very helpful.. Thanksss
 

Similar Topics

Wizards, I have a couple HMIs that were mounted on one side of a machine, but most of the work is done on the other side. I have installed RPIs...
Replies
9
Views
3,295
Hello everybody. I live in Chicago and work at airport as a maintenance electrician. I do a lot of automation technician work like control panels...
Replies
11
Views
4,079
i have a vga monitor that has to input one is a 15 pin high density sub d the other is a yellow composite video in. i am using the yellow video in...
Replies
6
Views
2,005
Does your job keep you up. I need sleep.
Replies
7
Views
2,105
Can I define functions blocks in RS5000 that can be used from ladder or can they only be used by the function block editor?
Replies
6
Views
2,390
Back
Top Bottom