Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
158
Добавлен:
11.10.2020
Размер:
2.81 Mб
Скачать

Declaration Editor...

When a variable is open, all of its components are listed after it. A minus sign appears in front of the variable. If you double-click again or press <Enter>, the variable will be closed, and the plus sign will reappear.

Pressing <Enter> or double-clicking on a single-element variable will open the dialog box to write a variable. Here it is possible to change the present value of the variable. In the case of Boolean variables, no dialog box appears; these variables are toggled.

The new value is displayed after the variable, in pointed brackets and in turquoise color, and remains unchanged. If the 'Online' 'Write values' command is given, then all variables are placed in the selected list and are once again displayed in black.

If the 'Online' 'Force values' command is given, then all variables will be set to the selected values, until the 'Release force' command is given. In this event, the color of the force value changes to red

5.2.3Pragma instructions in the Declaration Editor

The pragma instruction is used to affect the properties of a variable concerning the compilation resp. precompilation process. It can be used in with supplementary text in a program line of the declaration editor or in its own line.

The pragma instruction is enclosed in curly brackets, upperand lower-case are ignored: { <Instruction text> }

If the compiler cannot meaningfully interpret the instruction text, the entire pragma is handled as a comment and read over. A warning is issued: „Ignore compiler directive ‚<Instruction text>’!"

Depending on the type and contents of pragma, the pragma either operates on the line in which it is located or on all subsequent lines until it is ended by an appropriate pragma, or the same pragma is executed with different parameters, or the end of the file is reached. By file we mean here: declaration part, implementation portion, global variable list, type declaration.

The opening bracket may immediately follow a variable name. Opening and closing brackets must be located on the same line.

The following pragmas are currently available in CoDeSys: Pragma {flag} for Initialization, Monitoring, Creation of symbols Pragma {bitaccess...} for the Bitaccess

Pragma {parameter..}, {template...}, {instance...} for creating for Parameter Manager entries

Pragma instructions for Initialization, Monitoring, Creation of symbols, Bitaccess Pragma {flag [<flags>] [off|on]}

<flags> can be a combination of the following flags:

noinit:

The variable will not be initialized.

nowatch:

The variable can not be monitored

noread:

The variable is exported to the symbol file without read

 

permission

nowrite:

The variable is exported to the symbol file without write

 

permission

5-10

CoDeSys V2.3

5 - Editors in CoDeSys

noread,

The variable will not get exported to the symbol file

nowrite:

 

With the „on" modifier, the pragma operates on all subsequent variable declarations until it is ended by the pragma {flag off}, or until overwritten by another {flag <flags> on} pragma.

Without the „on" or „off" modifier, the pragma operates only on the current variable declaration (that is the declaration that is closed by the next semicolon).

Examples for use of pragma {flag}:

Initialization and monitoring of variables:

The variable a will not be initialized and will not be monitored. The variable b will not be initialized:

VAR

a : INT {flag noinit, nowatch}; b : INT {flag noinit };

END_VAR

VAR

{flag noinit, nowatch on} a : INT;

{flag noinit on} b : INT;

{flag off}

END_VAR

Neither variable will be initialized:

{flag noinit on}

VAR

a : INT; b : INT;

END_VAR {flag off}

VAR

{flag noinit on} a : INT;

b : INT;

{flag off} END_VAR

Getting variables to the symbol file:

The flags „noread" and „nowrite" are used, in a POU that has read and/or write permission, to provide selected variables with restricted access rights. The default for the variable is the same as the setting for the POU in which the variable is declared. If a variable has neither read nor write permission, it will not be exported into the symbol file.

Examples:

If the POU has read and write permission, then with the following pragmas variable a can only be exported with write permission, while variable b can not be exported at all:

VAR

a : INT {flag noread};

b : INT {flag noread, nowrite}; END_VAR

VAR

{flag noread on} a : INT;

{flag noread, nowrite on} b : INT;

{flag off}

END_VAR

Neither variable a nor b will be exported to the symbol file:

