24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Defined data types<br />

References<br />

For example, if you have a structure named "Week" that contains a component named "Monday", you<br />

can get to it by doing the following:<br />

Week.Monday<br />

You can use the user-defined reference data type to create an alternative name for a variable,<br />

constant or function block.<br />

Create your references as objects in the Object Organizer under the register card<br />

They begin with the keyword TYPE and end with END_TYPE.<br />

Syntax:<br />

TYPE : ;<br />

END_TYPE<br />

Example:<br />

TYPE message:STRING[50];<br />

END_TYPE;<br />

Data types.<br />

Subrange types<br />

A subrange type is a type whose range of values is only a subset of that of the basic type. The<br />

declaration can be carried out in the data types register, but a variable can also be directly declared<br />

with a subrange type:<br />

Syntax for the declaration in the 'Data types' register:<br />

TYPE : (..) END_TYPE;<br />

must be a valid IEC identifier,<br />

is one of the data types SINT, USINT, INT, UINT, DINT, UDINT, BYTE, WORD,<br />

DWORD (LINT, ULINT, LWORD).<br />

<br />

<br />

Is a constant which must be compatible with the basic type and which sets the<br />

lower boundary of the range types. The lower boundary itself is included in this<br />

range.<br />

Is a constant that must be compatible with the basic type, and sets the upper<br />

boundary of the range types. The upper boundary itself is included in this basic<br />

type.<br />

Examples:<br />

TYPE<br />

SubInt : INT (-4095..4095);<br />

END_TYPE<br />

Direct declaration of a variable with a subrange type:<br />

VAR<br />

i : INT (-4095..4095);<br />

ui : UINT (0..10000);<br />

END_VAR<br />

If a constant is assigned to a subrange type (in the declaration or in the implementation) that does not<br />

fall into this range (e.g. 1:=5000), an error message is issued.<br />

In order to check for observance of range boundaries at runtime, the functions CheckRangeSigned<br />

or CheckRangeUnsigned must be introduced. In these, boundary violations can be captured by the<br />

appropriate method and means (e.g. the value can be cut out or an error flag can be set.). They are<br />

implicitly called as soon as a variable is written as belonging to a subrange type constructed from<br />

either a signed or an unsigned type.<br />

10-36 CoDeSys V2.3

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

Saved successfully!

Ooh no, something went wrong!