条件指令

ExST (扩展ST)语言支持多种条件 指令结构, 其影响预编译中或编译过程中的代码生成。

执行代码将被视为编辑,例如可能取决于是否是一个特定的数据类型或一个被声明的变量,是否是一个类型或已经获得特定属性的变量,是否是一个有特定数据类型的变量,是否是一个特定的POU或目标可供使用或是访问数的一部分等。

对于一个POU或GVL在POUS数中声明使用一个在应用程序中定义…声明是不可能的。应用程序中的定义将只影响各自的应用程序下的接口插入。

{定义identifier string}

在预处理中所有标识符的连续例子将被给定的连续标记代替,如果 字符不为空 (允许很好定义),标识符保持定义,知道对象的范围结束或者 在未定义方向。使用“条件编译”,见下。

{未定义 identifier} .

标识符的预处理定义, (用 {定义}, 见上)将被移除, 标识符墙是 '未定义'。如果具体的标识符没有当前定义,这个指令将被忽视。

{IF expr}

...

{ELSIF expr}

...

{ELSE}

...

{END_IF}

这是指令条件 编译。具体表达式 exprs 需要在编译时间变成常量;他们正在评估中出现的顺序,直到其中的一个表达式计算为一个非零值。与成功相关的文字指令正常进行预处理和编译,其他被忽略。各部分的顺序是确定的;然而, elsifelse 区域可选, elsif 区域将经常随意出现。

在常量 expr 中,多个条件编译运算符可用,如以下所述。

条件编译运算符

在常数表达式 expr 的条件编译编译指示 ({if}{elsif}) - 见上图,多个运算符可被使用。这些运算符本身可能不是未定义或分别通过{未定义}或{定义}重新定义的。把这些表达式也通过{定义}来完成定义},同样可以用于编译器定义 一个对象的 属性 对话框 (类别 '编译')。

以下运算可用:

  • 定义(定义器)

这个运算符的影响,表达式得到的值是真的,只要标识符 定义了一个{定义}指令并且不是稍后通过{未定义}指令来不定义;否则它的值是错误的。

定义(变量:变量)

前提: 有两个应用程序App1App2。变量 pdef1App2声明, 不在App1中。

{IF defined (pdef1)}

(* this code is processed in App1 *)

{info 'pdef1 defined'}

hugo := hugo + SINT#1;

{ELSE}

(* the following code is only processed in application App2 *)

{info 'pdef1 not defined'}

hugo := hugo - SINT#1;

这里包含一个额外的例子 消息指令: 仅仅信息 pdef1 defined 将显示在消息窗口,当应用被编译,因为pdef1 已经定义。消息'pdef1 not defined'将被显示,如果 pdef1未被定义。

  • 定义 (变量:变量)

当应用到一个变量时,如果这个特殊变量在当前范围内被声明,那么他的值是真,否则是假的。

例子 '定义 (变量:变量)':

前提: 有两个应用程序App1App2。 变量 g_bTestApp2声明,不在 App1中。

{IF defined (variable:g_bTest)}

(* the following code is only processed in application App2 *)

g_bTest := x > 300;

{END_IF}

  • 定义 (类型:标识符)

当应用在一个标识符上时,如果一个类型的特殊名称被声明,那么他的值是真否则为假。

例子 '定义 (类型: 标识符)':

前提: 有两个应用程序 App1App2。数据类型 DUTApp2里定义, 不在 App1

 

{IF defined (type:DUT)}

(* the following code is only processed in application App1 *)

bDutDefined := TRUE;

{END_IF}

  • 定义 (pou:pou-名)

当应用在一个pou名称上时,如果一个POU或一个操作随特殊的pou-名称被定义,他的值为真否则为假。

例子 '定义 (pou: pou-名)'

前提: 有两个应用程序 App1App2, POU CheckBoundsApp2中可用, 但在 App1中不行。

 

{IF defined (pou:CheckBounds)}

(* the following code is only processed in application App1 *)

arrTest[CheckBounds(0,i,10)] := arrTest[CheckBounds(0,i,10)] + 1;

{ELSE}

(* the following code is only processed in application App2 *)

arrTest[i] := arrTest[i]+1;

{END_IF}

  • 尚未完成: 定义(任务:标识符)

这个运算符影响表达式获得真值,一旦标识符定义了任务名,否则它的值为 FALSE。

例子 '定义 (任务: 标识符)':

前提条件:有两个应用 App1App2。任务PLC_PRG_TaskApp1中可用,但在 App2中不可用。

 

{IF defined (task:PLC_PRG_Task)}

(* the following code is only processed in application App1 *)

erg := plc_prg.x;

{ELSE}

(* the following code is only processed in application App2 *)

erg := prog.x;

