UP/MAKRO程序调用
该指令可用于调用子程序并将子程序调用链接到条件(布尔操作数)。如果需要,可以链接多个操作数(最多11个)。
子程序的调用次数没有限制。
UP101 = F78 + F79 激活条件UP101
;%{SE}%MKUKATPVW %CVW_SPS %VUP %P 2:UP101 = F78 + F79,3:UP
;ENDFOLDSEL_RES=SELECT(#UP,101,$FLAG[78] OR $FLAG[79])
REPEAT UP101 N= 999 STOP= !F298 条件满足停止循环调用UP101
SEL_RES=SELECT (#CYC_UP,101,TRUE,#NUM,999,#NOT_F,298,FALSE)
;ENDFOLD
;ENDFOLD
DEFFCT INT SELECT
(SUB :IN,NO :IN,CALL_CND :IN,ARI_OP :IN,ARI_NUM :IN,BOOL_OP :IN,BOOL_NUM :IN,MAKRO_ADV :IN)
SUB : 选择调用的类型UP/makro
NO : 程序号
CALL_CND : 激活条件
ADV_RESULT = 0
IF NOT CALL_CND THEN ---如果不激活就跳步到最后
GOTO PEXIT -----跳步到退出
ENDIF
SWITCH SUB
CASE #UP 使用调用UP
CALLBYSELECT=TRUE
SWITCH NO ;调用UP程序号
CASE 101 ---程序号
UP101 ( ) 调用UP程序号
CASE 102
UP102 ( )
CASE 103
UP103 ( )
CASE 112
UP112 ( )
CASE 201
UP201 ( )
CASE 206
UP206 ( )
DEFAULT
$LOOP_MSG[]=" "
OFFSET = 0
---程序号不能被调用---
SWRITE($LOOP_MSG[],STATE,OFFSET,"UP%D ist nicht vorhanden",NO)
HALT ---程序号不能被调用---使得程序停止
$LOOP_MSG[]=" "
ENDSWITCH
CALLBYSELECT=FALSE
CASE #MAKRO
SWITCH NO ;开始调用MAKRO程序号 --
CASE 0 要激活的程序号
ADV_RESULT = MAKRO0 (MAKRO_ADV) 激活MAKRO0程序
CASE 1
ADV_RESULT = MAKRO1 (MAKRO_ADV) 激活MAKRO1程序
CASE 2
ADV_RESULT = MAKRO2 (MAKRO_ADV)
CASE 3
ADV_RESULT = MAKRO3 (MAKRO_ADV)
CASE 4
ADV_RESULT = MAKRO4 (MAKRO_ADV)
CASE 5
ADV_RESULT = MAKRO5 (MAKRO_ADV)
CASE 6
ADV_RESULT = MAKRO6 (MAKRO_ADV)
CASE 7
ADV_RESULT = MAKRO7 (MAKRO_ADV)
CASE 8
ADV_RESULT = MAKRO8 (MAKRO_ADV)
CASE 9
ADV_RESULT = MAKRO9 (MAKRO_ADV)
CASE 10
ADV_RESULT = MAKRO10 (MAKRO_ADV)
CASE 11
ADV_RESULT = MAKRO11 (MAKRO_ADV)
CASE 12
ADV_RESULT = MAKRO12 (MAKRO_ADV)
CASE 13
ADV_RESULT = MAKRO13 (MAKRO_ADV)
CASE 14
ADV_RESULT = MAKRO14 (MAKRO_ADV)
CASE 15
ADV_RESULT = MAKRO15 (MAKRO_ADV)
CASE 20
ADV_RESULT = MAKRO20 (MAKRO_ADV)
CASE 50
ADV_RESULT = MAKRO50 (MAKRO_ADV)
CASE 57
ADV_RESULT = MAKRO57 (MAKRO_ADV)
CASE 80
ADV_RESULT = MAKRO80 (MAKRO_ADV)
CASE 81
ADV_RESULT = MAKRO81 (MAKRO_ADV)
CASE 82
ADV_RESULT = MAKRO82 (MAKRO_ADV)
CASE 83
ADV_RESULT = MAKRO83 (MAKRO_ADV)
CASE 89
ADV_RESULT = MAKRO89 (MAKRO_ADV)
DEFAULT
$LOOP_MSG[]=" "
-------没有建立的Makro号被调用
OFFSET = 0
SWRITE($LOOP_MSG[],STATE,OFFSET,"Makro%D ist nicht vorhanden",NO)
用来模拟显示: 没有建立的Makro号被调用
HALT -----如果没有号需要停止
$LOOP_MSG[]=" "
ENDSWITCH 结束了MAKRO选择
CASE #CYC_UP -----循环执行UP程序
NR=0
WHILE NOT (CHECK_BOOL(BOOL_OP,BOOL_NUM) OR CHECK_ARI(NR,ARI_OP,ARI_NUM)) CHECK_BOOL/ CHECK_ARI启动功能条件开启
NR=NR+1 从0开始计数大于给定值将不执行循环程序
CALLBYSELECT=TRUE
SWITCH NO ; UP程序号调用
CASE 101
UP101 ( )
CASE 102
UP102 ( )
CASE 103
UP103 ( )
CASE 112
UP112 ( )
CASE 201
UP201 ( )
CASE 206
UP206 ( )
DEFAULT
$LOOP_MSG[]=" "
UP程序号没有被激活的程序号
OFFSET = 0
SWRITE($LOOP_MSG[],STATE,OFFSET,"UP%D ist nicht vorhanden",NO)
HALT 程序号没有使用程序停止
$LOOP_MSG[]=" "
ENDSWITCH
CALLBYSELECT=FALSE
ENDWHILE
CASE #CYC_MAKRO -----循环执行MAKRO程序
NR=0
WHILE NOT (CHECK_BOOL(BOOL_OP,BOOL_NUM) OR CHECK_ARI(NR,ARI_OP,ARI_NUM)) 大于给定值将不执行循环程序
NR=NR+1 从0开始计数大于给定值将不执行循环程序
SWITCH NO -----调用的程序号
CASE 0
ADV_RESULT = MAKRO0 (MAKRO_ADV) 调用执行MAKRO程序
CASE 1
ADV_RESULT = MAKRO1 (MAKRO_ADV)
CASE 2
ADV_RESULT = MAKRO2 (MAKRO_ADV)
CASE 3
ADV_RESULT = MAKRO3 (MAKRO_ADV)
CASE 4
ADV_RESULT = MAKRO4 (MAKRO_ADV)
CASE 5
ADV_RESULT = MAKRO5 (MAKRO_ADV)
CASE 6
ADV_RESULT = MAKRO6 (MAKRO_ADV)
CASE 7
ADV_RESULT = MAKRO7 (MAKRO_ADV)
CASE 8
ADV_RESULT = MAKRO8 (MAKRO_ADV)
CASE 9
ADV_RESULT = MAKRO9 (MAKRO_ADV)
CASE 10
ADV_RESULT = MAKRO10 (MAKRO_ADV)
CASE 11
ADV_RESULT = MAKRO11 (MAKRO_ADV)
CASE 12
ADV_RESULT = MAKRO12 (MAKRO_ADV)
CASE 13
ADV_RESULT = MAKRO13 (MAKRO_ADV)
CASE 14
ADV_RESULT = MAKRO14 (MAKRO_ADV)
CASE 15
ADV_RESULT = MAKRO15 (MAKRO_ADV)
CASE 20
ADV_RESULT = MAKRO20 (MAKRO_ADV)
CASE 50
ADV_RESULT = MAKRO50 (MAKRO_ADV)
CASE 57
ADV_RESULT = MAKRO57 (MAKRO_ADV)
CASE 80
ADV_RESULT = MAKRO80 (MAKRO_ADV)
CASE 81
ADV_RESULT = MAKRO81 (MAKRO_ADV)
CASE 82
ADV_RESULT = MAKRO82 (MAKRO_ADV)
CASE 83
ADV_RESULT = MAKRO83 (MAKRO_ADV)
CASE 89
ADV_RESULT = MAKRO89 (MAKRO_ADV)
DEFAULT
$LOOP_MSG[]=" "
Makro程序号没有被激活的程序号
OFFSET = 0
SWRITE($LOOP_MSG[],STATE,OFFSET,"Makro%D ist nicht vorhanden",NO)
HALT -----程序号没有使用程序停止
$LOOP_MSG[]=" "
ENDSWITCH ---结束选择程序
ENDWHILE ---结束条件
DEFAULT --- 没有UP,MAKRO,CYC_MAKRO,CYC_UP
ENDSWITCH ---结束选择程序
PEXIT: -------跳步退出
RETURN ADV_RESULT
ENDFCT
---检查位用于循环调用---
DEFFCT BOOL CHECK_BOOL(BOOLOP :IN,BOOLOP_NUM :IN)
INT BOOLOP_NUM 位号,数字
DECL BOOL_TYP BOOLOP 各种类型
BOOL STOP_BOOL
SWITCH BOOLOP
CASE #EIN
STOP_BOOL=TRUE ---激活
CASE #AUS
STOP_BOOL=FALSE ---关闭
CASE #E
STOP_BOOL=$IN[BOOLOP_NUM] ---用输入激活
CASE #NOT_E
STOP_BOOL= NOT $IN[BOOLOP_NUM] ---输入取反激活
CASE #A
STOP_BOOL=$OUT[BOOLOP_NUM] ---用输出激活
CASE #NOT_A
STOP_BOOL= NOT $OUT[BOOLOP_NUM] ---用输出的非激活
CASE #M
STOP_BOOL=$CYCFLAG[BOOLOP_NUM] ---用M量激活
CASE #NOT_M
STOP_BOOL= NOT $CYCFLAG[BOOLOP_NUM] ---用M量的非激活
CASE #F
STOP_BOOL=$FLAG[BOOLOP_NUM] 用F量激活
CASE #NOT_F
STOP_BOOL= NOT $FLAG[BOOLOP_NUM] 用F量的非激活
CASE #T
STOP_BOOL=$TIMER_FLAG[BOOLOP_NUM] 用时间量激活
CASE #NOT_T
STOP_BOOL= NOT $TIMER_FLAG[BOOLOP_NUM] 用时间量的非激活
CASE #S
STOP_BOOL=S[BOOLOP_NUM] S量一般不用
CASE #NOT_S
STOP_BOOL= NOT S[BOOLOP_NUM]
ENDSWITCH
RETURN (STOP_BOOL) 条件满足反馈
ENDFCT
-----用于输入数---
DEFFCT BOOL CHECK_ARI(ACT_NR :IN, ARIOP :IN ,ARIOP_NUM :IN)
INT ACT_NR, ARIOP_NUM, MAX_NR
DECL ARI_TYP ARIOP
SWITCH ARIOP
CASE #NUM 直接给入数
MAX_NR=ARIOP_NUM
CASE #COUNT 计数器
MAX_NR=$COUNT_I[ARIOP_NUM]
CASE #BIN 二进制
MAX_NR=$B_OUT[ARIOP_NUM]
CASE #BININ 二进制输入
MAX_NR=ARIOP_NUM
CASE #ANA 模拟量输出
MAX_NR=$ANOUT[ARIOP_NUM]*1000
CASE #ANAIN 模拟量输入
MAX_NR=$ANIN[ARIOP_NUM]*1000
CASE #TIMER 时间控制
MAX_NR=$TIMER[ARIOP_NUM]*0.01
CASE #PROCPAR P值控制
MAX_NR=PROCPAR[ARIOP_NUM]
ENDSWITCH
RETURN (ACT_NR>=MAX_NR) 计数大于给定值.
ENDFCT
;ENDFOLD
;ENDFOLD
编辑:jq
全部0条评论
快来发表一下你的评论吧 !