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?
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.
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.
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
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?
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.
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.