namespace ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport; /// /// The single to OPC UA StatusCode table shared by AbCipStatusMapper and /// AbLegacyStatusMapper (#580) — the two drivers used to carry identical copies. /// public static class AbOpcUaStatusMap { /// OPC UA Good. public const uint Good = 0u; /// OPC UA GoodMoreData. public const uint GoodMoreData = 0x00A60000u; /// OPC UA BadNodeIdUnknown. public const uint BadNodeIdUnknown = 0x80340000u; /// OPC UA BadNotWritable. public const uint BadNotWritable = 0x803B0000u; /// OPC UA BadOutOfRange. public const uint BadOutOfRange = 0x803C0000u; /// OPC UA BadNotSupported. public const uint BadNotSupported = 0x803D0000u; /// OPC UA BadDeviceFailure. public const uint BadDeviceFailure = 0x808B0000u; /// OPC UA BadCommunicationError. public const uint BadCommunicationError = 0x80050000u; /// OPC UA BadTimeout. public const uint BadTimeout = 0x800A0000u; /// OPC UA BadTypeMismatch. public const uint BadTypeMismatch = 0x80740000u; /// Maps a transport-neutral to an OPC UA StatusCode. /// The transport status. /// The corresponding OPC UA status code. public static uint MapStatus(AbStatus status) => status switch { AbStatus.Ok => Good, AbStatus.Pending => GoodMoreData, AbStatus.Timeout => BadTimeout, AbStatus.NotFound => BadNodeIdUnknown, AbStatus.NotAllowed => BadNotWritable, AbStatus.OutOfBounds or AbStatus.TooLarge or AbStatus.TooSmall => BadOutOfRange, AbStatus.Unsupported => BadNotSupported, AbStatus.TypeMismatch => BadTypeMismatch, AbStatus.DeviceStateConflict => BadDeviceFailure, _ => BadCommunicationError, // BadConnection, BadReply, Partial, Abort }; /// /// Status for an exception thrown while creating / reading a tag: a transport exception maps through its /// ; anything else is . /// /// The exception. /// The OPC UA status code. public static uint MapException(Exception ex) => ex is AbTransportException ate ? MapStatus(ate.Status) : BadCommunicationError; }