FB_NovRamReadWriteEx

FB_NovRamReadWriteEx 1:

The function block FB_NovRamReadWriteEx provides access to NOV-RAM (e.g. for FCxxxx-0002 fieldbus cards, CX9000 NOV-RAM 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    : UDINT;
    pDestAddr   : UDINT;    
    nReadOffs   : UDINT; 
    nWriteOffs  : UDINT;
    tTimeOut    : TIME; 
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 into which the read NOV-RAM data are to be copied.

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: If the bError output is set, this parameter supplies the ADS error number ("ADS Return Codes").

cbRead: Number of successfully read data bytes.

cbWrite: Number of successfully written data bytes.

Example of a call in the FBD:

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 system type

IO Hardware

PLC libraries to include

TwinCAT v2.10.0 Build > 1231

PC (i386)

FCxxxx cards with NOV-RAM

TcIoFunctions.Lib

( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib are included automatically )