namespace ZB.MOM.WW.OtOpcUa.Host.Domain
{
///
/// Translates MXAccess error codes (1008, 1012, 1013, etc.) to human-readable messages. (MXA-009)
///
public static class MxErrorCodes
{
///
/// The requested Galaxy attribute reference does not resolve in the runtime.
///
public const int MX_E_InvalidReference = 1008;
///
/// The supplied value does not match the attribute's configured data type.
///
public const int MX_E_WrongDataType = 1012;
///
/// The target attribute cannot be written because it is read-only or protected.
///
public const int MX_E_NotWritable = 1013;
///
/// The runtime did not complete the operation within the configured timeout.
///
public const int MX_E_RequestTimedOut = 1014;
///
/// Communication with the MXAccess runtime failed during the operation.
///
public const int MX_E_CommFailure = 1015;
///
/// The operation was attempted without an active MXAccess session.
///
public const int MX_E_NotConnected = 1016;
///
/// Converts a numeric MXAccess error code into an operator-facing message.
///
/// The MXAccess error code returned by the runtime.
/// A human-readable description of the runtime failure.
public static string GetMessage(int errorCode)
{
return errorCode switch
{
1008 => "Invalid reference: the tag address does not exist or is malformed",
1012 => "Wrong data type: the value type does not match the attribute's expected type",
1013 => "Not writable: the attribute is read-only or locked",
1014 => "Request timed out: the operation did not complete within the allowed time",
1015 => "Communication failure: lost connection to the runtime",
1016 => "Not connected: no active connection to the Galaxy runtime",
_ => $"Unknown MXAccess error code: {errorCode}"
};
}
///
/// Maps an MXAccess error code to the OPC quality state that should be exposed to clients.
///
/// The MXAccess error code returned by the runtime.
/// The quality classification that best represents the runtime failure.
public static Quality MapToQuality(int errorCode)
{
return errorCode switch
{
1008 => Quality.BadConfigError,
1012 => Quality.BadConfigError,
1013 => Quality.BadOutOfService,
1014 => Quality.BadCommFailure,
1015 => Quality.BadCommFailure,
1016 => Quality.BadNotConnected,
_ => Quality.Bad
};
}
}
}