FB_NovRamReadWrite

The following description is referenced to TwinCAT v2.8. From TwinCAT v2.9 [Build 927] on, no function block for read and write of PLC data to NOVRAM is necessary anymore. Please see also: Configuration example (TwinCAT 2.9).

FB_NovRamReadWrite 1:

With FUNCTION_BLOCK "FB_NovRamReadWrite" an acces to the NOV-RAM IC on the Beckhoff FCxxxx-0002 Fieldbus cards can be achieved through the PLC program. With a rising edge at the bRead or bWrite input, the FB instance is activated, and a various number of data bytes can be read from he NOV-RAM or written into the NOV-RAM with the given nDevId. If both inputs (bRead and bWrite) are set at the same time, the passed data is going to be written first and read back after that procedure again.

Note:

To detect the address pointer of the NOV-RAM, an instance of the ADSREAD FUNCTION_BLOCK is used inside the FB_NovRamReadWrite function block. This address pointer is detected only during the initial call of the FB_NovRamReadWrite function block or after a change of the nDevId input. Multiple PLC cycles are needed for getting this address pointer. To write the data into the NOV-RAM, the FUNCTION MEMCPY is used. Therefore, data can be written or read during the same PLC cycle. Internally, the maximum byte length of the NOV-RAM IC is detected also and the number of bytes to be written or read is limited to this value.

VAR_INPUT

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

nDevId: The appropriate device Id of the NOV-RAM device. Via this Id, the NOVRAM IC which is implemented on the FCxxxx-0002 card is specified. The device ID's are specified during the I/O Configuration within the TwinCAT System Manager.

bRead: With a rising edge on this input, the FB is activated and cbDestLen data is copied from NOV-RAM into the buffer with the pDestAddr address (starting with address offset NULL).

bWrite: With a positive edge on this input, the FB is activated and cbSrcLen data is copied out of the buffer with the address of pSrcAddr into the NOV-RAM (starting with address offset NULL).

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

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

pSrcAddr: The address pointer to the buffer for the data, to be written into the NOV-RAM. The address pointer can be determined with the ADR( ) -Operator.

pDestAddr: The address pointer to the buffer for the data, where the read values are going to be copied into.

tTimeOut: Names the timeout delay, which is not to be exceeded with this command.

VAR_OUTPUT

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

bBusy: With activation of the FB, this output is set until the execution of the write or read command is finished.

bError: If an error occured during the execution of the FB, this output is set.

nErrId: Shows with a TRUE on the bError output the appropriate ADS error ID ("ADS - Return Codes").

cbRead: Number of successfully read data bytes.

cbWrite: Number of successfully written data bytes..

Example for the FB call in FBD:

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 2:

In the above example, with a rising edge at bRead 100 byte data were read from the NOV-RAM and copied into the fromNovRam array.

Requirements

Development environment

Target System

IO-Hardware

PLC libraries to include

TwinCAT v2.8.0 Build > 722

PC (x86),
(not for CX (ARM)!)

FCxxxx cards with NOV-RAM (FCxxxx-0002)

TcIoFunctions.Lib

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