FB_NovRamReadWriteEx

FB_NovRamReadWriteEx 1:

The FB_NovRamReadWriteEx function block accesses the NOV-RAM (e.g. of the FCxxxx-0002 fieldbus cards, CX9000 NOVRAM, etc.) from a PLC program. Activation of the function block is triggered by a rising edge at the bRead or bWrite input. A certain number of data bytes is read from or written to the NOV-RAM. If both inputs, i.e. bRead and bWrite are set at the same time, data are first written to the NOV-RAM and then read back. Unlike with the FB_NovRamReadWrite block, the address offset for write and read access can be specified in the NOV-RAM. The block also checks the permitted NOV-RAM memory access mode and copies data byte by byte into the NOV-RAM memory if required, instead of using MEMCPY. The CX9000 NOV-RAM, for example, only allows byte access, and the FB_NovRamReadWrite block would return an error in this case.

Comments:

In order to determine the NOV-RAM address pointer, the FB_NovRamReadWriteEx function block internally uses an instance of the ADSREAD function block. This address pointer is only determined when the FB_NovRamReadWriteEx function block is called for the first time or in the event of a change in nDevId. This task requires several PLC cycles. The NOV-RAM memory is accessed directly for writing data to or reading data from the NOV-RAM. This enables data to be written or read in the same PLC cycle. Internally the maximum byte length of the NOV-RAM is also determined, and the maximum data length that can be read or written is limited to this length.

VAR_INPUT

VAR_INPUT
    nDevId     : UDINT;
    bRead      : BOOL;
    bWrite     : BOOL;
    cbSrcLen   : UDINT;
    cbDestLen  : UDINT;
    pSrcAddr   : PVOID;
    pDestAddr  : PVOID;
    nReadOffs  : UDINT;
    nWriteOffs : UDINT;
    tTimeOut   : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

nDevId: The device ID of a NOV-RAM card. Via the Id the NOV-RAM of an FCxxxx-0002 card is specified for which write or read access is required via the function block. The device IDs are specified by the TwinCAT System Manager during hardware configuration.

bRead: The block is activated by a rising edge at this input, and cbDestLen data are copied from the NOV-RAM (from address offset nReadOffs) into the buffer with address pDestAddr.

bWrite: The block is activated by a rising at this input, and cbSrcLen data are copied from the buffer with address pSrcAddr into the NOV-RAM (from address offset nWriteOffs).

cbSrcLen: : The byte length of the data to be written into the NOV-RAM.

cbDestLen: The byte length of the data to be read from the NOV-RAM.

pSrcAddr : The address pointer to a data buffer containing the data to be written into the NOV-RAM. The address pointer can be determined via the ADR operator.

pDestAddr : The address pointer to a data buffer with the data to be written into the NOV-RAM.

nReadOffs: The address offset in the NOV-RAM from which data are to be read.

nWriteOffs: The address offset in the NOV-RAM from which data are to be written.

tTimeOut: States the length of the timeout that may not be exceeded during execution of the command/function.

VAR_OUTPUT

VAR_OUTPUT
    bBusy    : BOOL;
    bError   : BOOL;
    nErrId   : UDINT;
    cbRead   : UDINT;
    cbWrite  : UDINT;
END_VAR

bBusy: This output is set when the function block is activated, and remains set until execution of the function has been completed.

bError: This output is set if an error occurs during execution.

nErrId: Supplies the ADS error number when the bError output is set.

cbRead: Number of successfully read data bytes.

cbWrite: Number of successfully written data bytes.

Example:

PROGRAM MAIN
VAR
    fbNovRamReadWrite : FB_NovRamReadWriteEx;
    bRead             : BOOL;
    bWrite            : BOOL;
    fromNovRam        : ARRAY[1..100] OF BYTE;
    toNovRam          : ARRAY[1..100] OF BYTE;
    bBusy             : BOOL;
    bError            : BOOL;
    nErrID            : UDINT;
    cbRead            : UDINT;
    cbWrite           : UDINT;
    readOffs          : UDINT :=0;
    writeOffs         : UDINT:=0;
    cbToWrite         : UDINT := 100;
    cbToRead          : UDINT := 100;
END_VAR

FB_NovRamReadWriteEx 2:

In the example a rising edge at the bRead input led to 100 bytes of data being read from the NOV-RAM and copied into the fromNovRam array.

Requirements

Development environment

Target platform

IO Hardware

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86)

FCxxxx cards with NOVRAM (FCxxxx-0002)

Tc2_IoFunctions (IO)