Using ArEventLog in Automation Basic

Hi,

Currently I am trying to use ArEventLog in structured text. I have came across some code in the help for BnR studio. Do we put the help code in another .ab file in our project? How would we use this code for logging a message from another .ab file?

Thanks and Regards,
Kenneth

Sorry if I misunderstood you, but it doesn’t matter at all which language you use to call the function blocks.

During Startup: You can just do ArEventLogGetIdent() with your desired logger, if an error occurs it doesn’t exist yet so you do ArEventLogCreate(). Since these FBs are asynchronous that should be already prepared before you are trying to log anything…

To log: As soon as it exists and you have the handle / ident you can write messages to the logger using the LogWrite function block, which works synchronous so you should be fine by just calling it inside your existing tasks.

Best regards,

If I have ArEventLog setup in C/C++ and am logging messages there, can I just use ArEventLogWrite in structured text also in the same program?

You cannot mix languages inside one task if you mean that.

But you can use one C task and one st task!

If you want to have one “LoggingIF” instance which does all the logging for you, you can of course e.g. write that logger handling in C and then use your interface in all your other tasks. Or just pass the ident from your C-tasks to your other tasks so they can write to it… Really is a matter of preference how you structure it.

2 Likes

Hi,

it’s possible to use ArEventLogWrite() calls for example n Structured Text, even if the preparation like ArEventLogCreate() was made in C/C++.
As Marcel mentioned, you only have to provide the ident for the call.

But you can’t mix up different coding languages within the same task.
That means, to use ST you have to add a ST task,

By the way:
*.ab are Automation Basic code files, *.st are Structured Text.
Automation Basic is a B&R proprietary language similar to Structured Text - unless there’s no compelling reason to use .ab, use .st instead :wink:

Best regards!

3 Likes

Thanks for the information. I have some code in .ab format, would I be able to invoke an ArEvent log function from there? I have changed the forum thread title for accuracy.

If we create a global Ident object in C, are we able to access it in Automation Basic or Structured Text?

1 Like

Hi,

yes, functions/function blocks can also be called in Automation Basic.

Best regards!

Yes, you can do that.

Regarding providing the Ident, is it a string? How do we find out the Ident that we have created in for eg. C++ file and then use it in a .ab program?

If you created the ident in a C++ task, just copy the ident (which is the .ident output of the FB ArEventLogCreate, it’s an UDINT) on a global PLC variable, and use it for function block calls in the AB task.

The 2nd possibility is to call the function block ArEventLogGetIdent in the AB task.
This function block determines the ident by the given logger module name (which is a string).
Then, there’s no need to share the ident out of the C++ program.

Best regards!

I currently created a task implementing the logging example code. I put the variable declarations in the parent module declarations. For the module using the logging, I declared and implemented a function to perform the logging as below. I found that I had to pass in the EventLog as an object. Not sure if this is the best way.

FUNCTION LogSTMsg : UINT (Gets code from EventId (bits 15-0).)
VAR_INPUT
Msg : STRING;
EventLog : EventLog_typ; (Event handling.)
END_VAR
END_FUNCTION

FUNCTION LogSTMsg
strcpy(ADR(EventLog.Event.AdditionalData),ADR(Msg));
EventLog.Event.AdditionalDataSize := strlen(ADR(EventLog.Event.AdditionalData)) + 1;
EventLog.Event.AdditionalDataFormat := arEVENTLOG_ADDFORMAT_TEXT;
EventLog.Commands.WriteUserEvent := TRUE;
END_FUNCTION