程序功能:OB35 周期0.1s,SCL编写FB块20s读一次输入,若此次读的数据和上次相差超过1,则立即将读的数据输出;若不超过1,输出不刷新,最长不刷新输出时间为60s。
参考‘海上的云’的思路,程序如下:
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
out1{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:=cout2+1;
count1:=0;
if ABS(InPre-IN1)>1 THEN
out1:=IN1;
InPre:=IN1;
count2:=0;
end_if
if cout2>=DurT then
out1:=IN1;
InPre:=IN1;
count2:=0;
end_if
end_if
end_function_block
出现的错误类型有:
1.unknown statement;
2.IT is not possible to declare system or block attributes in the instruction section or in the view decalration;
3.Label not found;
4.non-existent identifier;
5.expression must be of type bool.
我自己编程能力有限,请熟练SCL的高手帮我一下。
我的SCL语言是V5.3的。
小弟我被这个问题困扰好久了,也发了好几篇相关的帖子,学到了不少东西,在这儿向帮助我的人一并致谢了:谢谢你们的帮助!
顺祝论坛所有成员虎年安康,虎虎生威!