My Problem:
I have been creating projects using Codesys for the past 6 months or so and while I have learned a lot about the programming environment I have yet to discover a way to display custom messages during runtime to the console message log.
What I want:
To display a message in the message window of the Codesys IDE during runtime or while debugging.
What I have tried:
- Counters:
I have used counters to help keep track of when certain instances of my programs occur however it gets tedious to constantly having to monitor them especially as my projects get larger or know exactly where in my program the counter originated.
- Pragmas
I recently discovered what Codesys calls 'pragmas' and while they seem to be exactly what I am looking for - I have yet to see any results or outputs from using a pragma and so I am unsure exactly what they are for or do.
To show what my pragmas look like, in many instances I will have a line that looks like:
{info <'Manual mode started!'>} or {warning <'Manual mode terminated!'>}
These lines don't cause errors, but they don't seem to do anything as far as I can tell.
- Custom messaging:
I have gone so far as to create my own custom messaging system. The feature uses a custom function which adds messages to an array and is then displayed on a visualization. The function allows me to do this from anywhere in my program and essentially works as a print statement. But the fact that it requires a visualization makes it inconvenient to use especially for small projects or projects with multiple visualizations.
I appreciate any suggestions - if what I ask for is not possible then I would at least like to know.
CodePudding user response:
What you want is the CmpLog and ComponentManager
libraries. Example of my usage:
result: SysExcept.SysTypes.RTS_IEC_RESULT;
componentID: UDINT;
name: STRING := "myLogComponentName";
message: STRING := "my message";
// Execute this once and cache "componentID" in a global variable.
Component_Manager.CMAddComponent2(pszComponent := name, udiVersion := 1, udiCmpId := ADR(componentID), pResult := ADR(result));
// Use the cached "componentID".
CmpLog.LogAdd2(hLogger := CmpLog.LogConstants.LOG_STD_LOGGER, udiCmpID := componentID, udiClassID := CmpLog.LogClass.LOG_DEBUG, 1, 1, pszInfo := message);
The log will appear in the Log tab inside the running controller.