FUNCTION_BLOCK FB1
VAR_TEMP
// Temporary Variables
END_VAR
VAR
// Static Variables
com_step:INT;
time_counter:INT;
connection_request:BOOL;
discon_req:BOOL;
req_send:BOOL;
com_tcon:tcon;
com_trcv:TRCV;
com_tsend:TSEND;
com_tdiscon:TDISCON;
receive_length:INT;
receive_error:WORD;
send_error:WORD;
END_VAR
com_tcon(REQ :=connection_request AND m0.7 // IN: BOOL
,ID :=w#16#1// IN: WORD
,CONNECT :=db300.OUCW_1 // INOUT: ANY
);
com_tdiscon(REQ :=discon_req AND m0.7 // IN: BOOL
,ID :=w#16#1 // IN: WORD
);
// Statement Section
IF m10.0 THEN
m10.0:=false;
com_step:=10;
END_IF;
CASE com_step OF
0:;
10:
connection_request:=true;
discon_req:=false;
time_counter:=0;
com_step:=com_step+1;
11:
IF com_tcon.done THEN
com_step:=com_step+1;
connection_request:=false;
END_IF;
IF com_tcon.error OR com_tcon.busy THEN
time_counter:=time_counter+1;
IF time_counter>5000 THEN
com_step:=13;
connection_request:=false;
time_counter:=0;
END_IF;
END_IF;
12:
com_trcv(EN_R :=m0.2 // IN: BOOL
,ID :=w#16#1 // IN: WORD
,LEN :=20 // IN: INT
,DATA :=db2.rotation_table[1] // INOUT: ANY
);
com_tsend(REQ := m0.2// IN: BOOL
,ID :=w#16#1 // IN: WORD
,LEN :=20 // IN: INT
,DATA :=db12.rotation_table[1] );
IF com_trcv.ERROR THEN
com_step:=13;
receive_error:=com_trcv.STATUS;
END_IF;
IF com_tsend.ERROR THEN
com_step:=13;
send_error:=com_tsend.STATUS;
END_IF;
13:
discon_req:=true;
IF com_tdiscon.DONE THEN
com_step:=10;
discon_req:=false;
END_IF;
time_counter:=time_counter+1;
IF time_counter>5000 THEN
com_step:=10;
discon_req:=false;
END_IF;
END_CASE;
END_FUNCTION_BLOCK
最佳答案
建议你先看SCL手册,把语法看懂,如你这里的CASE。程序中还含有多重背景。
总的来说就是根据com_step的值(10、11、12、13)不同调用以下不同的语句执行,包括变量的状态、累加计数、功能块的调用( com_tcon、 com_trcv、com_tsend、com_tdiscon)。
参见:S7-SCL中文版
http://wenku.baidu.com/view/0ddc062fe2bd960590c67737.html
提问者对于答案的评价:
谢谢你给的帮助
专家置评
已阅,最佳答案正确。
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc237061.html