FB_NovRamReadWrite

The following description refers to TwinCAT Version 2.8. From TwinCAT version 2.9 [Build 927], a function block for writing or reading PLC data to be saved in NOVRAM is no longer required.

FB_NovRamReadWrite 1:

The FB_NovRamReadWrite function block accesses the NOV-RAM of the FCxxxx-0002 fieldbus cards from a PLC program. A rising edge at the bRead or bWrite input activates the function block and a corresponding number of data bytes are read from or written to the NOV-RAM. If both inputs, bRead and bWrite, are set simultaneously, the data are first written into the NOV-RAM and then read back.

Comments:

To determine the NOV-RAM address pointer, the FB_NovRamReadWrite function block internally uses an instance of the ADSREAD function block. This address pointer is only determined when the FB_NovRamReadWrite function block is called for the first time or in the event of a change in nDevId. Several PLC cycles are required for this. The MEMCPY function is used to write data into the NOV-RAM or to read 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.

FB_NovRamReadWrite 2: Inputs

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

Name

Type

Description

nDevId

UDINT

The device ID of a NOVRAM card. The ID is used to specify the NOVRAM of an FCxxxx-0002 card that is to be accessed for writing or reading with the function block. The device IDs are specified by the TwinCAT system during the hardware configuration.

bRead

BOOL

A positive edge at this input activates the function block and cbDestLen data is copied from the NOVRAM (from address offset NULL) into the buffer with the address pDestAddr.

bWrite

BOOL

A positive edge at this input activates the function block and copies cbSrcLen data from the buffer with the address pSrcAddr into the NOVRAM (from address offset NULL).

cbSrcLen

UDINT

The byte length of the data to be written to the NOVRAM.

cbDestLen

UDINT

The byte length of the data to be read from the NOVRAM.

pSrcAddr

PVOID

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

PVOID

The address pointer to a data buffer into which the read NOV-RAM data is to be copied.

tTimeOut

TIME

Specifies the time-out period that must not be exceeded when executing the command/function.

FB_NovRamReadWrite 3: Outputs

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

Name

Type

Description

bBusy

BOOL

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

bError

BOOL

This output is set if an error occurs during execution.

nErrId

UDINT

Returns the ADS error number when the bError output is set.

cbRead

UDINT

Number of successfully read data bytes.

cbWrite

UDINT

Number of successfully written data bytes.

Sample:

PROGRAM MAIN
VAR
    fbNovRamReadWrite : FB_NovRamReadWrite;
    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;
END_VAR
FB_NovRamReadWrite 4:

In the sample, a rising edge at the bRead input reads 100 bytes of data from the NOV-RAM and copies them 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)