F_iecCopyStreamToBuffer

F_iecCopyStreamToBuffer 1:

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

Syntax

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

F_iecCopyStreamToBuffer 2: Inputs

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

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

Inputs/outputs

stream: Source data buffer.

Sample in ST

A rising edge at bRx results in copying of the first four data bytes of the stream variable to the rxBufferA and rxBufferB variables.

PROGRAM P_iecCopyStreamToBuffer
VAR
    stream    : ST_IEC870_5_101Stream := ( length := 4, data := [16#01, 16#02, 16#03, 16#04] );
    rxBufferA : ARRAY[0..3] OF BYTE;
    rxBufferB : ARRAY[0..3] OF BYTE;
    cbResult  : UDINT;
    bRx       : BOOL;
END_VAR
IF bRx THEN
    bRx := FALSE;
    cbResult := F_iecCopyStreamToBuffer ( ADR( rxBufferA ), SIZEOF( rxBufferA ), stream );
    cbResult := F_iecCopyStreamToBuffer ( ADR( rxBufferB ), SIZEOF( rxBufferB ), stream );
END_IF

Memory representation of the stream variable after the program start:

length

data

4

16#01

16#02

16#03

16#04

...

...

...

...

...

...

...

IEC870_MAX_ASDU_DATA_BYTE

Memory representation of the stream variable after the first and second F_CopyStreamToBuffer function calls:

length

data

4

16#01

16#02

16#03

16#04

...

...

...

...

...

...

...

IEC870_MAX_ASDU_DATA_BYTE

The rxBufferA and rxBufferB array variables have the following values after the call: [16#01, 16#02, 16#03, 16#04].

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)