CoDeSys V2.3

5-11

Declaration Editor...

{ flag noread, nowrite on }

VAR

a : INT; b : INT;

END_VAR

{flag off}

VAR

{ flag noread, nowrite on} a : INT;

b : INT;

{flag off}

END_VAR

The pragma operates additively on all subsequent variable declarations.

Example: (all POUs in use will be exported with read and write permission) a : afb;

...

FUNCTION_BLOCK afB

VAR

b : bfb {flag nowrite}; c : INT;

END_VAR

...

FUNCTION_BLOCK bfB VAR

d : INT {flag noread}; e : INT {flag nowrite};

END_VAR

„a.b.d": Will not be exported

„a.b.e": Will be exported only with read permission „a.c": Will be exported with read and write permission.

Pragma {bitaccess...} for the Bitaccess

This pragma can be used to get a correct display of a variable, which is doing a bitaccess with the help of a global constant, in the input assistant, in the intellisense function and at monitoring in the declaration window. Further on it will effect that, when this variable is monitored in the declaration window of the particular POU, the used global constants are shown below the respective structure variable.

Please regard: The project option 'Replace constants' (category Build) must be activated !

The pragma must be inserted in the declaration of the structure in a separate line. The line is not terminated by a semicolon.

Syntax:

{bitaccess <Global Constant> <Bitnumber> '<comment>'}

<Global Constant>: Name of the global constant, which must be defined in a global variables list. <Bitnumber>: Value of the global constant, as defined in the global variables list.

See for an example in Chapter Appendix B: Operands in CoDeSys, Addressing bits in variables.

Pragma instructions for Parameter Manager entries

Pragma instructions can be inserted in variable declarations in order to create entries for these variables in parameter lists which are handled in the Parameter Manager. It depends on the target system, whether the Parameter Manager is available in the CoDeSys programming system. This means it must be activated in the target settings, category Networkfunctionality..

5-12

CoDeSys V2.3

5 - Editors in CoDeSys

The syntax:

The pragma instruction is enclosed in curly brackets, upperand lower-case are ignored: { <Instruction text> }. If it is included in "normal" variable declarations, it must be set before the terminating semicolon of the declaration.

Pragmas, which are used in the VAR_CONFIG interface, are set each in a single line and are not terminated with a semicolon !

The key definitions are written separated by space characters, all together enclosed in square brackets.

<name>: Name of the parameter list in the Parameter Manager. If the list does not yet exist, it will be created.

<key>: Name of the attribute, i.e. column title in the parameter list; e.g. "Name", "Value", "Accesslevel" etc.; It depends on the definition of the parameter list type, which keys can be defined in the pragma.

<value>: Value of the attribute which is defined by <key>. If <value> contains empty spaces it must be enclosed in double quotation marks, e.g. ...accessright="read only"...

Please note: The pragma instructions will be effective as soon as the focus is changed, that means as soon as a precompile is done e.g. via leaving the editor window. Erroneous inputs will not be messaged until the project is compiled.

The following entries can be generated:

1. Entries in parameter lists of type 'Variables'

(a)from the declaration part of programs and global variables lists:

For a variable defined in a PROGRAMor VAR_GLOBAL declaration an entry in a parameter list of type 'Variables' can be created, if it is declared like described in the following: (If the parameter list does not yet exist, it will be created automatically)

Syntax: {parameter list=<name> [ <key>=<value> <key>=<value> ...further keys ] }

Example: Variable bvar is declared in a program. It should be entered in the parameter list parlist1 type 'Variables') with symbolic name bvar1, value 102, index 16#1200 and subindex 16#2l.

VAR

