1. Add Library
Thanks for the hint with the need of the Library in the Project. This was just as basic that i forgot to mention it. I added it by editing.
2. Add Data
Yes you can add Detail Information via the AddData-Part. There are two Fromats you can use.
- arEVENTLOG_ADDFORMAT_TEXT
Just Add a ASCII String via a Pointer
- arEVENTLOG_ADDFORMAT_CODED
Use the AddData Functions to build a Data Set and attatch it
Work with AddData
Work with Texts
3. About the double call of the Function Block ArEventLogWrite
It is true that there is a Coding Guideline. But for me function is before Guideline.
And at least i think a to hard use of Guidelines lead to this wired situation… The Functionblock is in reality a more or less synchron function. But due to some API rouls it has a Functionblock Design and an Execute Input which requires a PositiveEdge to start the Operation. Which is basicaly a Design for an asynchronous Function Block.
Due to this sircumstance you will be forced to call it twice in a Cycle if you want to use it Synchronously.
To come over this wird looking code i created a wrapper for my own Programms were i can call it as function.
(ST-Code as i had no time to rewrite it)
FUNCTION TLogWriteSDDD
TLogWriteSDDD := 1;
IF Ident <> 0 THEN
pSharedData ACCESS Ident;
IF pSharedData.StatusCore = tlogsdSTATECORE_ACTIVE THEN
// Generate Event ID
ResultEventID := ArEventLogMakeEventID(DINT_TO_USINT(Severity),Facility,Code);
// Generate Additional Data
ResultAddDataInit := ArEventLogAddDataInit(Buffer:=ADR(AddData),BufferSize:=SIZEOF(AddData),Format:=arEVENTLOG_ADDFORMAT_CODED);
ResultAddDataString := ArEventLogAddDataString(Buffer:=ADR(AddData),BufferSize:=SIZEOF(AddData),Value:=ADR(Arg1STRING));
ResultAddDataDint := ArEventLogAddDataDint(Buffer:=ADR(AddData),BufferSize:=SIZEOF(AddData),Value:=Arg2DINT);
ResultAddDataDint := ArEventLogAddDataDint(Buffer:=ADR(AddData),BufferSize:=SIZEOF(AddData),Value:=Arg3DINT);
ResultAddDataDint := ArEventLogAddDataDint(Buffer:=ADR(AddData),BufferSize:=SIZEOF(AddData),Value:=Arg4DINT);
// Write Event
ArEventLogWrite_0.Ident := pSharedData.LogIdent;
ArEventLogWrite_0.EventID := ResultEventID;
ArEventLogWrite_0.TimeStamp := 0; (*System timestamp.*)
ArEventLogWrite_0.ObjectID := EnteredBy;
ArEventLogWrite_0.OriginRecordID := OriginID;
ArEventLogWrite_0.AddDataFormat := arEVENTLOG_ADDFORMAT_CODED;
ArEventLogWrite_0.AddDataSize := SIZEOF(AddData);
ArEventLogWrite_0.AddData := ADR(AddData);
ArEventLogWrite_0(Execute := TRUE);
IF ArEventLogWrite_0.Done THEN
CurrentID := ArEventLogWrite_0.RecordID;
TLogWriteSDDD := ERR_OK;
END_IF
ArEventLogWrite_0(Execute := FALSE);
END_IF
END_IF
END_FUNCTION
4. What do you have to call to make an entry
Thanks @c329837 for the hints.
After having the Ident of the Logbook you can use only write-function to set an Entry.
If you like to enter 2 Log lines in a cycle you have to call the Functionblock much more often in a cycle. Number of Entrys per Cycle * 2