Wid110LibConst.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. #define TEST_FOR_EXTENSION_OF_LIB
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders.IOSS
  7. {
  8. static partial class Wid110LibConst
  9. {
  10. // ====================================================================
  11. /// <summary>
  12. /// Constants that should be used overall WID110 library software.
  13. /// </summary>
  14. // ====================================================================
  15. // local system resources
  16. //
  17. public static string tmpImage = "testImage_WidLib.bmp";
  18. // return values: these must correspond with 'WID110Dll.h'
  19. // these are return values only for c-function calls
  20. //
  21. // function executed sucessfully
  22. public const int rcNoError = 1; // RETVAL_NO_ERROR
  23. // function failed, calls to FGetLastError()
  24. // and FGetErrorDescription() possible
  25. public const int rcError = 0; // RETVAL_ERROR
  26. // function parameter contained invalid lib handle, call
  27. // to FGetErrorDescription() possible
  28. public const int rcInvObj = -1; // RETVAL_INV_OBJ
  29. // error codes: these must correspond with 'WID110Dll.h'
  30. // these are values for internal lib errors returned by FGetLastError()
  31. // an error description can be retrieved by calling FGetErrorDescription()
  32. //
  33. public static int ecInvObj = -1; // RETVAL_INV_OBJ
  34. public static int ecNone = 0; // ERROR_NONE
  35. public static int ecNotInit = 1; // ERROR_NOT_INIT
  36. public static int ecNotFound = 2; // ERROR_READER_NOTFOUND
  37. public static int ecNetInit = 3; // ERROR_NETWORK_INIT
  38. public static int ecNetIP = 4; // ERROR_NETWORK_IP
  39. public static int ecNetSend = 5; // ERROR_NETWORK_SEND
  40. public static int ecNetRecv = 6; // ERROR_NETWORK_RECEIVE
  41. public static int ecFileName = 7; // ERROR_FILENAME
  42. public static int ecImgSave = 8; // ERROR_IMG_SAVE
  43. public static int ecParLoad = 9; // ERROR_PARAM_LOAD
  44. public static int ecNoProcTrg = 10; // ERROR_NO_PROC_TRIGGERSTR
  45. public static int ecArgBufSz = 11; // ERROR_ARGBUFFERSIZE
  46. public static int ecNoFailSt = 12; // ERROR_NO_FAILSTR
  47. public static int ecNoMoreImg = 13; // ERROR_NO_MORE_IMAGES
  48. public static int ecNoResult = 14; // ERROR_NO_VALID_RESULT
  49. public static int ecNoImage = 15; // ERROR_NO_VALID_IMAGE
  50. public static int ecNoTrgStr = 16; // ERROR_NO_TRIGGERSTRING
  51. public static int ecNoVersPar = 17; // ERROR_VERSION_PARAMETERSET
  52. public static int ecPOutOfRng = 18; // ERROR_PARAMETER_OUTOFRANGE
  53. public static int ecNetTrig = 19; // ERROR_NET_TRIGGERING
  54. public static int ecReaderTimeout = 20; //ERROR_READER_TIMEOUT
  55. public static int ecReaderNotRunning = 21; //ERROR_READER_NOT_RUNNING
  56. // parameter values for FProcessGetImage(type)
  57. // these must correspond with 'WID110Dll.h'
  58. //
  59. public static int pvImgBest = 0; // IMG_PROCESS_BEST
  60. public static int pvImgAll = 1; // IMG_PROCESS_ALL
  61. // dummy results
  62. //
  63. public static string rsltFAIL = "fail";
  64. public static string rsltOK = "OK";
  65. public static string rsltERROR = "no read result";
  66. public static string rsltBLANK = " ";
  67. public static string rsltREAD = "READ: ";
  68. public static string rsltNOREAD = "NOREAD: ";
  69. // return value for FGetCodeQualityX()
  70. // if there is no quality retrieved, call GetLastError() then
  71. public static int rsltNoCodeQuality = -1;
  72. // return value for FGetCodeTime()
  73. // if there is no time retrieved, call GetLastError() then
  74. public static int rsltNoCodeTime = -1;
  75. // dummy error messages
  76. //
  77. public static string errNO = "no error";
  78. public static string errDESC = "ERROR; no error description";
  79. // string buffer sizes
  80. //
  81. public static int errLen = 256;
  82. public static int versLenCS = 63;
  83. public static int versLenC = versLenCS + 1;
  84. public static int rsltLenCS = 259;
  85. public static int rsltLenC = rsltLenCS + 1;
  86. }
  87. }
  88. /**********************************************************************************************//**
  89. * @struct WID_CAPTURE
  90. *
  91. * @brief WID120 Grabbing data
  92. *
  93. * @author Jg
  94. * @date 10.05.2017
  95. **************************************************************************************************/
  96. public struct WID_CAPTURE
  97. {
  98. public int widColor; //!< light color (0..2)
  99. public int widChannel; //!< light channel (0..6)
  100. public int widIntensity; //!< light intensity (0..180) 0=off
  101. public int widRotated; //!< Image Rotated (0..1)
  102. public int widFlipped; //!< Image Flipped (0..1)
  103. };
  104. /**********************************************************************************************//**
  105. * @struct WID_ROI
  106. *
  107. * @brief A wid region of interest
  108. *
  109. * @author Jg
  110. * @date 14.06.2017
  111. **************************************************************************************************/
  112. public struct WID_ROI
  113. {
  114. public int roiXS; //!< X-Start (0..960)
  115. public int roiXL; //!< X-Length (64..960)
  116. public int roiYS; //!< Y-Start (0..304)
  117. public int roiYL; //!< Y-Length (64..368)
  118. };
  119. /**********************************************************************************************//**
  120. * @struct Unsafe WID_OCR
  121. *
  122. * @brief WID120 OCR parameter (Internal used by <see cref="Wid110LibUser.Wid110Lib"/>
  123. *
  124. * @author Jg
  125. * @date 10.05.2017
  126. **************************************************************************************************
  127. * 16.04.2020 MAI Changed char array to fixed byte. Added StructLayout attribute.
  128. [**************************************************************************************************/
  129. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  130. public unsafe struct WID_OCR_Unsafe
  131. {
  132. public fixed byte widFontName[12]; //!< Name of font "semi_5x9","semi_org","semi_lin","ocra"
  133. public fixed byte widFielding[32]; //!< Fielding of String "aannnn-nn-cc"
  134. public fixed byte widFormat[32]; //!< Fielding of String "++++++++++++"
  135. public fixed byte widResult[32]; //!< Result of String "Reading Result"
  136. public int widMinSimilarity; //!< minimum Similarity (50..75)
  137. public int widAccSimilarity; //!< accepted Similarity (85..99)
  138. public int widSpacing; //!< Spacing of Character (80..200)
  139. public int widRotation; //!< Rotation of charactor (..90..)
  140. public int widAdjustSpace; //!< Adjust Spacing (0..1)
  141. public int widAdjustSize; //!< Adjust Size of Characters (0..1)
  142. public int widFilter; //!< Filter (0..40)
  143. public int widCharSizeX; //!< Character Size in X (15.. 60)
  144. public int widCharSizeY; //!< Character Size in Y (27..108)
  145. public int widCharPosX; //!< Character Position in X (64..960)
  146. public int widCharPosY; //!< Character Position in Y (64..304)
  147. public WID_ROI widRoi; //!< Region of Interrest
  148. };
  149. /**********************************************************************************************//**
  150. * @class WID_OCR
  151. *
  152. * @brief WID120 OCR parameter
  153. *
  154. * @author MAI
  155. * @date 16.04.2020
  156. **************************************************************************************************/
  157. public class WID_OCR
  158. {
  159. public string widFontName; //!< Name of font "semi_5x9","semi_org","semi_lin","ocra"
  160. public string widFielding; //!< Fielding of String "aannnn-nn-cc"
  161. public string widFormat; //!< Fielding of String "++++++++++++"
  162. public string widResult; //!< Result of String "Reading Result"
  163. public int widMinSimilarity; //!< minimum Similarity (50..75)
  164. public int widAccSimilarity; //!< accepted Similarity (85..99)
  165. public int widSpacing; //!< Spacing of Character (80..200)
  166. public int widRotation; //!< Rotation of charactor (..90..)
  167. public int widAdjustSpace; //!< Adjust Spacing (0..1)
  168. public int widAdjustSize; //!< Adjust Size of Characters (0..1)
  169. public int widFilter; //!< Filter (0..40)
  170. public int widCharSizeX; //!< Character Size in X (15.. 60)
  171. public int widCharSizeY; //!< Character Size in Y (27..108)
  172. public int widCharPosX; //!< Character Position in X (64..960)
  173. public int widCharPosY; //!< Character Position in Y (64..304)
  174. public WID_ROI widRoi; //!< Region of Interrest
  175. public WID_OCR() { }
  176. public unsafe WID_OCR(WID_OCR_Unsafe s)
  177. {
  178. widFontName = TypeConversion.FixedByteToString(s.widFontName);
  179. widFielding = TypeConversion.FixedByteToString(s.widFielding);
  180. widFormat = TypeConversion.FixedByteToString(s.widFormat);
  181. widResult = TypeConversion.FixedByteToString(s.widResult);
  182. widMinSimilarity = s.widMinSimilarity;
  183. widAccSimilarity = s.widAccSimilarity;
  184. widSpacing = s.widSpacing;
  185. widRotation = s.widRotation;
  186. widAdjustSpace = s.widAdjustSpace;
  187. widAdjustSize = s.widAdjustSize;
  188. widFilter = s.widFilter;
  189. widCharSizeX = s.widCharSizeX;
  190. widCharSizeY = s.widCharSizeY;
  191. widCharPosX = s.widCharPosX;
  192. widCharPosY = s.widCharPosY;
  193. widRoi = s.widRoi;
  194. }
  195. public unsafe WID_OCR_Unsafe ToUnsafeStruct()
  196. {
  197. WID_OCR_Unsafe s = new WID_OCR_Unsafe();
  198. TypeConversion.StringToFixedByte(widFontName, s.widFontName, 12);
  199. TypeConversion.StringToFixedByte(widFielding, s.widFielding, 32);
  200. TypeConversion.StringToFixedByte(widFormat, s.widFormat, 32);
  201. TypeConversion.StringToFixedByte(widResult, s.widResult, 32);
  202. s.widMinSimilarity = widMinSimilarity;
  203. s.widAccSimilarity = widAccSimilarity;
  204. s.widSpacing = widSpacing;
  205. s.widRotation = widRotation;
  206. s.widAdjustSpace = widAdjustSpace;
  207. s.widAdjustSize = widAdjustSize;
  208. s.widFilter = widFilter;
  209. s.widCharSizeX = widCharSizeX;
  210. s.widCharSizeY = widCharSizeY;
  211. s.widCharPosX = widCharPosX;
  212. s.widCharPosY = widCharPosY;
  213. s.widRoi = widRoi;
  214. return s;
  215. }
  216. }
  217. // ====================================================================
  218. /// <summary>
  219. /// Type Conversion class.
  220. /// </summary>
  221. // ====================================================================
  222. public static class TypeConversion
  223. {
  224. // ====================================================================
  225. /// <summary>
  226. /// Convert from unsafe fixed byte array to managed string
  227. /// </summary>
  228. /// <param name="sender">fixed byte array</param>
  229. /// <returns>string</returns>
  230. // ====================================================================
  231. public static unsafe string FixedByteToString(byte* sender)
  232. {
  233. List<byte> data = new List<byte>();
  234. for (byte* counter = sender; *counter != 0; counter++)
  235. {
  236. data.Add(*counter);
  237. }
  238. return System.Text.Encoding.ASCII.GetString(data.ToArray()).Trim('\0');
  239. }
  240. // ====================================================================
  241. /// <summary>
  242. /// Convert from managed string to unsafe fixed byte array
  243. /// </summary>
  244. /// <param name="value">input string</param>
  245. /// <param name="result">fixed byte array (output)</param>
  246. // ====================================================================
  247. public static unsafe void StringToFixedByte(string value, byte* result, int length)
  248. {
  249. if (string.IsNullOrEmpty(value)) value = "";
  250. byte[] valueBytes = System.Text.Encoding.ASCII.GetBytes(value);
  251. byte* counter = result;
  252. for (int index = 0; index < length; index++)
  253. {
  254. if (index < value.Length) *counter = valueBytes[index];
  255. else *counter = 0x00;
  256. counter++;
  257. }
  258. }
  259. }
  260. /**********************************************************************************************//**
  261. * @struct Unsafe WID_BCR
  262. *
  263. * @brief WID120 Barcode Parameter (Internal used by <see cref="Wid110LibUser.Wid110Lib"/>
  264. *
  265. * @author Jg
  266. * @date 10.05.2017
  267. **************************************************************************************************
  268. * 16.04.2020 MAI Changed char array to fixed byte. Added StructLayout attribute.
  269. **************************************************************************************************/
  270. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  271. public unsafe struct WID_BCR_Unsafe
  272. {
  273. public fixed byte widFormat[32]; //!< Format of String "++++++++++++"
  274. public fixed byte widConversion[48]; //!< IBM- Conversion Table ("000102030405060708091011121314151517")
  275. public int widIBM_RtoL; //!< Activate IBM BC412 (0..1)
  276. public int widIBM_LtoR; //!< Activate IBM BC412 (0..1)
  277. public int widIBMConversion; //!< IBM- Conversion (0..2) None,Base 35,Custom A, Custom V, Custom R, Programmable
  278. public int widSemi; //!< Activate Semi Barcode (0..1)
  279. public int widTIConversion; //!< TI Conversion (0..3) None,Base 35, Custom, Custom Checksum
  280. public int widBarCodeLength; //!< Code Length (0..18) 0=auto
  281. public int widSeparator; //!< Separator Character (0..4) none,DASH,POINT,SPACE,HASH
  282. public int widDigits; //!< Wafer Number (0..3) 2 digits, suppress leading zero, 3 digits
  283. public int widEnableAltis; //!< Enable Altis (0..1)
  284. public int widCheckSum; //!< Show Check Character (0..1)
  285. public int widResolution; //!< Resolution of Barcode (0..2) Standard, High Resolution, Standard & High Resolution
  286. public int widLowContrast; //!< Contrast of Barcode (0..1) Activate Low Contrast Codes
  287. public WID_ROI widRoi; //!< Region of Interrest
  288. };
  289. /**********************************************************************************************//**
  290. * @class WID_BCR
  291. *
  292. * @brief WID120 Barcode parameter
  293. *
  294. * @author MAI
  295. * @date 16.04.2020
  296. **************************************************************************************************/
  297. public class WID_BCR
  298. {
  299. public string widFormat; //!< Format of String "++++++++++++"
  300. public string widConversion; //!< IBM- Conversion Table ("000102030405060708091011121314151517")
  301. public int widIBM_RtoL; //!< Activate IBM BC412 (0..1)
  302. public int widIBM_LtoR; //!< Activate IBM BC412 (0..1)
  303. public int widIBMConversion; //!< IBM- Conversion (0..2) None,Base 35,Custom A, Custom V, Custom R, Programmable
  304. public int widSemi; //!< Activate Semi Barcode (0..1)
  305. public int widTIConversion; //!< TI Conversion (0..3) None,Base 35, Custom, Custom Checksum
  306. public int widBarCodeLength; //!< Code Length (0..18) 0=auto
  307. public int widSeparator; //!< Separator Character (0..4) none,DASH,POINT,SPACE,HASH
  308. public int widDigits; //!< Wafer Number (0..3) 2 digits, suppress leading zero, 3 digits
  309. public int widEnableAltis; //!< Enable Altis (0..1)
  310. public int widCheckSum; //!< Show Check Character (0..1)
  311. public int widResolution; //!< Resolution of Barcode (0..2) Standard, High Resolution, Standard & High Resolution
  312. public int widLowContrast; //!< Contrast of Barcode (0..1) Activate Low Contrast Codes
  313. public WID_ROI widRoi; //!< Region of Interrest
  314. public WID_BCR() { }
  315. public unsafe WID_BCR(WID_BCR_Unsafe s)
  316. {
  317. widFormat = TypeConversion.FixedByteToString(s.widFormat);
  318. widConversion = TypeConversion.FixedByteToString(s.widConversion);
  319. widIBM_RtoL = s.widIBM_RtoL;
  320. widIBM_LtoR = s.widIBM_LtoR;
  321. widIBMConversion = s.widIBMConversion;
  322. widSemi = s.widSemi;
  323. widTIConversion = s.widTIConversion;
  324. widBarCodeLength = s.widBarCodeLength;
  325. widSeparator = s.widSeparator;
  326. widDigits = s.widDigits;
  327. widEnableAltis = s.widEnableAltis;
  328. widCheckSum = s.widCheckSum;
  329. widResolution = s.widResolution;
  330. widLowContrast = s.widLowContrast;
  331. widRoi = s.widRoi;
  332. }
  333. public unsafe WID_BCR_Unsafe ToUnsafeStruct()
  334. {
  335. WID_BCR_Unsafe s = new WID_BCR_Unsafe();
  336. TypeConversion.StringToFixedByte(widFormat, s.widFormat, 32);
  337. TypeConversion.StringToFixedByte(widConversion, s.widConversion, 48);
  338. s.widIBM_RtoL = widIBM_RtoL;
  339. s.widIBM_LtoR = widIBM_LtoR;
  340. s.widIBMConversion = widIBMConversion;
  341. s.widSemi = widSemi;
  342. s.widTIConversion = widTIConversion;
  343. s.widBarCodeLength = widBarCodeLength;
  344. s.widSeparator = widSeparator;
  345. s.widDigits = widDigits;
  346. s.widEnableAltis = widEnableAltis;
  347. s.widCheckSum = widCheckSum;
  348. s.widResolution = widResolution;
  349. s.widLowContrast = widLowContrast;
  350. s.widRoi = widRoi;
  351. return s;
  352. }
  353. }
  354. /**********************************************************************************************//**
  355. * @struct Unsafe WID_DMR
  356. *
  357. * @brief WID120 2D-Code Parameter (Internal used by <see cref="Wid110LibUser.Wid110Lib"/>
  358. *
  359. * @author Jg
  360. * @date 10.05.2017
  361. **************************************************************************************************
  362. * 16.04.2020 MAI Changed char array to fixed byte. Added StructLayout attribute.
  363. **************************************************************************************************/
  364. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  365. public unsafe struct WID_DMR_Unsafe
  366. {
  367. public int widSymbol; //!< Activate Code Type (0 = DataMatrix, 1 = QR-Code
  368. public int widLinNrm; //!< linear Code (normal) (0/1) off/on
  369. public int widLinInv; //!< linear Code (invers) (0/1) off/on
  370. public int widDotNrm; //!< Punkt Code (normal) (0/1) off/on
  371. public int widDotInv; //!< Punkt Code (invers) (0/1) off/on
  372. public int widCodeType; //!< Activate Code Type (0/1) normal/mirrored
  373. public int widCodeSize; //!< Module Size of Code (0..3) large, semi, small, tiny
  374. public fixed byte widFormat[32]; //!< Format of String "++++++++++++"
  375. public WID_ROI widRoi; //!< Region of Interrest
  376. };
  377. /**********************************************************************************************//**
  378. * @class WID_DMR
  379. *
  380. * @brief WID120 2D-Code parameter
  381. *
  382. * @author MAI
  383. * @date 16.04.2020
  384. **************************************************************************************************/
  385. public class WID_DMR
  386. {
  387. public int widSymbol; //!< Activate Code Type (0 = DataMatrix, 1 = QR-Code
  388. public int widLinNrm; //!< linear Code (normal) (0/1) off/on
  389. public int widLinInv; //!< linear Code (invers) (0/1) off/on
  390. public int widDotNrm; //!< Punkt Code (normal) (0/1) off/on
  391. public int widDotInv; //!< Punkt Code (invers) (0/1) off/on
  392. public int widCodeType; //!< Activate Code Type (0/1) normal/mirrored
  393. public int widCodeSize; //!< Module Size of Code (0..3) large, semi, small, tiny
  394. public string widFormat; //!< Format of String "++++++++++++"
  395. public WID_ROI widRoi; //!< Region of Interrest
  396. public WID_DMR() { }
  397. public unsafe WID_DMR(WID_DMR_Unsafe s)
  398. {
  399. widSymbol = s.widSymbol;
  400. widLinNrm = s.widLinNrm;
  401. widLinInv = s.widLinInv;
  402. widDotNrm = s.widDotNrm;
  403. widDotInv = s.widDotInv;
  404. widCodeType = s.widCodeType;
  405. widCodeSize = s.widCodeSize;
  406. widFormat = TypeConversion.FixedByteToString(s.widFormat);
  407. widRoi = s.widRoi;
  408. }
  409. public unsafe WID_DMR_Unsafe ToUnsafeStruct()
  410. {
  411. WID_DMR_Unsafe s = new WID_DMR_Unsafe();
  412. s.widSymbol = widSymbol;
  413. s.widLinNrm = widLinNrm;
  414. s.widLinInv = widLinInv;
  415. s.widDotNrm = widDotNrm;
  416. s.widDotInv = widDotInv;
  417. s.widCodeType = widCodeType;
  418. s.widCodeSize = widCodeSize;
  419. TypeConversion.StringToFixedByte(widFormat, s.widFormat, 32);
  420. s.widRoi = widRoi;
  421. return s;
  422. }
  423. }