PrintMessage
Function - Generates a log message with any wanted strings in the Log Messages tabs window.
Inputs
Input |
Data Type |
Range |
Unit |
Default |
Description |
---|---|---|---|---|---|
Level |
DINT |
0 to 4 |
N/A |
No default |
Level of the logged message (i.e., it's importance).
The Range defines are:
|
Message |
STRING |
1 - 255 |
|
|
Content of the message. The string is a maximum of 255 characters. |
Outputs
Output |
Data Type |
Range |
Unit |
Description |
---|---|---|---|---|
Default (.Q) |
BOOL |
|
N/A |
Returns TRUE when the function successfully executes. |
Remarks
Source
PrintMessage uses the SYSTEM message type.
To view all messages generated by PrintMessage, go to the log configuration and select the specified level for the SYSTEM source.
Level
The message could be sent with a logging level from 0 to 4 that qualifies its importance.
- The highest level, 4, logs critical messages.
- Available levels are: Debug, Informational, Warning, Error, and Critical.
- Only Error and Critical messages a generated by default.
- To force the system to generate every message level, use the Configuration Settings to change the settings to the desired level.
-
-
Enabling all messages can slow down the application's execution.
To avoid locking up communications between the IDE and Runtime, you must never include a print statement in your program that prints to the log every update cycle.
Usage
PrintMessage( LEVEL_DEBUG, 'Message string to be logged' );
FBD Language Example
FFLD Language Example
IL Language Example
Not available.
ST Language Example
// It's possible to create a temporary variable with the message.
MESSAGE := CONCAT( 'MachineState=', ANY_TO_STRING(MachineState), '. MachineSpeed=', ANY_TO_STRING(MachineSpeed) );
// Then print the message to the log window
PrintMessage( LEVEL_INFO, MESSAGE );
PrintMessage( LEVEL_WARNING, MESSAGE );
PrintMessage( LEVEL_ERROR, MESSAGE );
// Or to create the string directly in the function call:
PrintMessage( LEVEL_CRITICAL, CONCAT( 'MachineState=', ANY_TO_STRING(MachineState), '. MachineSpeed=', ANY_TO_STRING(MachineSpeed) ) );