F_iecCopyBufferToStream

From product version:  TwinCAT PLC Library IEC60870-5-104 substation v2.0.6 and higher.

 F_iecCopyBufferToStream 1:

This function copies data bytes from an external buffer variable to the stream variable.The memory content of the stream variable increases. The return parameter of the function delivers the number of successfull copied data bytes.

 

FUNCTION F_iecCopyBufferToStream: UDINT

VAR_INPUT
    pBuffer     : DWORD;
    cbBuffer    : UDINT;
END_VAR
VAR_IN_OUT
    stream      : ST_IEC870_5_101Stream;
END_VAR

pBuffer: Pointer (address) of external buffer variable.

cbBuffer: Number of data bytes to be copied from the external buffer variable to the stream variable.

stream: Data buffer.

 

Exmple in ST:

The 4 data bytes of the txBuffer variable are copied to the stream variable by a rising edge at bTx.

PROGRAM P_CopyBufferToStream
VAR
    stream  : ST_IEC870_5_101Stream;
    txBuffer : ARRAY[0..3] OF BYTE := 1, 2, 3, 4;
    cbTx    : UDINT;
    bTx     : BOOL;
END_VAR

 

IF bTx THEN
    bTx     := FALSE;
    cbTx    := cbTx + F_iecCopyBufferToStream( ADR( txBuffer ), SIZEOF( txBuffer ), stream );
    txBuffer[0] := txBuffer[0] + 1;
    txBuffer[1] := txBuffer[1] + 1;
    txBuffer[2] := txBuffer[2] + 1;
    txBuffer[3] := txBuffer[3] + 1;
END_IF

 

Memory description of stream variable before the first function call:

length

data

0

16#00

16#00

16#00

16#00

16#00

...

...

...

...

...

...

IEC870_MAX_ASDU_DATA_BYTE

 

Memory description of stream variable after the first function call:

length

data

4

16#01

16#02

16#03

16#04

...

...

...

...

...

...

...

IEC870_MAX_ASDU_DATA_BYTE

 

Memory description of stream variable after the second function call:

length

data

8

16#01

16#02

16#03

16#04

16#02

16#03

16#04

16#05

...

...

...

IEC870_MAX_ASDU_DATA_BYTE

 

Requirements

Development Environment

Target System

PLC libraries to include

TwinCAT v2.10.0 Build >= 1301

PC or CX (x86)

CX (ARM)

TcIEC870_5_101.Lib
( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib;  are included automatically )