TYPE "ComCouple"
VERSION : 0.1
STRUCT
ComPro : Struct
TCON : Struct
CONN_DONE : Bool;
CONN_BUSY : Bool;
CONN_ERROR : Bool;
CONN_SETA : Bool;
DISCONNECT : Bool;
CONN_STATUS : Word;
STATUS_SAVE : Word;
Errorzähler : DInt;
Donezähler : DInt;
END_STRUCT;
TSEND : Struct
SEND : Bool;
DONE : Bool;
BUSY : Bool;
ERROR : Bool;
REQ_P : Bool;
REQ_I : Bool;
STATUS : Word;
STATUS_SAVE : Word;
NDR : Bool;
LEN : UDInt;
Errorzähler : DInt;
Donezähler : DInt;
END_STRUCT;
TRCV : Struct
REQ : Bool;
DONE : Bool;
BUSY : Bool;
ERROR : Bool;
REQ_P : Bool;
REQ_I : Bool;
STATUS : Word;
STATUS_SAVE : Word;
NDR : Bool;
LEN : UDInt;
Errorzähler : DInt;
Donezähler : DInt;
END_STRUCT;
Empfangstrigger : Bool;
END_STRUCT;
TCP_Parameter {InstructionName := 'TCON_IP_v4'; LibVersion := '1.0'} : TCON_IP_v4;
sSendeVerz : Struct
IN : Bool;
Q : Bool;
END_STRUCT;
Snd : Struct
Byte1 : Byte;
Byte2 : Byte;
Sendebereich : Array[0..256] of Byte;
END_STRUCT;
Rec : Struct
Byte1 : Byte;
Byte2 : Byte;
Empfangsbereich : Array[0..256] of Byte;
END_STRUCT;
END_STRUCT;
END_TYPE
FUNCTION_BLOCK "Kommunikationsaufbau"
TITLE = Kommunikationsserver
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : VoR
FAMILY : Komm
VERSION : 0.3
//Baut die Verbindung zum Informations und Kontrollsystem auf. Umgerüstet für integrierte Profinetschnittstelle der 300er Reihe. Wird nicht mehr im Netpro projektiert!
// V0.2 Umgerüstet für S7-1500 und TIA V10.5
// V0.3 hochgerüstet für TIA V15 keine neuen Versionsnummern für Hochrüstungen zwischen den TIA Versionen. soviele Versionsnummern kosten Geld.
VAR_INPUT
init : Bool;
END_VAR
VAR_OUTPUT
Error : Bool; // Verbindungsunterbuch
END_VAR
VAR_IN_OUT
ComCouple : "ComCouple";
END_VAR
VAR
TCON_Instance {InstructionName := 'TCON'; LibVersion := '4.0'} : TCON;
TSEND_Instance {InstructionName := 'TSEND'; LibVersion := '4.0'} : TSEND;
TRCV_Instance {InstructionName := 'TRCV'; LibVersion := '4.0'} : TRCV;
SendREQ_TON {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
SendeVerz {InstructionName := 'TOF_TIME'; LibVersion := '1.0'} : TOF_TIME;
R_TRIG_TRCV_NDR {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
T_DIAG_Instance {InstructionName := 'T_DIAG'; LibVersion := '1.2'} : T_DIAG;
T_DIAG_result {InstructionName := 'TDiag_Status'; LibVersion := '1.0'} : TDiag_Status;
T_RESET_Instance {InstructionName := 'T_RESET'; LibVersion := '1.2'} : T_RESET;
tVerbindungsreset {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
stVerbindungsreset : Struct
IN : Bool;
q : Bool;
END_STRUCT;
TDISCON_Instance {InstructionName := 'TDISCON'; LibVersion := '2.1'} : TDISCON;
st_TDISCON : Struct
REQ : Bool;
END_STRUCT;
END_VAR
VAR_TEMP
Dummyval : Int;
END_VAR
VAR CONSTANT
akt_verz : Bool := false; // Abstand zwischen telegrammen aktivieren?
akt_vz_Time : Time := t#1000ms;
Zykl_senden : Bool := true; // Aktivieren wenn sendetelegramm nicht extern angetriggert wird
END_VAR
BEGIN
#TCON_Instance.REQ := #stVerbindungsreset.q;
IF #ComCouple.ComPro.TCON.CONN_DONE THEN // Verbindungsaufbau. Donezähler inkrementieren.
#ComCouple.ComPro.TCON.Donezähler := #ComCouple.ComPro.TCON.Donezähler + 1;
END_IF;
IF #ComCouple.ComPro.TCON.CONN_ERROR THEN // Verbindungsaufbau. Error. Errorzähler inkrementieren. Status sichern.
#ComCouple.ComPro.TCON.Errorzähler := #ComCouple.ComPro.TCON.Errorzähler + 1;
#ComCouple.ComPro.TCON.STATUS_SAVE := #ComCouple.ComPro.TCON.CONN_STATUS;
END_IF;
#TCON_Instance(ID := #ComCouple.TCP_Parameter.ID,
DONE => #ComCouple.ComPro.TCON.CONN_DONE,
BUSY => #ComCouple.ComPro.TCON.CONN_BUSY,
ERROR => #ComCouple.ComPro.TCON.CONN_ERROR,
STATUS => #ComCouple.ComPro.TCON.CONN_STATUS,
CONNECT := #ComCouple.TCP_Parameter);
#T_DIAG_Instance.REQ := NOT #T_DIAG_Instance.BUSY;
#T_DIAG_Instance(ID := #ComCouple.TCP_Parameter.ID, // Verbindungsstatus
RESULT := #T_DIAG_result);
// Nach 30s nicht erfolgreicher verbindung. TCON erneut antriggern.
#stVerbindungsreset.IN := #T_DIAG_result.State <> 16#04 AND NOT #stVerbindungsreset.q;
#TDISCON_Instance(REQ := #st_TDISCON.REQ,
ID := #ComCouple.TCP_Parameter.ID);
#tVerbindungsreset(IN := #stVerbindungsreset.IN,
PT := t#30s,
Q => #stVerbindungsreset.q);
// #T_RESET_Instance(REQ:=#stVerbindungsreset.q,
// ID:=#ComCouple.TCP_Parameter.ID);
REGION Sendeempfangsteil
IF #Zykl_senden THEN
IF NOT #ComCouple.sSendeVerz.Q AND NOT #ComCouple.ComPro.TSEND.SEND THEN
#ComCouple.ComPro.TSEND.SEND := true;
END_IF;
END_IF;
IF #T_DIAG_result.State <> 16#04 THEN // Wenn keine Verbindung aufgebaut. Nix senden.
#ComCouple.ComPro.TSEND.SEND := false;
END_IF;
IF #ComCouple.ComPro.TSEND.DONE THEN // Wenn gesendet Donezähler inkrementieren. Sendeflag zurücksetzen
#ComCouple.ComPro.TSEND.Donezähler := #ComCouple.ComPro.TSEND.Donezähler + 1;
#ComCouple.ComPro.TSEND.SEND := false;
END_IF;
IF #ComCouple.ComPro.TSEND.ERROR THEN // Wenn error beim Senden. Status sichern und Errorzähler inkrementieren. Sendeflag zurücksetzen
#ComCouple.ComPro.TSEND.Errorzähler := #ComCouple.ComPro.TSEND.Errorzähler + 1;
#ComCouple.ComPro.TSEND.STATUS_SAVE := #ComCouple.ComPro.TSEND.STATUS;
#ComCouple.ComPro.TSEND.SEND := false;
END_IF;
#SendREQ_TON(IN := #ComCouple.ComPro.TSEND.SEND, // Angsstimer. Wenn Sendeflag aus Gründen nicht zurückgesetzt wird nach spätestens x zurücksetzen
PT := t#3s);
IF #SendREQ_TON.Q THEN
#ComCouple.ComPro.TSEND.SEND := false;
END_IF;
#TSEND_Instance(REQ := #ComCouple.ComPro.TSEND.SEND,
ID := #ComCouple.TCP_Parameter.ID,
LEN := #ComCouple.ComPro.TSEND.LEN,
DONE => #ComCouple.ComPro.TSEND.DONE,
BUSY => #ComCouple.ComPro.TSEND.BUSY,
ERROR => #ComCouple.ComPro.TSEND.ERROR,
STATUS => #ComCouple.ComPro.TSEND.STATUS,
DATA := #ComCouple.Snd.Sendebereich);
#TRCV_Instance(EN_R := #T_DIAG_result.State = 16#04,
ID := #ComCouple.TCP_Parameter.ID,
LEN := 0,
ADHOC := TRUE,
NDR => #ComCouple.ComPro.TRCV.NDR,
BUSY => #ComCouple.ComPro.TRCV.BUSY,
ERROR => #ComCouple.ComPro.TRCV.ERROR,
STATUS => #ComCouple.ComPro.TRCV.STATUS,
RCVD_LEN => #ComCouple.ComPro.TRCV.LEN,
DATA := #ComCouple.Rec.Empfangsbereich);
#R_TRIG_TRCV_NDR(CLK := #ComCouple.ComPro.TRCV.NDR, // Telegramm empfangen (auf Flanke genommen, da es Bausteine gibt mit stehendem Done)
Q => #ComCouple.ComPro.Empfangstrigger);
IF #ComCouple.ComPro.TRCV.NDR THEN // Wenn Done dann Donezähler inkrementieren
#ComCouple.ComPro.TRCV.Donezähler := #ComCouple.ComPro.TRCV.Donezähler + 1;
END_IF;
IF #ComCouple.ComPro.TRCV.ERROR THEN // Wenn Error dann status sichern und errorzähler inkrementieren
#ComCouple.ComPro.TRCV.Errorzähler := #ComCouple.ComPro.TRCV.Errorzähler + 1;
#ComCouple.ComPro.TRCV.STATUS_SAVE := #ComCouple.ComPro.TRCV.STATUS;
END_IF;
#SendeVerz(IN := #ComCouple.ComPro.TSEND.SEND, // Zeit um Senden langsamer zu machen bei langsameren Gegenstellen ohne Empfangsquittierung.
PT := #akt_vz_Time, // Konstante zum aktivieren oder deaktivieren der Verzögerung (Constants)
Q => #ComCouple.sSendeVerz.Q);
IF NOT #akt_verz THEN
#ComCouple.sSendeVerz.Q := false;
END_IF;
#Error := #ComCouple.ComPro.TCON.CONN_ERROR OR #ComCouple.ComPro.TRCV.ERROR OR #ComCouple.ComPro.TSEND.ERROR;
END_REGION
END_FUNCTION_BLOCK