发布于 2010-02-21 14:36:05
3楼
以下是编译通过的程序代码:
FUNCTION_BLOCK FB1110
Title= 'FB1110'
{
S7_m_c:='true';
S7_tag:='true'
}
VERSION : '1.0'
VAR_INPUT
IN1{S7_m_c:='true'}:real;
SamT{S7_m_c:='true'}:INT:=20 ;//20s读一次数据
DurT{S7_m_c:='true'}:INT:=3;//最多时间间隔20*3=60s
end_var
VAR_OUTPUT
Myout1{S7_m_c:='true'}:real;
end_var
var
InPre:real:=0;
count1:int:=0;
count2:int:=0;
end_var
begin
count1:=count1+1;
if count1>=SamT*10 then //OB35周期0.1s,所以计数200次相当于20s
count2:=count2+1;
count1:=0;
if ABS(InPre-IN1)>1 THEN
Myout1:=IN1;
InPre:=IN1;
count2:=0;
END_IF;
if count2>=DurT then
Myout1:=IN1;
InPre:=IN1;
count2:=0;
END_IF;
END_IF;
end_function_block
---------------------------------------------------
其实这些错误都是粗心和一些格式细节不注意造成的。