Download Example
CODESYS includes a logger, where system components and fieldbusses are issuing status and error messages.
But this functionality is not limited to internal features. Every application and every library has access to the logger. You simply need to register a component, that you can identify yourself against the logger.
Component_Manager.CMAddComponent2('User Application', 16#00000001, ADR(udiCmpId), 0);
After that you can freely issue LogAdd to write new messages to the PLC log.
CmpLog.LogAdd2(CmpLog.LOG_STD_LOGGER, udiCmpId, CmpLog.LogClass.LOG_INFO, 1, 1, 'Test Message');
Nice posting! Thank you for this
Is the project file corrupted some how? Getting the following when trying to open in CodeSys 3.5 SP11
I think this example is for SP14 or SP15, you use SP11.
Dang, thanks for the info!
hi,
why <>
IF udiCmpId <> 0 THEN
Component_Manager.CMAddComponent2('User Application', 16#00000001, ADR(udiCmpId), 0);
END_IF
does this operation be executed only the first time?
BR, Paolo
Hi, the correct statement should be
IF udiCmpId = 0 THEN
so that it will called once at the beginning
True, but it makes more sense that this code needs to be executed in implicitly available methods:
If those methods are used, the code will be robust and only called once per triggering event (Init, Re-Init or exit) and can be tailored accordingly.
Do you know why DTClogger seems not to work if passed a custom logger with these options?
DM1_logOptions : CmpLog.LogOptions :=
(szName := 'J1939_DM1',
bEnable := 1,
uiType := CmpLog.LogTypes.LT_NORMAL OR CmpLog.LogTypes.LT_TIMESTAMP_RTC OR CmpLog.LogTypes.LT_NO_DISABLE OR CmpLog.LogTypes.LT_DUMP_ALWAYS, // LT_DUMP_ASYNC as in LT_STD results in the same
uiFilter := CmpLog.LogClass.LOG_INFO OR CmpLog.LogClass.LOG_WARNING OR CmpLog.LogClass.LOG_ERROR OR CmpLog.LogClass.LOG_EXCEPTION,
iMaxEntries := 1000,
iMaxFileSize := 50000,
iMaxFiles := 20);
'J1939_DM1' log is always empty, but DTCs end up in the device-specific log (I think thanks to DM1 read...)