{END_IF}

  • 还未实现: 定义 (源:标识符)

当应用源 标识符,如果定义了特殊名字的源,它的值是 TRUE ,否则为 FALSE。

例子 'defined (resource: identifier)':

前提条件:有两个应用 App1App2。源对象 glob_var1 (全局变量列表)在 App1中可用, 但在App2中不可用。

 

{IF defined (resource:glob_var1)}

(* the following code is only processed in application App1 *)

gvar_x := gvar_x + ivar;

{ELSE}

(* the following code is only processed in application App2 *)

x := x + ivar;

{END_IF}

  • 特性 (pou: pou-名称, '特性')

当应用于一个POU, 如果在POUs声明部分的第一行明确了属性,该值为TRUE。

例子 '特性 (pou: pou-名称, '特性')':

前提条件:有两个应用 App1App2。 功能 fun1App1App2中可用, 但在App1 会附加获得也够特性'视觉':

在 App1定义 fun1:

{attribute 'vision'}

FUNCTION fun1 : INT

VAR_INPUT

i : INT;

END_VAR

VAR

END_VAR

 

在 App2定义 fun1:

FUNCTION fun1 : INT

VAR_INPUT

i : INT;

END_VAR

VAR

END_VAR

 

指令:

{IF hasattribute (pou: fun1, 'vision')}

(* the following code is only processed in application App1 *)

ergvar := fun1(ivar);

{END_IF}

 

  • Hasattribute (变量: 变量, '属性')

当应用到变量, 它的值为 TRUE,如果该特殊 属性通过 {属性}指令在变量的声明部分的一行中明确了。

例子 '特性 (变量:变量,‘属性’)':

前提条件:有两个应用 App1App2。 变量 g_globalIntApp1App2中可用, 但在 App1 中附加获得一个特性 'DoCount' :

声明 g_globalInt in App1 :

VAR_GLOBAL

{attribute 'DoCount'}

g_globalInt : INT;

g_multiType : STRING;

END_VAR

 

声明 g_globalInt in App2 :

VAR_GLOBAL

g_globalInt : INT;

g_multiType : STRING;

END_VAR

 

指令

{IF hasattribute (variable: g_globalInt, 'DoCount')}

(* the following code line will only be processed in App1, because there variable g_globalInt has got the attribute 'DoCount' *)

 

g_globalInt := g_globalInt + 1;

{END_IF}

 

  • 类型 (变量:变量, type-spec)

当应用在 变量, 它的值为 TRUE,如果这个 特殊变量有明确的 type-spec; 否则为FALSE。

  type-spec的可用数据类型
  • hasvalue (define-ident, char-string)

如果 (define-ident)已经定义,它有具体的值 (char-string), 则它的值为TRUE, 否则为 FALSE

例子 'hasvalue (define-ident, char-string)':

前提条件:变量test用于应用 App1App2,获得值 '1'在 App1和值 '2'在 App2:

{IF hasvalue(test,'1')}

(* the following code line will be processed in App1, because there variable test has value 1 *)

x := x + 1;

{ELSIF hasvalue(test,'2')}

(* the following code line will be processed in App1, because there variable test has value 2 *)

x := x + 2;

{END_IF}

  • NO 运算符

表达式值为 TRUE,当转换值 运算符 是 TRUE。  运算符 可以被列在表格中。

例子无运算符 :

前提条件:有两个应用App1App2。 POU PLC_PRG1App1App2中可用, POU CheckBounds 仅在 App1中可用:

 

{IF defined (pou: PLC_PRG1) AND NOT (defined (pou: CheckBounds))}

(* the following code line is only executed in App2 *)

bANDNotTest := TRUE;

{END_IF}

 

  • operator ANDoperator

为TRUE如果所有运算符都是TRUE. operator 可以被列在表格中。

例子AND 运算符:

前提条例:有两个应用App1App2。 POU PLC_PRG1在应用 App1App2中可用, POU CheckBounds 仅在 App1中可用:

{IF defined (pou: PLC_PRG1) AND (defined (pou: CheckBounds))}

(* the following code line will be processed only in applications App1, because only there "PLC_PRG1" and "CheckBounds" are defined *)

bORTest := TRUE;

{END_IF}

  • operator OR operator

表达式为 TRUE如果其中一个为 TRUE。operator可以为任意一个列在表格中的运算符。

Example on OR operator:

Precondition: POU PLC_PRG1 is used in applications App1 and App2, POU CheckBounds is only available in App1:

{IF defined (pou: PLC_PRG1) OR (defined (pou: CheckBounds))}

(* the following code line will be processed in applications App1 and App2, because both contain at least one of the POUs "PLC_PRG1" and "CheckBounds" *)

bORTest := TRUE;

{END_IF}

  • (运算符)

括号运算符