Hello Community,
I would like to share a library that we have developed in B&R Spain
General Information
Description
The EasyLog library is used to insert messages in an easy way in custom loggers. The library only contains one function (also called EasyLog) that run synchronously, so that means that in only one line it is possible to make a logger insertion. If it is the first message to insert in a logger, the function will create the logger if it doesn’t exist, also in the same call.
The EasyLog library it is based on ArEventLog (the official B&R library to make custom logger insertions). If you have ever used the ArEventLog library you know that there are a few steps before you can insert the message. Check if the logger exist, create it if don’t exist, calculate the message number, priority etc. All this steps are wrapped in a single function with the EasyLog library.
Minimum required versions
Automation Studio 4
- From AS4.2 to AS4.12
- From AR4.21 to AR4.93
Automation Studio 6
- From AS6.0
- From AR6.0
Functionality
The library EasyLog works in a very simple way. It only contains one function, called also EasyLog and has 5 inputs to fill to execute the function.
- Execute → Boolean input. Every cycle that it is set to TRUE it will insert a message
- LoggerName → STRING[10]. The function will check if it already exist or not, and will create this log if don’t.
- LogLevel → Severity of the message to insert (success, info, warning or error).
- ErrorNumber → User defined code to insert with the message.
- Message → STRING[256]. User defined message to insert in this entry
As an output, the function only has 1 output with the Status of the execution. Any other result than ERR_OK (that is 0) should be checked in the help in order to check what has been wrong during the function execution.
Library Help
The library has its own help that comer with sample code for different examples of use. From Automation Studio can be shown by pressing F1 over the library.
Example
This is one of the examples that are available in the help. With this code the task will make one insertion every cycle of execution with the value of the process variable Temperature.
VAR
Message : STRING[256];
Status : DINT;
Temperature : INT;
TempStr : STRING[80];
InsertMessages : BOOL;
END_VAR
PROGRAM _INIT
//Set an initial message
Message := 'TestMesage';
//This will create the logger in case that does not exist in advance.
//Only necessary if the insert time will be very fast < 5ms.
// If logger already exist it is not necessary
//In that case this call with FALSE in Execute will create the logger
// to avoid Cycle Time Violation
Status := EasyLog(FALSE, 'Temp', arEVENTLOG_SEVERITY_INFO, 123, Message);
END_PROGRAM
PROGRAM _CYCLIC
// Convert the current temperature into a string
brsitoa(Temperature, ADR(TempStr));
TempStr := CONCAT(TempStr, ' ºC');
Message := CONCAT('Current Temperature: ', TempStr);
// Execute the logger insertion if InsertMessages = TRUE
Status := EasyLog(InsertMessages, 'Temp', arEVENTLOG_SEVERITY_INFO, 123, Message);
IF Status <> ERR_OK THEN
//Check the error in the help and solve it
END_IF;
END_PROGRAM
This will be a similar result in the logger:
Downloads
Binary library V1.00.0 Version for AS4
EasyLog.zip (1.5 MB)
Binary library V1.00.0 Version for AS6
EasyLog6.zip (1.5 MB)