ISR7Api.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using SR7Link;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace SRAPI
  5. {
  6. /// <summary>
  7. /// SR7IFGetDataCallBack
  8. /// </summary>
  9. /// <param name="nProfileWidth">返回单条轮廓宽度数据 / Returns a single contour width data</param>
  10. /// <param name="nHighlen">返回的批处理行数 / The number of rows in the batch returned</param>
  11. /// <param name="nFlag">回调函数执行状态,根据不同模式自定义 / Callback function execution status, customized according to different modes</param>
  12. /// <param name="nStatusCode">错误码,0无错误 / Error code, 0 no error</param>
  13. /// <param name="ProfileBits">Sync callback 0:32bit data, 1:16bit data</param>
  14. public delegate void SR7IFGetDataCallBack(int nProfileWidth, int nHighlen, int nFlag, int nStatusCode, int ProfileBits);
  15. /// <summary>
  16. /// SR7 API 接口 / SR7 API
  17. /// </summary>
  18. public interface ISR7Api
  19. {
  20. /// <summary>
  21. /// Open
  22. /// </summary>
  23. /// <param name="lDeviceId">设备 ID 号,范围 0-63. / Device ID, range: 0-63.</param>
  24. /// <param name="strIP">相机IP / Camera IP</param>
  25. /// <param name="timeout">搜索时间 (ms),最小值 100 / Search timeout (ms), minimum value: 100</param>
  26. /// <param name="pfErrCallBack">掉线回调函数/Disconnection callback function</param>
  27. /// <returns> <0:失败./Fail. =0:成功./Success</returns>
  28. int Open(int lDeviceId, string strIP, int timeout, ErrConnectCallBack pfErrCallBack);
  29. /// <summary>
  30. /// Init
  31. /// </summary>
  32. /// <param name="dwProfileCnt">指定行数返回数据 / Return the specified number of rows</param>
  33. /// <param name="ProfileBits">0:返回32位高度数据。1:返回16位高度数据 / 0: Return 32-bit height data. 1: Return 16-bit height data.</param>
  34. /// <param name="nTimeout">获取当次回调行数超时时间,单位ms <0:关闭超时,用于无限循环回调初始化
  35. /// Get the timeout of the current callback row number, in ms < 0: turn off the timeout, used for infinite loop callback initialization</param>
  36. /// <param name="pfGetDataCallBack">相机数据回调函数 / Camera data callback function</param>
  37. /// <returns> <0:失败./Fail. =0:成功./Success</returns>
  38. int Init(int dwProfileCnt, uint ProfileBits, int nTimeout, SR7IFGetDataCallBack pfGetDataCallBack);
  39. /// <summary>
  40. /// Start 开始批处理/ Start batch processing
  41. /// </summary>
  42. /// <param name="bIOTrigger">是否硬触发;0:软触发,1:硬触发 / Whether it is hard trigger; 0: soft trigger, 1: hard trigger</param>
  43. /// <param name="timeout">非循环获取时,超时时间(单位ms),-1为无限等待;循环模式该参数可设置为-1.
  44. /// Timeout period (in ms) for non-cyclic acquisition. -1 means infinite waiting. For cyclic mode, this parameter can be set to -1.</param>
  45. /// <returns> <0:失败./Fail. =0:成功./Success</returns>
  46. int Start(bool bIOTrigger, int timeout);
  47. /// <summary>
  48. /// Stop 停止批处理 / Stop batch processing
  49. /// </summary>
  50. /// <param name="instantStop">0:等数据传输完成 1:立即停止,抛弃剩余未传完数据. 用于高速回调
  51. /// 0: Wait for data transmission to complete 1: Stop immediately and discard the remaining untransmitted data. Used for high-speed callback</param>
  52. /// <returns> <0:失败./Fail. =0:成功./Success</returns>
  53. int Stop(int instantStop);
  54. /// <summary>
  55. /// GetData 获取数据接口 / Get data interface
  56. /// </summary>
  57. /// <param name="pHighData">返回的高度数据 / height data returned</param>
  58. /// <param name="pGrayData">返回的灰度数据. / The returned grayscale data.</param>
  59. /// <param name="pEncoderData">返回的编码器数据 / Returned encoder data</param>
  60. /// <param name="nProfileWidth">单条轮廓宽度数据,用于申请内存大小 / Single contour width data, used to apply for memory size</param>
  61. /// <param name="nHighlen">批处理行数,用于申请内存大小 / The number of rows in a batch, used to apply for memory size</param>
  62. /// <param name="ABCam">AB相机; 0:A相机; 1:B相机 / AB camera; 0:A camera; 1:B camera</param>
  63. /// <returns> <0:失败./Fail. =0:成功./Success</returns>
  64. int GetData(int[] pHighData, byte[] pGrayData, int[] pEncoderData, int nProfileWidth, int nHighlen, int ABCam);
  65. int GetData(short[] pHighData, byte[] pGrayData, int[] pEncoderData, int nProfileWidth, int nHighlen, int ABCam);
  66. }
  67. #region PinnedObject
  68. public sealed class PinnedObject : IDisposable
  69. {
  70. private GCHandle _handle; // Garbage collector handle
  71. private bool _isDisposed; // Track whether the object has been disposed
  72. /// <summary>
  73. /// Gets the address of the pinned object.
  74. /// </summary>
  75. public IntPtr Pointer
  76. {
  77. get
  78. {
  79. if (_isDisposed)
  80. throw new ObjectDisposedException(nameof(PinnedObject), "The object has been disposed.");
  81. return _handle.AddrOfPinnedObject();
  82. }
  83. }
  84. /// <summary>
  85. /// Constructor
  86. /// </summary>
  87. /// <param name="target">Target to protect from the garbage collector</param>
  88. public PinnedObject(object target)
  89. {
  90. if (target == null)
  91. throw new ArgumentNullException(nameof(target), "Target object cannot be null.");
  92. _handle = GCHandle.Alloc(target, GCHandleType.Pinned);
  93. }
  94. /// <summary>
  95. /// Dispose method to free the resources held by GCHandle.
  96. /// </summary>
  97. public void Dispose()
  98. {
  99. if (_isDisposed) return;
  100. _handle.Free();
  101. _isDisposed = true;
  102. }
  103. }
  104. #endregion
  105. }