Wid110Lib.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. // ============================================================================
  2. // Copyright (c) 2010 IOSS GmbH
  3. // All Rights Reserved.
  4. // ============================================================================
  5. // ============================================================================
  6. //
  7. // Wid110Lib - WID110 C# based library
  8. //
  9. // ============================================================================
  10. //
  11. // File: Wid110Lib.cs Type: Implementation
  12. //
  13. // Date: 05.02.2010 Last Change: 09.11.2011
  14. //
  15. // Author: Thomas M. Schlageter
  16. // Silvio Robel
  17. //
  18. // Methods: Wid110Lib - constructor
  19. // ~Wid110Lib - destructor
  20. //
  21. // FCreateDll - create WID110Lib instance
  22. // FDestroyDll - destroy WID110Lib instance
  23. // FExit - terminate connection and exit
  24. // FGetCodeQualityBCR - get code qualitiy for BCR codes
  25. // FGetCodeQualityDMR - get code qualitiy for DMR codes
  26. // FGetCodeQualityLast - get code qualitiy for LAST code
  27. // FGetCodeQualityOCR - get code qualitiy for OCR codes
  28. // FGetErrorDescription - get error description
  29. // FGetLastError - get the last error number
  30. // FGetVersionParam - return sensor/interface version
  31. // FGetVersion - return library version
  32. // FGetWaferId - get the last BCR/OCR decode result
  33. // FInit - initialize library and connect
  34. // FIsInitialized - check for initialized state
  35. // FLiveGetImage - take single image with parameters
  36. // FLiveRead - perform a live read
  37. // FLoadRecipes - load parameters by sending a file
  38. // FLoadRecipesToSlot - load parameters by sending a file
  39. // FProcessGetImage - get image from process trigger
  40. // FProcessRead - perform a process read
  41. // FSwitchOverlay - switch overlay on/off
  42. // FGetCodeTime - get certain time parameter
  43. //
  44. //
  45. // Auxiliary methods:
  46. //
  47. // getErrno - get error number
  48. // getLastExcp - get the last exception message
  49. // getReadOK - get result read state
  50. // getTmpImage - return temporary image name
  51. // isException - return exception state
  52. //
  53. // ============================================================================
  54. using System;
  55. using System.Collections;
  56. using System.Collections.Generic;
  57. using System.Data;
  58. using System.Reflection;
  59. using System.Text;
  60. using System.Runtime.InteropServices;
  61. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders.IOSS
  62. {
  63. public class Wid110LibV7
  64. {
  65. // ====================================================================
  66. /// <summary>
  67. /// Private member variables.
  68. /// </summary>
  69. // ====================================================================
  70. private string version;
  71. private string versParam;
  72. private string tmpImage = Wid110LibConstV7.tmpImage;
  73. private string lastExcp;
  74. private int errno = Wid110LibConstV7.ecNone;
  75. private int readOK = Wid110LibConstV7.rcError;
  76. private IntPtr dll;
  77. // ====================================================================
  78. /// <summary>
  79. /// Imported method prototypes.
  80. /// </summary>
  81. // ====================================================================
  82. [DllImport("wid110Lib.dll")]
  83. public static extern IntPtr FuncCreateDll();
  84. [DllImport("wid110Lib.dll")]
  85. public static extern int FuncDestroyDll(IntPtr objptr);
  86. [DllImport("wid110Lib.dll")]
  87. public static extern int FuncInit(IntPtr objptr,
  88. string cpIPAddress);
  89. [DllImport("wid110Lib.dll")]
  90. public static extern int FuncIsInitialized(IntPtr objptr);
  91. [DllImport("wid110Lib.dll")]
  92. public static extern int FuncGetVersionParam(IntPtr objptr,
  93. StringBuilder cVersion,
  94. int nMaxLen);
  95. [DllImport("wid110Lib.dll")]
  96. public static extern int FuncGetVersion(IntPtr objptr,
  97. StringBuilder cVersion,
  98. int nMaxLen);
  99. [DllImport("wid110Lib.dll")]
  100. public static extern int FuncSwitchOverlay(IntPtr objptr,
  101. int bOnOff);
  102. [DllImport("wid110Lib.dll")]
  103. public static extern int FuncExit(IntPtr objptr);
  104. [DllImport("wid110Lib.dll")]
  105. public static extern int FuncLiveGetImage(IntPtr objptr,
  106. string cpFileName,
  107. int nChannel,
  108. int nIntensity,
  109. int nColor);
  110. [DllImport("wid110Lib.dll")]
  111. public static extern int FuncLiveRead(IntPtr objptr);
  112. [DllImport("wid110Lib.dll")]
  113. public static extern int FuncLiveGetImageRead(IntPtr objptr,
  114. string cpFileName,
  115. int nChannel,
  116. int nIntensity,
  117. int nColor);
  118. [DllImport("wid110Lib.dll")]
  119. public static extern int FuncProcessRead(IntPtr objptr);
  120. [DllImport("wid110Lib.dll")]
  121. public static extern int FuncProcessGetImage(IntPtr objptr,
  122. string cpFileName,
  123. int nTypeImage);
  124. [DllImport("wid110Lib.dll")]
  125. public static extern int FuncGetWaferId(IntPtr objptr,
  126. StringBuilder cReadId,
  127. int nMaxLen,
  128. IntPtr bReadSuccessful);
  129. [DllImport("wid110Lib.dll")]
  130. public static extern int FuncGetCodeQualityOCR(IntPtr objptr,
  131. IntPtr pnQuality);
  132. [DllImport("wid110Lib.dll")]
  133. public static extern int FuncGetCodeQualityBCR(IntPtr objptr,
  134. IntPtr pnQuality);
  135. [DllImport("wid110Lib.dll")]
  136. public static extern int FuncGetCodeQualityDMR(IntPtr objptr,
  137. IntPtr pnQuality);
  138. [DllImport("wid110Lib.dll")]
  139. public static extern int FuncGetCodeQualityLast(IntPtr objptr,
  140. IntPtr pnQuality);
  141. [DllImport("wid110Lib.dll")]
  142. public static extern int FuncGetCodeTime(IntPtr objptr,
  143. IntPtr pnTime);
  144. [DllImport("wid110Lib.dll")]
  145. public static extern int FuncLoadRecipes(IntPtr objptr,
  146. int nTimeType,
  147. IntPtr pnTime);
  148. [DllImport("wid110Lib.dll")]
  149. public static extern int FuncLoadRecipes(IntPtr objptr,
  150. string cpFilePath,
  151. string cpFilename);
  152. [DllImport("wid110Lib.dll")]
  153. public static extern int FuncLoadRecipesToSlot(IntPtr objptr,
  154. string cpFilePath,
  155. string cpFilename,
  156. int nSlot);
  157. [DllImport("wid110Lib.dll")]
  158. public static extern int FuncGetLastError(IntPtr objptr);
  159. [DllImport("wid110Lib.dll")]
  160. public static extern int FuncGetErrorDescription(IntPtr objptr,
  161. int nError,
  162. StringBuilder strText,
  163. int nTextLength);
  164. // ====================================================================
  165. /// <summary>
  166. /// Constructor: Initialize WID C# Library.
  167. /// </summary>
  168. // ====================================================================
  169. public Wid110LibV7()
  170. {
  171. dll = FCreateDll();
  172. }
  173. // ====================================================================
  174. /// <summary>
  175. /// Destructor: Remove WID C# Library.
  176. /// </summary>
  177. // ====================================================================
  178. ~Wid110LibV7()
  179. {
  180. FDestroyDll(dll);
  181. }
  182. // ====================================================================
  183. /// <summary>
  184. /// Create WID C# Library instance.
  185. /// </summary>
  186. /// <return> DLL if created, NULL upon error.</return>
  187. // ====================================================================
  188. private IntPtr FCreateDll()
  189. {
  190. IntPtr d = IntPtr.Zero;
  191. lastExcp = "";
  192. errno = Wid110LibConstV7.ecNone;
  193. try
  194. {
  195. d = FuncCreateDll();
  196. }
  197. catch (Exception e)
  198. {
  199. lastExcp = e.ToString();
  200. }
  201. return d;
  202. }
  203. // ====================================================================
  204. /// <summary>
  205. /// Destroy WID C# Library instance.
  206. /// </summary>
  207. /// <param name="dll"> DLL to destroy.</param>
  208. /// <return> true if destroyed.</return>
  209. // ====================================================================
  210. private bool FDestroyDll(IntPtr dll)
  211. {
  212. bool ok = false;
  213. errno = Wid110LibConstV7.ecNone;
  214. lastExcp = "";
  215. try
  216. {
  217. switch (FuncDestroyDll(dll))
  218. {
  219. case Wid110LibConstV7.rcError:
  220. {
  221. break;
  222. }
  223. case Wid110LibConstV7.rcInvObj:
  224. {
  225. errno = Wid110LibConstV7.ecInvObj;
  226. break;
  227. }
  228. case Wid110LibConstV7.rcNoError:
  229. {
  230. ok = true;
  231. break;
  232. }
  233. }
  234. }
  235. catch (Exception e)
  236. {
  237. lastExcp = e.ToString();
  238. }
  239. return ok;
  240. }
  241. // ====================================================================
  242. /// <summary>
  243. /// Initialize library and connect to IP.
  244. /// </summary>
  245. /// <param name="ip"> IP to connect.</param>
  246. /// <return> true if connected.</return>
  247. // ====================================================================
  248. public bool FInit(string ip)
  249. {
  250. bool isInit = false;
  251. errno = Wid110LibConstV7.ecNone;
  252. lastExcp = "";
  253. try
  254. {
  255. switch (FuncInit(dll, ip))
  256. {
  257. case Wid110LibConstV7.rcError:
  258. {
  259. break;
  260. }
  261. case Wid110LibConstV7.rcInvObj:
  262. {
  263. errno = Wid110LibConstV7.ecInvObj;
  264. break;
  265. }
  266. case Wid110LibConstV7.rcNoError:
  267. {
  268. isInit = true;
  269. break;
  270. }
  271. }
  272. }
  273. catch (Exception e)
  274. {
  275. lastExcp = e.ToString();
  276. }
  277. return isInit;
  278. }
  279. // ====================================================================
  280. /// <summary>
  281. /// Check library state.
  282. /// </summary>
  283. /// <return> true if initialized.</return>
  284. // ====================================================================
  285. public bool FIsInitialized()
  286. {
  287. if (dll == IntPtr.Zero)
  288. {
  289. errno = Wid110LibConstV7.ecInvObj;
  290. return false;
  291. }
  292. bool isInit = false;
  293. errno = Wid110LibConstV7.ecNone;
  294. lastExcp = "";
  295. try
  296. {
  297. switch (FuncIsInitialized(dll))
  298. {
  299. case Wid110LibConstV7.rcError:
  300. {
  301. break;
  302. }
  303. case Wid110LibConstV7.rcInvObj:
  304. {
  305. errno = Wid110LibConstV7.ecInvObj;
  306. break;
  307. }
  308. case Wid110LibConstV7.rcNoError:
  309. {
  310. isInit = true;
  311. break;
  312. }
  313. }
  314. }
  315. catch (Exception e)
  316. {
  317. lastExcp = e.ToString();
  318. }
  319. return isInit;
  320. }
  321. // ====================================================================
  322. /// <summary>
  323. /// Terminate connection.
  324. /// </summary>
  325. /// <return> true if disconnected.</return>
  326. // ====================================================================
  327. public bool FExit()
  328. {
  329. errno = Wid110LibConstV7.ecNone;
  330. lastExcp = "";
  331. try
  332. {
  333. switch (FuncExit(dll))
  334. {
  335. case Wid110LibConstV7.rcError:
  336. case Wid110LibConstV7.rcNoError:
  337. {
  338. break;
  339. }
  340. case Wid110LibConstV7.rcInvObj:
  341. {
  342. errno = Wid110LibConstV7.ecInvObj;
  343. break;
  344. }
  345. }
  346. }
  347. catch (Exception e)
  348. {
  349. lastExcp = e.ToString();
  350. }
  351. return true; // if FuncExit() fails or not, lib is always "not init"
  352. }
  353. // ====================================================================
  354. /// <summary>
  355. /// Get library version.
  356. /// </summary>
  357. /// <param name="v"> WID110 library version.</param>
  358. // ====================================================================
  359. public string FGetVersion()
  360. {
  361. StringBuilder sb = new StringBuilder("", Wid110LibConstV7.versLenCS);
  362. errno = Wid110LibConstV7.ecNone;
  363. lastExcp = "";
  364. try
  365. {
  366. switch (FuncGetVersion(dll, sb, Wid110LibConstV7.versLenC))
  367. {
  368. case Wid110LibConstV7.rcError:
  369. {
  370. version = ""; // reset string if error occured
  371. break;
  372. }
  373. case Wid110LibConstV7.rcInvObj:
  374. {
  375. errno = Wid110LibConstV7.ecInvObj;
  376. break;
  377. }
  378. case Wid110LibConstV7.rcNoError:
  379. {
  380. version = sb.ToString(); // copy string if lib function had no error
  381. break;
  382. }
  383. }
  384. }
  385. catch (Exception e)
  386. {
  387. lastExcp = e.ToString();
  388. }
  389. return version;
  390. }
  391. // ====================================================================
  392. /// <summary>
  393. /// Get sensor interface version.
  394. /// </summary>
  395. /// <return> WID110 interface version.</return>
  396. // ====================================================================
  397. public string FGetVersionParam()
  398. {
  399. StringBuilder sb = new StringBuilder("", Wid110LibConstV7.versLenCS);
  400. errno = Wid110LibConstV7.ecNone;
  401. lastExcp = "";
  402. try
  403. {
  404. switch (FuncGetVersionParam(dll, sb, Wid110LibConstV7.versLenC))
  405. {
  406. case Wid110LibConstV7.rcError:
  407. {
  408. versParam = ""; // reset string if error occured
  409. break;
  410. }
  411. case Wid110LibConstV7.rcInvObj:
  412. {
  413. errno = Wid110LibConstV7.ecInvObj;
  414. break;
  415. }
  416. case Wid110LibConstV7.rcNoError:
  417. {
  418. versParam = sb.ToString(); // copy string if lib function had no error
  419. break;
  420. }
  421. }
  422. }
  423. catch (Exception e)
  424. {
  425. lastExcp = e.ToString();
  426. }
  427. return versParam;
  428. }
  429. // ====================================================================
  430. /// <summary>
  431. /// Change overlay flag.
  432. /// </summary>
  433. /// <param name="o"> overlay flag.</param>
  434. /// <return> true if changed.</return>
  435. // ====================================================================
  436. public bool FSwitchOverlay(bool o)
  437. {
  438. bool ok = false;
  439. int ovl = (o) ? 1 : 0;
  440. errno = Wid110LibConstV7.ecNone;
  441. lastExcp = "";
  442. try
  443. {
  444. switch (FuncSwitchOverlay(dll, ovl))
  445. {
  446. case Wid110LibConstV7.rcError:
  447. {
  448. break;
  449. }
  450. case Wid110LibConstV7.rcInvObj:
  451. {
  452. errno = Wid110LibConstV7.ecInvObj;
  453. break;
  454. }
  455. case Wid110LibConstV7.rcNoError:
  456. {
  457. ok = true;
  458. break;
  459. }
  460. }
  461. }
  462. catch (Exception e)
  463. {
  464. lastExcp = e.ToString();
  465. }
  466. return ok;
  467. }
  468. // ====================================================================
  469. /// <summary>
  470. /// Perform a live read using the temporary settings from an
  471. /// earlier 'FLiveGetImage()' call.
  472. /// </summary>
  473. /// <return> true if done.</return>
  474. // ====================================================================
  475. public bool FLiveRead()
  476. {
  477. bool ok = false;
  478. errno = Wid110LibConstV7.ecNone;
  479. lastExcp = "";
  480. try
  481. {
  482. switch (FuncLiveRead(dll))
  483. {
  484. case Wid110LibConstV7.rcError:
  485. {
  486. break;
  487. }
  488. case Wid110LibConstV7.rcInvObj:
  489. {
  490. errno = Wid110LibConstV7.ecInvObj;
  491. break;
  492. }
  493. case Wid110LibConstV7.rcNoError:
  494. {
  495. ok = true;
  496. break;
  497. }
  498. }
  499. }
  500. catch (Exception e)
  501. {
  502. lastExcp = e.ToString();
  503. }
  504. return ok;
  505. }
  506. // ====================================================================
  507. /// <summary>
  508. /// Perform a live read using the given parameters, and decode.
  509. /// </summary>
  510. /// <param name="name"> name to save image to.</param>
  511. /// <param name="channel"> illumination channel.</param>
  512. /// <param name="intensity"> illumination intensity.</param>
  513. /// <param name="color"> illumination color.</param>
  514. /// <return> true if done.</return>
  515. // ====================================================================
  516. public bool FLiveRead(string name,
  517. int channel,
  518. int intensity,
  519. int color)
  520. {
  521. bool ok = false;
  522. errno = Wid110LibConstV7.ecNone;
  523. lastExcp = "";
  524. try
  525. {
  526. switch (FuncLiveGetImageRead(dll, name, channel, intensity, color))
  527. {
  528. case Wid110LibConstV7.rcError:
  529. break;
  530. case Wid110LibConstV7.rcInvObj:
  531. errno = Wid110LibConstV7.ecInvObj;
  532. break;
  533. case Wid110LibConstV7.rcNoError:
  534. ok = true;
  535. break;
  536. }
  537. }
  538. catch (Exception e)
  539. {
  540. lastExcp = e.ToString();
  541. }
  542. return ok;
  543. }
  544. // ====================================================================
  545. /// <summary>
  546. /// Perform a process read..
  547. /// </summary>
  548. /// <return> true if done.</return>
  549. // ====================================================================
  550. public bool FProcessRead()
  551. {
  552. bool ok = false;
  553. errno = Wid110LibConstV7.ecNone;
  554. lastExcp = "";
  555. try
  556. {
  557. switch (FuncProcessRead(dll))
  558. {
  559. case Wid110LibConstV7.rcError:
  560. {
  561. break;
  562. }
  563. case Wid110LibConstV7.rcInvObj:
  564. {
  565. errno = Wid110LibConstV7.ecInvObj;
  566. break;
  567. }
  568. case Wid110LibConstV7.rcNoError:
  569. {
  570. ok = true;
  571. break;
  572. }
  573. }
  574. }
  575. catch (Exception e)
  576. {
  577. lastExcp = e.ToString();
  578. }
  579. return ok;
  580. }
  581. // ====================================================================
  582. /// <summary>
  583. /// Get code quality for OCR codes.
  584. /// </summary>
  585. /// <return> code quality, or rsltNoCodeQuality upon failure.</return>
  586. // ====================================================================
  587. public int FGetCodeQualityOCR()
  588. {
  589. IntPtr q = Marshal.AllocHGlobal(sizeof(int));
  590. int rc = Wid110LibConstV7.rsltNoCodeQuality;
  591. errno = Wid110LibConstV7.ecNone;
  592. lastExcp = "";
  593. try
  594. {
  595. switch (FuncGetCodeQualityOCR(dll, q))
  596. {
  597. case Wid110LibConstV7.rcError:
  598. {
  599. break;
  600. }
  601. case Wid110LibConstV7.rcInvObj:
  602. {
  603. errno = Wid110LibConstV7.ecInvObj;
  604. break;
  605. }
  606. case Wid110LibConstV7.rcNoError:
  607. {
  608. rc = Marshal.ReadInt32(q);
  609. break;
  610. }
  611. }
  612. }
  613. catch (Exception e)
  614. {
  615. lastExcp = e.ToString();
  616. }
  617. Marshal.FreeHGlobal(q);
  618. return rc;
  619. }
  620. // ====================================================================
  621. /// <summary>
  622. /// Get code quality for BCR codes.
  623. /// </summary>
  624. /// <return> code quality, or rsltNoCodeQuality upon failure.</return>
  625. // ====================================================================
  626. public int FGetCodeQualityBCR()
  627. {
  628. IntPtr q = Marshal.AllocHGlobal(sizeof(int));
  629. int rc = Wid110LibConstV7.rsltNoCodeQuality;
  630. errno = Wid110LibConstV7.ecNone;
  631. lastExcp = "";
  632. try
  633. {
  634. switch (FuncGetCodeQualityBCR(dll, q))
  635. {
  636. case Wid110LibConstV7.rcError:
  637. {
  638. break;
  639. }
  640. case Wid110LibConstV7.rcInvObj:
  641. {
  642. errno = Wid110LibConstV7.ecInvObj;
  643. break;
  644. }
  645. case Wid110LibConstV7.rcNoError:
  646. {
  647. rc = Marshal.ReadInt32(q);
  648. break;
  649. }
  650. }
  651. }
  652. catch (Exception e)
  653. {
  654. lastExcp = e.ToString();
  655. }
  656. Marshal.FreeHGlobal(q);
  657. return rc;
  658. }
  659. // ====================================================================
  660. /// <summary>
  661. /// Get code quality for DMR codes.
  662. /// </summary>
  663. /// <return> code quality, or rsltNoCodeQuality upon failure.</return>
  664. // ====================================================================
  665. public int FGetCodeQualityDMR()
  666. {
  667. IntPtr q = Marshal.AllocHGlobal(sizeof(int));
  668. int rc = Wid110LibConstV7.rsltNoCodeQuality;
  669. errno = Wid110LibConstV7.ecNone;
  670. lastExcp = "";
  671. try
  672. {
  673. switch (FuncGetCodeQualityDMR(dll, q))
  674. {
  675. case Wid110LibConstV7.rcError:
  676. {
  677. break;
  678. }
  679. case Wid110LibConstV7.rcInvObj:
  680. {
  681. errno = Wid110LibConstV7.ecInvObj;
  682. break;
  683. }
  684. case Wid110LibConstV7.rcNoError:
  685. {
  686. rc = Marshal.ReadInt32(q);
  687. break;
  688. }
  689. }
  690. }
  691. catch (Exception e)
  692. {
  693. lastExcp = e.ToString();
  694. }
  695. Marshal.FreeHGlobal(q);
  696. return rc;
  697. }
  698. // ====================================================================
  699. /// <summary>
  700. /// Get code quality for LAST code.
  701. /// </summary>
  702. /// <return> code quality, or rsltNoCodeQuality upon failure.</return>
  703. // ====================================================================
  704. public int FGetCodeQualityLast()
  705. {
  706. IntPtr q = Marshal.AllocHGlobal(sizeof(int));
  707. int rc = Wid110LibConstV7.rsltNoCodeQuality;
  708. errno = Wid110LibConstV7.ecNone;
  709. lastExcp = "";
  710. try
  711. {
  712. switch (FuncGetCodeQualityLast(dll, q))
  713. {
  714. case Wid110LibConstV7.rcError:
  715. {
  716. break;
  717. }
  718. case Wid110LibConstV7.rcInvObj:
  719. {
  720. errno = Wid110LibConstV7.ecInvObj;
  721. break;
  722. }
  723. case Wid110LibConstV7.rcNoError:
  724. {
  725. rc = Marshal.ReadInt32(q);
  726. break;
  727. }
  728. }
  729. }
  730. catch (Exception e)
  731. {
  732. lastExcp = e.ToString();
  733. }
  734. Marshal.FreeHGlobal(q);
  735. return rc;
  736. }
  737. // ====================================================================
  738. /// <summary>
  739. /// Retrieve image from last process trigger.
  740. /// </summary>
  741. /// <param name="name"> file name to save image.</param>
  742. /// <param name="type"> 'pvImgBest' or 'pvImgAll'.</param>
  743. /// <return> true if OK.</return>
  744. // ====================================================================
  745. public bool FProcessGetImage(string name,
  746. int type)
  747. {
  748. bool ok = false;
  749. errno = Wid110LibConstV7.ecNone;
  750. lastExcp = "";
  751. try
  752. {
  753. switch (FuncProcessGetImage(dll, name, type))
  754. {
  755. case Wid110LibConstV7.rcError:
  756. {
  757. break;
  758. }
  759. case Wid110LibConstV7.rcInvObj:
  760. {
  761. errno = Wid110LibConstV7.ecInvObj;
  762. break;
  763. }
  764. case Wid110LibConstV7.rcNoError:
  765. {
  766. ok = true;
  767. break;
  768. }
  769. }
  770. }
  771. catch (Exception e)
  772. {
  773. lastExcp = e.ToString();
  774. }
  775. return ok;
  776. }
  777. // ====================================================================
  778. /// <summary>
  779. /// Get the last BCR/OCR/DMR decode result.
  780. /// </summary>
  781. /// <return> the latest read result.</return>
  782. // ====================================================================
  783. public string FGetWaferId()
  784. {
  785. StringBuilder sb = new StringBuilder(Wid110LibConstV7.rsltERROR,
  786. Wid110LibConstV7.rsltLenCS);
  787. string res = Wid110LibConstV7.rsltERROR;
  788. IntPtr pok = Marshal.AllocHGlobal(sizeof(int));
  789. readOK = Wid110LibConstV7.rcError;
  790. errno = Wid110LibConstV7.ecNone;
  791. lastExcp = "";
  792. try
  793. {
  794. switch (FuncGetWaferId(dll, sb, Wid110LibConstV7.rsltLenC, pok))
  795. {
  796. case Wid110LibConstV7.rcError:
  797. {
  798. break;
  799. }
  800. case Wid110LibConstV7.rcInvObj:
  801. {
  802. errno = Wid110LibConstV7.ecInvObj;
  803. break;
  804. }
  805. case Wid110LibConstV7.rcNoError:
  806. {
  807. readOK = Marshal.ReadInt32(pok);
  808. if (1 == readOK)
  809. res = Wid110LibConstV7.rsltREAD + sb.ToString();
  810. else
  811. res = Wid110LibConstV7.rsltNOREAD + sb.ToString();
  812. break;
  813. }
  814. }
  815. }
  816. catch (Exception e)
  817. {
  818. lastExcp = e.ToString();
  819. }
  820. Marshal.FreeHGlobal(pok);
  821. return res;
  822. }
  823. // ====================================================================
  824. /// <summary>
  825. /// Take a single image using the given parameters.
  826. /// </summary>
  827. /// <param name="name"> name to save image to.</param>
  828. /// <param name="channel"> illumination channel.</param>
  829. /// <param name="intensity"> illumination intensity.</param>
  830. /// <param name="color"> illumination color.</param>
  831. /// <return> true if OK.</return>
  832. // ====================================================================
  833. public bool FLiveGetImage(string name,
  834. int channel,
  835. int intensity,
  836. int color)
  837. {
  838. bool ok = false;
  839. errno = Wid110LibConstV7.ecNone;
  840. lastExcp = "";
  841. try
  842. {
  843. switch (FuncLiveGetImage(dll, name, channel, intensity, color))
  844. {
  845. case Wid110LibConstV7.rcError:
  846. {
  847. break;
  848. }
  849. case Wid110LibConstV7.rcInvObj:
  850. {
  851. errno = Wid110LibConstV7.ecInvObj;
  852. break;
  853. }
  854. case Wid110LibConstV7.rcNoError:
  855. {
  856. ok = true;
  857. break;
  858. }
  859. }
  860. }
  861. catch (Exception e)
  862. {
  863. lastExcp = e.ToString();
  864. }
  865. return ok;
  866. }
  867. // ====================================================================
  868. /// <summary>
  869. /// Load process parameter file
  870. /// </summary>
  871. /// <param name="path"> path to file.</param>
  872. /// <param name="file"> file to use.</param>
  873. /// <return> true if OK.</return>
  874. // ====================================================================
  875. public bool FLoadRecipes(string path,
  876. string file)
  877. {
  878. bool ok = false;
  879. errno = Wid110LibConstV7.ecNone;
  880. lastExcp = "";
  881. try
  882. {
  883. switch (FuncLoadRecipes(dll, path, file))
  884. {
  885. case Wid110LibConstV7.rcError:
  886. {
  887. break;
  888. }
  889. case Wid110LibConstV7.rcInvObj:
  890. {
  891. errno = Wid110LibConstV7.ecInvObj;
  892. break;
  893. }
  894. case Wid110LibConstV7.rcNoError:
  895. {
  896. ok = true;
  897. break;
  898. }
  899. }
  900. }
  901. catch (Exception e)
  902. {
  903. lastExcp = e.ToString();
  904. }
  905. return ok;
  906. }
  907. // ====================================================================
  908. /// <summary>
  909. /// Load parameters to a certain parameter slot (if applicable)
  910. /// </summary>
  911. /// <param name="path"> path to file.</param>
  912. /// <param name="file"> file to use.</param>
  913. /// <param name="slot"> slot (only for ocf and led files).</param>
  914. /// <return> true if valid.</return>
  915. // ====================================================================
  916. public bool FLoadRecipesToSlot(string path,
  917. string file,
  918. int slot)
  919. {
  920. bool ok = false;
  921. errno = Wid110LibConstV7.ecNone;
  922. lastExcp = "";
  923. string sPath = path;
  924. if (false == sPath.EndsWith("\\"))
  925. {
  926. sPath += ("\\");
  927. }
  928. try
  929. {
  930. switch (FuncLoadRecipesToSlot(dll, sPath, file, slot))
  931. {
  932. case Wid110LibConstV7.rcError:
  933. {
  934. break;
  935. }
  936. case Wid110LibConstV7.rcInvObj:
  937. {
  938. errno = Wid110LibConstV7.ecInvObj;
  939. break;
  940. }
  941. case Wid110LibConstV7.rcNoError:
  942. {
  943. ok = true;
  944. break;
  945. }
  946. }
  947. }
  948. catch (Exception e)
  949. {
  950. lastExcp = e.ToString();
  951. }
  952. return ok;
  953. }
  954. // ====================================================================
  955. /// <summary>
  956. /// Get code time parameter
  957. /// </summary>
  958. /// <return> overall process time or rsltNoCodeTime upon failure.</return>
  959. // ====================================================================
  960. public int FGetCodeTime()
  961. {
  962. IntPtr q = Marshal.AllocHGlobal(sizeof(int));
  963. int rc = Wid110LibConstV7.rsltNoCodeTime;
  964. errno = Wid110LibConstV7.ecNone;
  965. lastExcp = "";
  966. try
  967. {
  968. switch (FuncGetCodeTime(dll, q))
  969. {
  970. case Wid110LibConstV7.rcError:
  971. {
  972. break;
  973. }
  974. case Wid110LibConstV7.rcInvObj:
  975. {
  976. errno = Wid110LibConstV7.ecInvObj;
  977. break;
  978. }
  979. case Wid110LibConstV7.rcNoError:
  980. {
  981. rc = Marshal.ReadInt32(q);
  982. break;
  983. }
  984. }
  985. }
  986. catch (Exception e)
  987. {
  988. lastExcp = e.ToString();
  989. }
  990. Marshal.FreeHGlobal(q);
  991. return rc;
  992. }
  993. // ====================================================================
  994. /// <summary>
  995. /// Get error description.
  996. /// </summary>
  997. /// <param name="eno"> error number to translate.</param>
  998. /// <return> error description.</return>
  999. // ====================================================================
  1000. public string FGetErrorDescription(int eno)
  1001. {
  1002. StringBuilder sb = new StringBuilder(Wid110LibConstV7.errDESC,
  1003. Wid110LibConstV7.errLen);
  1004. string text = Wid110LibConstV7.errDESC;
  1005. int len = Wid110LibConstV7.errLen;
  1006. errno = Wid110LibConstV7.ecNone;
  1007. lastExcp = "";
  1008. try // if lib handle is invalid, error text is generated as well
  1009. {
  1010. switch (FuncGetErrorDescription(dll, eno, sb, len))
  1011. {
  1012. case Wid110LibConstV7.rcError:
  1013. {
  1014. break;
  1015. }
  1016. case Wid110LibConstV7.rcInvObj:
  1017. {
  1018. errno = Wid110LibConstV7.ecInvObj;
  1019. break;
  1020. }
  1021. case Wid110LibConstV7.rcNoError:
  1022. {
  1023. text = sb.ToString();
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. catch (Exception e)
  1029. {
  1030. lastExcp = e.ToString();
  1031. }
  1032. return text;
  1033. }
  1034. // ====================================================================
  1035. /// <summary>
  1036. /// Get last error number.
  1037. /// </summary>
  1038. /// <return> last error number.</return>
  1039. // ====================================================================
  1040. public int FGetLastError()
  1041. {
  1042. if (Wid110LibConstV7.ecInvObj == errno) // if lib handle was invalid in last call
  1043. { // it is probably still invalid, so
  1044. return errno; // FuncGetLastError() will fail as well
  1045. }
  1046. lastExcp = "";
  1047. try
  1048. {
  1049. errno = FuncGetLastError(dll); // get last internal lib error
  1050. }
  1051. catch (Exception e)
  1052. {
  1053. lastExcp = e.ToString();
  1054. }
  1055. return errno;
  1056. }
  1057. // ====================================================================
  1058. /// <summary>
  1059. /// Get the last error number.
  1060. /// </summary>
  1061. /// <return> last error number.</return>
  1062. // ====================================================================
  1063. public int getErrno()
  1064. {
  1065. return errno;
  1066. }
  1067. // ====================================================================
  1068. /// <summary>
  1069. /// Get the result read state.
  1070. /// </summary>
  1071. /// <return> result read state.</return>
  1072. // ====================================================================
  1073. public int getReadOK()
  1074. {
  1075. return readOK;
  1076. }
  1077. // ====================================================================
  1078. /// <summary>
  1079. /// Get the last exception message.
  1080. /// </summary>
  1081. /// <return> last exception message.</return>
  1082. // ====================================================================
  1083. public string getLastExcp()
  1084. {
  1085. return lastExcp;
  1086. }
  1087. // ====================================================================
  1088. /// <summary>
  1089. /// Get temporary image name.
  1090. /// </summary>
  1091. /// <return> temporary image name.</return>
  1092. // ====================================================================
  1093. public string getTmpImage()
  1094. {
  1095. return tmpImage;
  1096. }
  1097. // ====================================================================
  1098. /// <summary>
  1099. /// Get exception state.
  1100. /// </summary>
  1101. /// <return> true if exception.</return>
  1102. // ====================================================================
  1103. public bool isException()
  1104. {
  1105. return lastExcp.Length != 0;
  1106. }
  1107. }
  1108. }