F_iecCopyStreamToBuffer
From product version: TwinCAT PLC Library IEC60870-5-104 substation v2.0.6 and higher.
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 delivers the number of successfull copied data bytes.
FUNCTION F_iecCopyStreamToBuffer: 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: Maximum number of data bytes to be copied from the stream variable to the external buffer.
stream: Data buffer.
Example in ST:
After run 4 data bytes are copied to the stream variable. The first 4 data bytes of the stream variable are copied to the rxBuffer variable by a rising edge at bRx .
PROGRAM P_CopyStreamToBuffer
VAR
stream : ST_IEC870_5_101Stream;
txBuffer : ARRAY[0..3] OF BYTE := 1, 2, 3, 4;
cbTx : UDINT;
bTx : BOOL := TRUE;
rxBuffer : ARRAY[0..3] OF BYTE;
cbRx : UDINT;
bRx : 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
IF bRx THEN
bRx := FALSE;
cbRx := F_iecCopyStreamToBuffer( ADR( rxBuffer ), SIZEOF( rxBuffer ), stream );
END_IF
Memory description of stream variable after run:
length | data | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | 16#01 | 16#02 | 16#03 | 16#04 | ... | ... | ... | ... | ... | ... | ... | IEC870_MAX_ASDU_DATA_BYTE |
Memory description of stream variable after first and each further F_CopyStreamToBuffer function call:
length | data | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | 16#01 | 16#02 | 16#03 | 16#04 | ... | ... | ... | ... | ... | ... | ... | 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 |