1using System.Runtime.InteropServices;
2using System.Runtime.Serialization;
17 internal IcvException(
string message, Backend.Types.peak_icv_status errorCode)
20 ErrorCode = errorCode;
23 internal IcvException(SerializationInfo info, StreamingContext context)
26 ErrorCode = (Backend.Types.peak_icv_status)
27 info.GetValue(nameof(ErrorCode), typeof(Backend.Types.peak_icv_status));
30 internal Backend.Types.peak_icv_status ErrorCode {
get; }
33 public override string Message => $
"{base.Message} - ErrorCode: {ErrorCode}";
36 public override void GetObjectData(SerializationInfo info, StreamingContext context)
38 base.GetObjectData(info, context);
39 info.AddValue(nameof(ErrorCode), ErrorCode);
51 : base(message, errorCode)
64 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NOT_SUPPORTED)
77 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_CORRUPTED)
90 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_MISMATCH)
104 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NOT_POSSIBLE)
117 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NULL_POINTER)
130 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_OUT_OF_RANGE)
143 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_MATH_ERROR)
156 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_TARGET_NOT_FOUND)
169 : base(message, Backend.Types.peak_icv_status.PEAK_ICV_STATUS_IO_ERROR)
182 : base(message, errorCode)
187internal static class DllHelper
193 public static void ExecuteAndMapReturnCodes(Func<Backend.Types.peak_icv_status> dllFunction)
195 Backend.Types.peak_icv_status errorCode = dllFunction();
196 if (errorCode == Backend.Types.peak_icv_status.PEAK_ICV_STATUS_SUCCESS)
201 var errorText = GetLastError();
204 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_LIBRARY_NOT_INITIALIZED:
205 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_DYNAMIC_DEPENDENCY_MISSING:
207 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_MISMATCH:
209 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NOT_SUPPORTED:
211 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NOT_POSSIBLE:
213 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_NULL_POINTER:
215 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_OUT_OF_RANGE:
217 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_MATH_ERROR:
219 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_TARGET_NOT_FOUND:
221 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_CORRUPTED:
223 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_IO_ERROR:
225 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_INTERNAL_ERROR:
226 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_INVALID_BUFFER_SIZE:
227 case Backend.Types.peak_icv_status.PEAK_ICV_STATUS_INVALID_HANDLE:
239 public static void ExecuteAndMapReturnCodesLight(Func<Backend.Types.peak_icv_status> dllFunction)
241 Backend.Types.peak_icv_status errorCode = dllFunction();
242 if (errorCode == Backend.Types.peak_icv_status.PEAK_ICV_STATUS_SUCCESS)
247 throw new IcvException(
"Could not query the last error!", errorCode);
250 internal static string GetLastError()
252 var count = (nuint) 0u;
253 ExecuteAndMapReturnCodesLight(() => CInterface.peak_icv_GetLastErrorMessage_GetCount(out count));
254 var buffer =
new byte[(int) count];
255 ExecuteAndMapReturnCodesLight(() => CInterface.peak_icv_GetLastErrorMessage(buffer, count));
256 return Utils.FromUtf8(buffer);
259 private static class CInterface
261 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
262 public static extern Backend.Types.peak_icv_status peak_icv_GetLastErrorMessage_GetCount(out nuint count);
264 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
265 public static extern Backend.Types.peak_icv_status peak_icv_GetLastErrorMessage(
266 byte[] lastErrorMessage,
Base class for all exceptions thrown by the peak libraries.
Occurs when reading from a file or stream that is incomplete, damaged, or in an unexpected format.
Base class for all exceptions thrown by the library.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Occurs when a file operation fails (e.g., missing file, insufficient permissions, or inaccessible dir...
Occurs when a failure happens during processing due to an unhandled internal routine condition.
Occurs when a required dependency is missing, the library is not initialized, or a misconfiguration a...
Occurs when a mathematical computation fails (e.g., division by zero or invalid matrix operations).
Occurs when input parameters do not match expected conditions (e.g., two input images have different ...
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Occurs when attempting to access an object or value via an uninitialized or null pointer.
Occurs when a provided value falls outside the allowed valid range.
Occurs when an expected target object (e.g., calibration plate or marker) is not detected in the inpu...
Marker interface for exceptions indicating an I/O failure.
Marker interface for exceptions representing internal errors, which are thrown when an unexpected err...
Marker interface for exceptions indicating an unsupported operation.
Marker interface for exceptions indicating an out-of-range condition.