F_iecCopyBufferToStreamByOffset

F_iecCopyBufferToStreamByOffset 1:

This function copies data bytes from an external buffer variable to the stream variable, starting from a byte offset position. The memory content of the stream variable is increased, depending on the previous length and the specified byte offset. The return parameter of the function returns the number of successfully copied data bytes.

Syntax

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

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

nOffset: Byte offset position in the target data buffer.

Inputs/outputs

stream: Target data buffer.

Sample in ST

A rising edge at bTx results in copying of 4 data bytes from the txAtOffs variable to the stream variable (from byte offset position: 5).

PROGRAM P_iecCopyBufferToStreamByOffset
VAR
    bTx      : BOOL; 
    stream   : ST_IEC870_5_101Stream := (length := 8, data := [16#01, 16#02, 16#03, 16#04, 16#05, 16#06, 16#07, 16#08] );
    txAtOffs : DWORD := 16#DDCCBBAA;
    cbResult : UDINT;
END_VAR
IF bTx THEN
    bTx := FALSE;
    cbResult := F_iecCopyBufferToStreamByOffset ( ADR( txAtOffs), SIZEOF(txAtOffs), 5, stream );
      (* stream.length == 9 *)
END_IF

Memory representation of the stream variable after the program start:

length

data

8

16#01

16#02

16#03

16#04

16#05

16#06

16#07

16#08

16#00

16#00

...

IEC870_MAX_ASDU_DATA_BYTE

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

length

data

9

16#01

16#02

16#03

16#04

16#05

16#AA

16#BB

16#CC

16#DD

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)