F_iecCopyStreamToBufferByOffset

F_iecCopyStreamToBufferByOffset 1:

This function copies data bytes from the stream variables into an external buffer variable from a byte offset position. 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_iecCopyStreamToBufferByOffset: UDINT
VAR_INPUT
    pBuffer : PVOID;
    cbBuffer: UDINT;
    nOffset : UDINT;
END_VAR
VAR_IN_OUT
    stream  : ST_IEC870_5_101Stream;
END_VAR

F_iecCopyStreamToBufferByOffset 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.

nOffset: Byte offset position of the source data buffer.

Inputs/outputs

stream: Source data buffer.

Sample in ST

A rising edge at bRx results in copying of four data bytes from byte offset 1 of the stream variable into the rxAtOffs variable.

PROGRAM P_iecCopyStreamToBufferByOffset
VAR
    stream   : ST_IEC870_5_101Stream := ( length := 8, data := [16#01, 16#AA, 16#BB, 16#CC, 16#DD, 16#06, 16#07, 16#08] );
    bRx      : BOOL;
    rxAtOffs : DWORD := 0;
    cbResult : UDINT := 0;
END_VAR
IF bRx THEN
    bRx := FALSE;
    cbResult := F_iecCopyStreamToBufferByOffset ( ADR( rxAtOffs ), SIZEOF( rxAtOffs ), 1, stream );
END_IF

Memory representation of the stream variable after the program start:

length

data

8

16#01

16#AA

16#BB

16#CC

16#DD

16#06

16#07

16#08

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

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

length

data

8

16#01

16#AA

16#BB

16#CC

16#DD

16#06

16#07

16#08

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

The variable rxAtOffs has the value: 16#DDCCBBAA.

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)