bvar:INT{parameter list=parlist1 [name=bvar1 value=102 index=16#1200 subindex=16#1 ] };

END_VAR

(b)via a declaration in the VAR_CONFIG Interface:

There is the possibility to create an entry for a variable in a parameter list of type 'Variables' by placing a pragma in a VAR_CONFIG window (independent of variable configurations, which also are done in the VAR_CONFIG interface): (If the parameter list does not yet exist, it will be created automatically)

Syntax: {parameter list=<name> path=<path> [ <key>=<value> <key>=<value> ...further keys ] } <path> Path of the variable, for which the entry should be generated, e.g. "PLC_PRG.act1.var_x"

Example: For variable var_x an entry is created in parameter list "varlist1", symbolic name is xvar".

VAR_CONFIG

{parameter list=varlist1 path=PLC_PRG.act1.var_x [ name=xvar ] }

END_VAR

CoDeSys V2.3

5-13

Declaration Editor...

2. Entries in parameter lists of type 'Template' via function blocks and structures

Pragmas in variable declarations in function blocks and structures can be used to create entries in parameter lists of type 'Template'. (If the template does not yet exist, it will be created automatically.)

Syntax: {template list=<name> [ <key>=<value> <key>=<value> ...further keys ] }

Example: Variable strvar, which is an element of structure "stru1", should be entered in a parameter list "templ1" of type 'Template'; symbolic name (member) of the entry is "struvar1, the access level is "low" :

TYPE stru :

STRUCT

ivar:INT;

strvar:STRING{template list=vorl1 [member=struvar1 accesslevel=low] };

END_STRUCT

END_TYPE

3. Entries in parameter lists of type 'Instance' (for arrays, function blockor structure variables)

(a)via declarations in programs or global variable lists

At the declaration of arrays, function blockor structure variables in a program or in a global variables list directly an parameter list of type 'Instance' can be created:

Syntax: {instance list=<name> template=<template> baseindex=<index> basesubindex=<subindex> [ <key>=<value> <key>=<value> ...further keys ] }

Attention: Do not define a value for the key "Member"; this column will be filled automatically by using the array index values.

Examples:

Example1:

An array variable "arr_1" is declared as described in the following in order to get entries in a parameter list "arrinst" of type 'Instance'; in this list all array components will get a symbolic name "xname" (could be edited afterwards in the parameter manager) and the subindex will be counted up by 1 for each entry, starting with 0.

arr_1: ARRAY [1..8] OF INT{instance list=arrinst template=ARRAY baseindex=16#0 basesubindex=16#0 [name=xname ] };

Example1, Entries for an array in an instance list

5-14

CoDeSys V2.3

5 - Editors in CoDeSys

Example2:

A structure variable of type "stru1" (contains variables a,b,c) is declared as described in the following in order to get entries in a parameter list of type 'Instance' which is basing on the template "strulist_temp"; the list will get entries for the components a,b,c, no symbolic names are assigned, the access level is set to "high" and each index value defined by the template will be increased by 2. Make sure that the template defined in the pragma is available in the Parameter Manager:

struvar:stru1{instance list=strulist template=strulist_templ baseindex=16#2 basesubindex=16#0 [accesslevel=high] };

Example2, Entries for structure variable in Template

(b)via declarations in the VAR_CONFIG interface

For variables which can be instanced, you can directly create entries in an parameter list of type 'Instance' by a pragma in a VAR_CONFIG window (independent of variable configuration definitions which are also done in this interface). (If the template does not yet exist, it will be created automatically).

Make sure that the Template defined in the pragma is already available in the Parameter Manager..

Syntax: {instance list=<name> path=<path> template=<template> baseindex=<index> basesubindex=<subindex>[ <key>=<value> <key>=<value> ...further keys ] }

<path>: The instance path of the variable;e.g. "PLC_PRG.fb1inst", whereby fb1inst is an instance of function block fb1.

Example: The following entry in a VAR_CONFIG window will create entries for all variables of function block "fb1" in an instance list "varinst1" basing on the template "fb1_templ" (which must be already available). For each entry the index offset, which is predefined by the template, will be increased by 2 (baseindex), the subindex offset will not be modified (basesubindex). Each entry gets a symbolic name "fb1var", which you can edit afterwards in the Parameter Manager.

VAR_CONFIG

CoDeSys V2.3

5-15

Соседние файлы в папке 759-333