FB_NLinkWrite

FB_NLinkWrite 1:

This function block sends data from the local TwinCAT system to the third-party system (WRITE service).

VAR_IN_OUT


VAR_IN_OUT
    hLink : T_HNLINK;
END_VAR

hLink : Network connection handle ( Type:T_HNLINK). This is where the instance of the variable used for establishing the connection by the FB_NLinkOpen function block is transferred.

VAR_INPUT

VAR_INPUT
    devAddr    : BYTE := 2;
    eArea      : E_NLinkArea := eNLinkArea_DB;
    nDB        : WORD := 0;
    nOffset    : WORD := 0;
    cbBuffer   : UDINT(0..MAX_NLink_DATALENGTH) := 0;
    pBuffer    : POINTER TO BYTE := 0;
    nOpt       : DWORD := 0;
    bExecute   : BOOL;
    tTimeout   : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

devAddr: Device address, MPI address of the component on the third-party system.

eArea: PLC data area in the third-party system (inputs, outputs, data block, etc.) to which data are to be written (type:E_NLinkArea)

nDB: Data block number in the third-party system. Block in which data are to be written (only relevant for access to data blocks and extended data blocks).

nOffset: The start byte address or word address from which data are to be written to the third-party system. Whether a byte or word address is to be specified depends on the type of external controller/protocol used and the data area to be accessed. Further information can be found here: Description of the PLC data area parameter values.

cbBuffer: Maximum byte length of the data to be transferred from the source data buffer in the local TwinCAT system to the third-party system. The byte length is specified even for access to word addresses.

pBuffer: Pointer/address for the source data buffer. Data from this buffer are transferred to the third-party system. The address can be determined with the ADR operator. The source data buffer must not be smaller than the specified length of the data to be sent.

nOpt: Reserved for future applications.

bExecute: The block is activated by a rising edge at this input.

tTimeout: Specifies the timeout that must not be exceeded on receipt of the command.

VAR_OUTPUT


VAR_OUTPUT
    bBusy : BOOL;
    bError : BOOL;
    nErrID : UDINT;
    cbWrite : UDINT := 0;(* Number of successfull written data bytes *)
END_VAR

bBusy: When the function block is activated this output is set. It remains set until a feedback is received. While Busy = TRUE, no new command will be accepted at the inputs. Please note that it is not the command execution but the receipt of the command that is monitored.

bError: In the event of an error during the command transfer, this output is set once the bBusy output has been reset.

nErrID: Supplies the error number when the bError output is set.

cbWrite: In case of success: Number of successfully written data bytes.

Example:

See examples.


Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4016 or higher

PC oder CX (x86, x64, ARM)

Tc2_S5S7Com (Communication->TcpIp)
Tc2_TcpIp (Communication->TcpIp)
Tc2_Utilities (System)