Citect - Cicode help

EICS

Member
Join Date
Dec 2008
Location
Melbourne, Australia
Posts
323
in the past i have only been doing small mods to existing cicode and coping sections to reuse and modify to suit.

Now i have been tasked to write a lot of cicode, as an electrician this does not come easily to me, i'm up to 1600 lines so far in about 30 separate functions and calls and progressing well.

i have a general question as follows, i want to re-run a section depending on an outcome.

FUNCTION

TEST()

code in line 1;
code in line 2; ! this section is re-run depending on outcome
code in line 3;
code in line 4;
IF code in line 5 = x THEN
code in line 6;
ELSE
Tag A = 1;
return back to Line 2; ! i need to jump back to line 2 here somehow

END
END

END

so what statement ( or label etc) do i use to do this?
 
Use the WHILE ... DO ... END instruction.

https://www.citect.schneider-electric.com/webhelp/citect800/Subsystems/CicodeReferenceCitectHTML/Content/using_whilE_..._DO_Conditional_Loops.html

FUNCTION

TEST()


code in line 1;
WHILE code in line 5 <> x DO
code in line 2; ! this section is re-run depending on outcome
code in line 3;
code in line 4;
Tag A = 1;
END // return back to Line 2; ! i need to jump back to line 2 here somehow
code in line 6;

END

However, I recommend never having a chance of a never-ending loop. Depending on the situation, I might put a dummy loop counter, and if the value gets too high, I exit the while loop anyway. Or, as the link I posted above states, you can use the Sleep() command inside the while to give Citect time to do other tasks, but I've never done it this way before.
 
Last edited:
Can't you just add your line2 code to also after else statement.


Or maybe coding another cicode function, which you call on line2 and after else comparing.


Or run ccode at intervals, but to code add vaiable which select which lines executed on next time.





pseudo-code



TEST()

if B = 0 then code in line 1;
End

if B = 1 then code in line 2; ! this section is re-run depending on outcome
end


code in line 3;
code in line 4;
IF code in line 5 = x THEN

if y=x then Tag B= 0; start from line1 on next run
end

code in line 6;
ELSE
Tag A = 1;
Tag B = 1; next run start Line 2

end
 
Consider making the line 2 code a FUNCTION then call as needed.
Look into using the CASE statement to control the execution rather than a bunch of IFs
 

Similar Topics

Some cicode help required Please. i am by no means a cicode expert. i have a tag "D2_WESP_TRA_Op_stat" which depending on its returned integer...
Replies
6
Views
3,275
Hi all, my citect program write all the alarms to a xls file when i open that excel i will run a marco automatic and i can see a bargraph of all...
Replies
4
Views
3,929
Hi If any Citect guru would see this, I'd be very :bow: and even more if answers... Using v7.10 and would like to get some .pdf or something, to...
Replies
1
Views
3,563
I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a...
Replies
3
Views
289
Hi guys, its my first time progamming cicode and I need to do popups alarms, there are several digital alarms and in their rising edge transition...
Replies
0
Views
507
Back
Top Bottom