Error Handling
When using the MELSEC Communication plug-in, basically two fields in the PLC memory are used to indicate the presence of errors: "gMV_ErrorCode" and "gMV_ErrorCause". By default, they are set to 0, indicating that no errors occurred.
When the plug-in starts, the "gMV_ErrorCode" field is set to 1, indicating that no error is present. If an error occurs, both fields "gMV_ErrorCode" and "gMV_ErrorCause" are updated to reflect the error condition. The PLC needs to acknowledge the error by requesting the "AcknowledgeError" command, that is, by setting "gMV_ReqCommandCode" to the respective command code. For more information on the available command codes, see Communication between Plug-in and PLC.
In response, the plug-in will set "gMV_AckCommandCode" to the same command code. After the PLC has reset "gMV_ReqCommandCode", "gMV_ErrorCode" and "gMV_ErrorCause", the plug-in will also reset "gMV_AckCommandCode" to 0. With this handshake mechanism, the PLC knows that the error fields have been updated.
If a new error occurs while a previous error is still displayed in "gMV_ErrorCode" and "gMV_ErrorCause", it will not overwrite these fields with the new error information. Instead, the previous error is first processed. As soon as "gMV_AckCommandCode" has been reset to 0, the second error will be written to the error fields. If the value in "gMV_ErrorCode" remains unchanged even after "gMV_AckCommandCode" has been reset, it indicates that the same error occurred again. Then, the "AcknowledgeError" command has to be executed a second time to also acknowledge the second error. If no further errors have occurred in the meantime, the value of the "gMV_ErrorCode" field will be reset to 1. This indicates that all errors have been acknowledged.
The MELSEC Communication plug-in also supports a heartbeat mode which allows the PLC to monitor the connection to MERLIC and to handle any unexpected loss of connections. For more information, see the section gMV_Heartbeat.
gMV_ErrorCode
If an error occurs, this field contains a numeric unsigned 32-bit integer that represents the error code. The error code provides information about the severity, the affected component, and the nature of the error according to the error definitions provided by the plug-in development API.
The severity of the error is represented by the most significant 4 bits in the error code. We differentiate between the following severities:
|
Value |
Severity |
|---|---|
|
1 |
Critical |
|
2 |
Error |
|
4 |
Warning |
The affected component where the error occurred is represented by the next four bits of lower significance. The following table shows the possible components:
|
Value |
Affected component |
|---|---|
|
1 |
Vision system (MERLIC) |
|
2 |
MVApp / recipe |
|
4 |
Plug-in host |
|
8 |
MELSEC Communication plug-in |
The least significant 8 bits indicate the nature of the error according to the MV_CODE_* definitions of the plug-in development API. You can find the definitions in the documentation of the API header mv_error_def.h in the Communication Plug-in Development Manual.
For example, if the "gMV_ErrorCode" field contains the hexadecimal error code 0x2139, the respective bits indicate that an error (0x2000) occurred in the vision system (0x0100) because of an image acquisition error (0x39).
gMV_ErrorCause
This field indicates which command caused the error. Thus, it assumes the same numeric value as given in the "gMV_ReqCommandCode" and "gMV_AckCommandCode" fields. For more information on the available commands and their codes, see Communication between Plug-in and PLC.
Sometimes, errors can occur spontaneously and are not caused by any command, for example, when the connection to a camera is lost. In such cases, "gMV_ErrorCause" assumes the value 0, which represents "NoCommand". Only errors caused by commands triggered by the same MELSEC Communication plug-in instance as well as spontaneous errors are processed. Hence, errors caused by a command issued by another plug-in instance are ignored.
gMV_Heartbeat
This field contains a variable used for the heartbeat mode. It indicates whether the connection between MERLIC and the PLC is still active. The field can be monitored by the PLC to constantly check the connection and the PLC can be configured to react to any unexpected loss of connections.
The variable represents a counter in the form of an unsigned 16 bit integer. This counter is updated by the plug-in while MERLIC is connected. This is the case if MERLIC RTE and the plug-in are running. Initially, the counter starts with value 0, which means that MERLIC is not connected, for example, because the plug-in has not been started yet or it has been stopped. When MERLIC is connected, the value is counted up in the specified heartbeat interval. If the counter reaches the limit for WORD values, it is reset to 1 before counting resumes.
If the connection to MERLIC is lost, for example, due to network issues, the counter will not be updated anymore. To ensure that the PLC can detect and handle any unexpected loss of connection, the "gMV_Heartbeat" field should be monitored.