FB_GetDPRAMInfo

The function block FB_GetDPRAMInfo can be used to determine the address pointer and the configured size of the NOV/DP-RAM of a fieldbus card. The address pointer can be used, for example, for direct write or read access of the NOV-RAM of the FCxxx-0002 (Beckhoff) cards or the DPRAM of cards that are not supported by TwinCAT (third-party manufacturers). First, the card has to be configured as general NOV/DP-RAM within the TwinCAT System Manager. The MEMCPY, MEMSET or MEMCMP functions of the PLC program can then be used for write/read access to any memory offset.
VAR_INPUT
VAR_INPUT
nDevId : UDINT;
bExecute : BOOL;
tTimeOut : TIME;
END_VAR
nDevId: The device ID of a NOV/DP-RAM card. The ID is used to specify the card from which information is to be read. The device IDs are specified by the TwinCAT System Manager during hardware configuration.
bExecute: The function block is activated via a rising edge at this input.
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;
stInfo : ST_NovRamAddrInfo;
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").
stInfo: A structure with the address and size of the NOV/DP-RAM.
Example in ST:
TYPE ST_NOVRAM :
STRUCT
dwParam_0 : DWORD;
dwParam_1 : DWORD;
dwParam_2 : DWORD;
dwParam_3 : DWORD;
cbSize : DWORD;
wCounter : WORD;
func : BYTE;
sMsg : STRING(20);
(* ...other NOV-/DP-RAM variables *)
END_STRUCT
END_TYPE
PROGRAM MAIN
VAR
pNOVRAM : POINTER TO ST_NOVRAM;
cbNOVRAM : DWORD;
fbGetInfo : FB_GetDPRAMInfo;
state : INT := 0;
bInit : BOOL := FALSE;
timer : TON;
bReset : BOOL;
END_VAR
CASE state OF
0:
IF NOT bInit THEN
state := 1;
END_IF
1:
fbGetInfo( bExecute := FALSE ); (* reset fb *)
fbGetInfo( nDevId:= 3,
bExecute:= TRUE, (* start fb execution *)
tTimeOut:= T#10s );
state := 2;
2:
fbGetInfo( bExecute := FALSE );
IF NOT fbGetInfo.bBusy THEN
IF NOT fbGetInfo.bError THEN
IF fbGetInfo.stInfo.pCardAddress <> 0 THEN
pNOVRAM := fbGetInfo.stInfo.pCardAddress;
cbNOVRAM := fbGetInfo.stInfo.iCardMemSize;
bInit := TRUE;
state := 0; (* ready, go to the idle step *)
ELSE
state := 100; (* error *)
END_IF
ELSE
state := 100; (* error *)
END_IF
END_IF
100:
; (* error, stay here *)
END_CASE
IF bInit THEN
(* read from or write to NOV-/DP-RAM*)
IF bReset THEN (* reset all bytes to 0 *)
bReset := FALSE;
MEMSET( pNOVRAM, 0, cbNOVRAM );
END_IF
timer( IN := TRUE, PT := T#1s );
IF timer.Q THEN
timer( IN := FALSE );
pNOVRAM^.dwParam_0 := pNOVRAM^.dwParam_0 + 1;
pNOVRAM^.dwParam_1 := pNOVRAM^.dwParam_1 - 1;
END_IF
END_IF
Requirements
Development environment | Target system type | IO Hardware | PLC libraries to include |
---|---|---|---|
TwinCAT v2.8.0 Build > 740 | PC (i386) | FCxxxx cards with NOV-RAM and all other cards with DPRAM | TcIoFunctions.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib are included automatically ) |