FB_HVACNOVRAMDataHandling
Application
PLC variables are written fail-safe to NOVRAM with this function block. Following a power failure or a restart of the controller, the NOVRAM will be read out completely.
The behavior of the function block looks as follows if everything was correct at startup:
udiStatus:= 1;
iNovRamReadCount:= 1;
iNovRamWriteCount:= 0;
bDone:= TRUE
Note In the case of ARM-based runtime systems, please make sure that the memory addresses of the PLC variables are divisible by 4! |
Comments
The globally declared variables g_dwHVACVarConfigStart and g_dwHVACVarConfigEnd are allocated to the start address and end address of the memory area. The user must take care to ensure that there are no memory overlaps. The block size is then determined internally from the two addresses. The entire flag area is written automatically to NOVRAM in the event of changes to the flag variables.
see also application example: Example_NOVRAM.zip
VAR_INPUT
sNETID : T_AmsNetId;
TMOUT : TIME;
udiDevID : UDINT;
usiBlockSize : USINT;
sNETID : AmsNetId of the TwinCAT computer on which the function should be executed. If it is to be run on the local computer, an empty string can be entered.
TMOUT : states the length of the timeout that may not be exceeded by execution of the ADS command.
udiDevID : the Device ID specifies the NOVRAM of the CX90xx or CX10xx to be accessed with the function block for reading or writing. The device IDs are specified by the TwinCAT System Manager during hardware configuration.
usiBlockSize : the block size to be accessed per read/write cycle is given in percent; e.g. 20, i.e 5 read/write cycles will be required in order to access the entire flag area.
VAR_OUTPUT
udiStatus : UDINT;
iNovramReadCount : INT;
iNovramWriteCount : INT;
bDone : BOOL;
bBusy : BOOL;
bError : BOOL;
udiErrorID : UDINT;
udiStatus : = 0 , no status
= 1, valid data at last reading of NOVRAM
= 2, invalid data at last reading of NOVRAM. Data were discarded.
iNovramReadCount : counter that is incremented by 1 when NOVRAM is read from.
iNovramWriteCount: counter that is incremented by 1 when NOVRAM is written to.
bDone: will be set to TRUE if the function block is executed.
bBusy: when the function block is activated the output is set, and it remains active until execution of the command has been completed.
bError: this output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in udiErrorID.
udiErrorID: contains the command-specific error code. Please see ADS Return Codes.
Example of handling inside TwinCAT PLC
1st step
- Creating a new project
- Insertion of TcHVAC.lib; this takes place via the tab Resources in object Organizer
2nd step
- Translate project; two warnings are received, since two incompletely defined addresses exist in TcHVAC.lib. The user must define the start and end addresses of the memory area via these two addresses.
3rd step
- The menu command All Instance Paths in the Insert menu can be used via the tab Resources in Object Organizer under Variables_Configuration. The user can define the start and end addresses after performing this step.
4th step
- Define the addresses in Variables_Configuration under the Global Variables.
On ARM-based platforms (e.g. CX90xx) care must be taken that the addresses of the allocated variables are divisible by 4. |
5th step
- In this example 0 was defined as the start address and 56 as the end address.
6th step
- The project must be translated again after performing steps 1 to 5.
|
Sample for declaration of allocated variables:
Heizkurve.fbRealMinTemp_NOVRAM.rVar_N AT %MB12 : REAL;
Heizkurve.fbRealMaxTemp_NOVRAM.rVar_N AT %MB16 : REAL;
Heizkurve.fbRealNightSetback_NOVRAM.rVar_N AT %MB20 : REAL;
Heizkurve.fbRealSetpoint_Y1_NOVRAM.rVar_N AT %MB24 : REAL;
Heizkurve.fbRealSetpoint_Y2_NOVRAM.rVar_N AT %MB28 : REAL;
Heizkurve.fbRealSetpoint_Y3_NOVRAM.rVar_N AT %MB32 : REAL;
Heizkurve.fbRealSetpoint_Y4_NOVRAM.rVar_N AT %MB36 : REAL;
Heizkurve.fbRealOutsideTemp_X1_NOVRAM.rVar_N AT %MB40 : REAL;
Heizkurve.fbRealOutsideTemp_X2_NOVRAM.rVar_N AT %MB44 : REAL;
Heizkurve.fbRealOutsideTemp_X3_NOVRAM.rVar_N AT %MB48 : REAL;
Heizkurve.fbRealOutsideTemp_X4_NOVRAM.rVar_N AT %MB52 : REAL;
.g_dwHVACVarConfigStart AT %MB0 : DWORD;
.g_dwHVACVarConfigEnd AT %MB56 : DWORD;