Příloha 1
Zdrojový kód pro PLC automat
var_global
RecvFromETH1_UNI0 : fbRecvFrom;
rxBuf : STRING[100];
errMsg : STRING;
SendToCH1 : fbSendTo;
txBuf : STRING[100];
sendTim : TON;
sendCnt : UDINT;
Rele1,Rele2,Rele3,Rele4,Rele5,Rele6,Rele7 : TOF;
end_var
PROGRAM prgMain VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR END_VAR VAR_TEMP END_VAR
// receiving
RecvFromETH1_UNI0( rq := TRUE, chanCode :=
ETH1_UNI0,
lenRx := 100, data := void(rxBuf));
if RecvFromETH1_UNI0.mesRec then if RecvFromETH1_UNI0.error = 0 then else
errMsg := GetLastComErrTxt(
RecvFromETH1_UNI0.error); // show error as a text
end_if;
end_if;
Rele1(IN:= int_to_bool(find(rxBuf, 'OTEVRI 1')) , PT:=T#3s, Q => r0_p3_DO.DO0);
Rele2(IN:= int_to_bool(find(rxBuf, 'OTEVRI 2')) , PT:=T#3s, Q => r0_p3_DO.DO1);
Rele3(IN:= int_to_bool(find(rxBuf, 'OTEVRI 3')) , PT:=T#3s, Q => r0_p3_DO.DO2);
Rele4(IN:= int_to_bool(find(rxBuf, 'OTEVRI 4')) , PT:=T#3s, Q => r0_p3_DO.DO3);
Rele5(IN:= int_to_bool(find(rxBuf, 'OTEVRI 5')) , PT:=T#3s, Q => r0_p3_DO.DO4);
Rele6(IN:= int_to_bool(find(rxBuf, 'OTEVRI 6')) , PT:=T#3s, Q => r0_p3_DO.DO5);
Rele7(IN:= int_to_bool(find(rxBuf, 'OTEVRI 7')) , PT:=T#3s, Q => r0_p3_DO.DO6);
rxBuf := '';
sendTim(IN := TRUE, PT := T#1s);
if sendTim.Q then // send new message every 3 sec
sendCnt := sendCnt + 1; // number of messages
if r0_p3_DI.DI0 then txBuf :='STOJAN 1 OTEVREN$0D$0A'; else txBuf := 'STOJAN 1 UZAVREN$0D$0A';end_if;
// txBuf := 'Message number : ' + UDINT_TO_STRING( sendCnt);
SendToCH1( rq := TRUE, chanCode :=
ETH1_UNI0,
lenTx := len(txBuf), data := void(txBuf));
if SendToCH1.error = 0 then // no error if SendToCH1.mesSent then //
message sent succesfully
sendTim(IN := FALSE); // timer restart
end_if;
else
errMsg := GetLastComErrTxt(
SendToCH1.error); // show error as a text end_if;
end_if;
END_PROGRAM