F_iecCopyBufferToStream

F_iecCopyBufferToStream 1:

This function copies data bytes from an external buffer variable to the stream variable. The memory content of the stream variable is increased. The return parameter of the function returns the number of successfully copied data bytes.

Syntax

FUNCTION F_iecCopyBufferToStream: UDINT
VAR_INPUT
    pBuffer : PVOID;
    cbBuffer: UDINT;
END_VAR
VAR_IN_OUT
    stream  : ST_IEC870_5_101Stream;
END_VAR

F_iecCopyBufferToStream 2: Inputs

pBuffer: Pointer (address) of an external buffer variable.

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

Inputs/outputs

stream: Target data buffer.

Sample in ST

A rising edge at bTx results in copying of 2 x 4 data bytes from the txBuffer variable to the stream variable.

PROGRAM P_iecCopyBufferToStream
VAR
    stream   : ST_IEC870_5_101Stream;
    txBuffer : ARRAY[0..3] OF BYTE := [1, 2, 3, 4];
    cbResult : UDINT;
    bTx      : BOOL;
END_VAR
IF bTx THEN
    bTx := FALSE;
    cbResult := F_iecResetStream( 0, stream );
    cbResult := F_iecCopyBufferToStream ( ADR( txBuffer ), SIZEOF( txBuffer ), stream );
    cbResult := F_iecCopyBufferToStream ( ADR( txBuffer ), SIZEOF( txBuffer ), stream );
END_IF

Memory representation of the stream variable before the first function call:

length

data

0

16#00

16#00

16#00

16#00

16#00

16#00

16#00

16#00

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

Memory representation of the stream variable after the first function call:

length

data

4

16#01

16#02

16#03

16#04

16#00

16#00

16#00

16#00

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

Memory representation of the stream variable after the second function call:

length

data

8

16#01

16#02

16#03

16#04

16#01

16#02

16#03

16#04

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

Requirements

Development environment

Target system type

PLC libraries to be linked (category group)

TwinCAT v3.1.4012.0

PC oder CX (x86, x64, ARM)

Tc2_IEC60870_5_10x (Communication->IEC60870)
Tc2_SerialCom (Communication->Serial)
Tc2_TcpIp (Communication->TcpIp)
Tc2_Utilities (System)