24.01.2015 Views

PLC Programming

  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5 - Editors in CoDeSys<br />

con1:INT:=12; (* 1. Constant*)<br />

END_VAR<br />

See Appendix B: "Operands in CoDeSys" for a listing of possible constants. See there also regarding<br />

the possibility of using typed constants (Typed Literals).<br />

External variables<br />

Keywords<br />

Global variables which are to be imported into the POU are designated with the keyword EXTERNAL.<br />

They also appear in the Watch window of the declaration part in Online mode.<br />

If the VAR_EXTERNAL declaration does not match the global declaration in every respect, the<br />

following error message appears: "Declaration of '' does not match global declaration!"<br />

If the global variable does not exist, the following error message appears: "Unkown global variable:<br />

''!"<br />

Example:<br />

VAR EXTERNAL<br />

var_ext1:INT:=12; (* 1st external variable *)<br />

END_VAR<br />

Keywords are to be written in uppercase letters in all editors. Keywords may not be used as variables.<br />

Examples for keywords: VAR, VAR_CONSTANT, IF, NOT, INT.<br />

Variables declaration<br />

A variables declaration has the following syntax:<br />

{AT }: {:=};<br />

The parts in the braces {} are optional.<br />

Regarding the identifier, that is the name of a variable, it should be noted that it may not contain<br />

spaces or umlaut characters, it may not be declared in duplicate and may not be identical to any<br />

keyword. Upper/lowercase writing of variables is ignored, in other words VAR1, Var1 and var1 are not<br />

different variables. Underlines in identifiers are meaningful, e.g. A_BCD and AB_CD are interpreted<br />

as different identifiers. Multiple consecutive underlines at the beginning of an identifier or within a<br />

identifier are not allowed. The length of the identifier, as well as the meaningful part of it, are unlimited.<br />

All declarations of variables and data type elements can include initialization. They are brought about<br />

by the ":=" operator. For variables of elementary types, these initializations are constants. The defaultinitialization<br />

is 0 for all declarations.<br />

Example:<br />

AT Declaration<br />

var1:INT:=12; (* Integer variable with initial value of 12*)<br />

If you wish to link a variable directly to a definite address, then you must declare the variable with the<br />

keyword AT.<br />

For faster input of the declarations, use the shortcut mode.<br />

In function blocks you can also specify variables with incomplete address statements. In order for<br />

such a variable to be used in a local instance, there must be an entry for it in the variable<br />

configuration.<br />

Pay attention to the possibility of an automatic declaration<br />

If you wish to link a variable directly to a definite address, then you must declare the variable with the<br />

keyword AT. The advantage of such a procedure is that you can assign a meaningful name to an<br />

CoDeSys V2.3 5-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!