F_iecChangeLinkLayerMode
Starting from the product version:
- TwinCAT PLC Library IEC60870-5-101 Central Station v2.0.3;
- TwinCAT PLC Library IEC60870-5-101 Substation v4.0.3;
- TwinCAT PLC Library IEC60870-5-102 Central Station v2.0.3;
- TwinCAT PLC Library IEC60870-5-103 Central Station v2.0.3;
With this function the default behaviour of each individual ASDU frame at the Link-Layer level in the primary station can be set or changed. The ASDU frame to be sent can be marked as a SEND/NO REPLY frame (function 4) or as a broadcast frame. The frames are marked before depositing the frame in the TX buffer I.e. before calling the FB_IEC870_5_101TBufferCtrl.TxAddObj action.
If you do not use the function, then all frames in the primary station are sent as SEND/CONFIRM frames (function 3). In this case the configured station address is used as the link address.
![]() |
|
Important notes:
- In unbalanced mode the use of this function has no meaning in the substation. The substation never acts as a primary station in this mode.
- The function has no meaning when using the IEC 6087-5-104 protocol.
- This functionality is supported only when using the ‘low level’ interface.
FUNCTION F_iecChangeLinkLayerMode: BOOL
VAR_INPUT
sendNoReplay : BOOL;(* TRUE => Use SEND / NO REPLAY link layer function, FALSE => Use SEND/CONFIRM function (default) *)
globalLinkAddr : BOOL;(* TRUE => Use global (broadcast link address, 0xFF... ), FALSE => Use configured (station) link address *)
END_VAR
VAR_IN_OUT
asdu : ST_IEC870_5_101AOGen;
END_VAR
sendNoReplay : this parameter specifies whether the Link-Layer function SEND/NO REPLY (TRUE = function 4) or SEND/CONFIRM (FALSE = function 3) is to be used when sending the frame;
globalLinkAddr : this parameter specifies whether a global (broadcast) address is to be used instead of the configured station link address when sending the frame. If the value is TRUE, 16#FF or 16#FFFF (size one octet, link address size two octets) is used as the link address in the sent frame;
asdu : The ASDU frame to be sent as a VAR_IN_OUT variable;
Return parameter | Description |
---|---|
FALSE | Function failed. |
TRUE | No error. |
Example 1 (excerpt):
The spontaneous data of a bitstring are to be sent to the central station with the aid of the SEND/NO REPLY function (balanced mode).
...
(* Send spontanous bitstring data *)
IF ( txQDS <> BITSTRING_QUALITY_100 ) OR ( txBSI <> BITSTRING_100 ) THEN
txBSI := BITSTRING_100;
txQDS := BITSTRING_QUALITY_100;(* Get quality *)
txTT := SYSTEMTIME_TO_CP56Time2a( fbRTC.CDT, TRUE );(* Get current time stamp *)(* create asdu *)
txAsdu.ident.eType := M_BO_TB_1; (* Bit string with time tag *)
txAsdu.ident.bSQ := FALSE;
txAsdu.ident.nObj := 1;
txAsdu.ident.eCOT := eIEC870_COT_SPONTAN;
txAsdu.ident.nORG := sysPara.nOrg;(* Set originator address *)
txAsdu.ident.bPN := FALSE;
txAsdu.ident.bT := FALSE;
txAsdu.ident.eClass := eIEC870_Class_1;(* Put to the high priority tx buffer *)
txAsdu.ident.asduAddr := sysPara.asduAddr;(* Set common asdu address *)
txAsdu.info.objAddr := 100;(* Set information object address *)
F_iecResetStream( 0, txAsdu.info.stream ); (* clear previous data (this sets the stream length = 0 *)
F_iecCopyBufferToStream( ADR( txBSI ), SIZEOF( txBSI ), txAsdu.info.stream ); (* put BSI to stream *)
F_iecCopyBufferToStream( ADR( txQDS ), SIZEOF( txQDS ), txAsdu.info.stream ); (* put QDS to stream *)
F_iecCopyBufferToStream( ADR( txTT ), SIZEOF( txTT ), txAsdu.info.stream ); (* put time tag to stream *)F_iecChangeLinkLayerMode( TRUE, FALSE, txAsdu );
fbBuffer.TxAddObj( putObj := txAsdu, buffer := buffer ); (* put asdu to the TX fifo *)F_iecChangeLinkLayerMode( FALSE, FALSE, txAsdu );
IF fbBuffer.bOk THEN
fbLog( put := CONCAT( '<=', IEC101ASDU_TO_STRING(txAsdu) ) );
ELSE(* Report send buffer overflow error *)
fbLog( put := 'TX buffer overflow (spontanous bitstring data)!' );
END_IF
END_IF
...
The txAsdu variable is used to send further data points. The default configuration of the txAsdu frame is produced by a further F_iecChangeLinkLayerMode (FALSE, FALSE,…) function call. Other ASDUs are not to be sent as SEND/NO REPLY telegrams.
Example 2 (excerpt):
A single command is to be sent to the substation with the aid of the SEND/NO REPLY function (unbalanced mode).
...
(* Send one single command *)
IF SND_SCS_2100 THEN
SND_SCS_2100 := FALSE; (* Reset flag *)
txAsdu.ident.eType := C_SC_NA_1; (* Single command *)
txAsdu.ident.bSQ := FALSE;
txAsdu.ident.nObj := 1;
txAsdu.ident.eCOT := eIEC870_COT_ACT; (* Command activation *)
txAsdu.ident.nORG := sysPara.nOrg;(* Set originator address *)
txAsdu.ident.bPN := FALSE;
txAsdu.ident.bT := FALSE;
txAsdu.ident.eClass := eIEC870_Class_1;(* Put to the high priority tx buffer *)
txAsdu.ident.asduAddr := sysPara.asduAddr;(* Set common asdu address *)
txAsdu.info.objAddr := 2100;(* Set information object address *)
tmpByte := INT_TO_BYTE(SCS_2100);(* Set single command state *)
tmpByte.7 := 0;(* Set select/execute bit *)
F_iecResetStream( 0, txAsdu.info.stream ); (* Clear previous data (this sets the stream length = 0 *)
F_iecCopyBufferToStream( ADR( tmpByte ), SIZEOF( tmpByte ), txAsdu.info.stream ); (* put QCC to stream *) F_iecChangeLinkLayerMode( TRUE, FALSE, txAsdu );
fbBuffer.TxAddObj( putObj := txAsdu, buffer := buffer ); (* put asdu to the TX fifo *)
F_iecChangeLinkLayerMode( FALSE, FALSE, txAsdu );
IF fbBuffer.bOk THEN
timerCON( IN := FALSE );(* Reset timer *)
timerTERM( IN := FALSE );(* Reset timer *)
fbLog( put := CONCAT( '<=', IEC101ASDU_TO_STRING(txAsdu) ) );
state := 80;(* Wait for command confirmation *)
ELSE(* Report send buffer overflow error *)
fbLog( put := 'TX buffer overflow (single command)!' );
state := 1;
END_IF
END_IF
...
Requirements
Development environment | Target platform | PLC libraries to be linked |
---|---|---|
TwinCAT v2.11.0 Build >= 1554 | PC or CX (x86, ARM) | (Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib; TcIEC870_5_101.Lib are included automatically) |