SemController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. using FEIApiControl;
  2. using OTSDataType;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSModelSharp.ServiceInterface
  12. {
  13. public class SemController : ISemController
  14. {
  15. public static OTSCLRINTERFACE.COTSControlFunExport hw=null;
  16. public static APIClass ApiClass = null;
  17. private static SemController sem = null;
  18. private static bool isFEI = false;
  19. public static SemController GetSEMController()
  20. {
  21. if (FileHelper.GetXMLInformations("SemControllerName") == "FEI")
  22. {
  23. isFEI = true;
  24. }
  25. if (sem == null)
  26. {
  27. sem = new SemController();
  28. }
  29. return sem;
  30. }
  31. private SemController()
  32. {
  33. if (isFEI)
  34. {
  35. ApiClass = new APIClass();
  36. }
  37. else
  38. {
  39. hw = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();
  40. }
  41. }
  42. public bool Connect()
  43. {
  44. if (isFEI)
  45. {
  46. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  47. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  48. if (FEIIP == "" || FEIPORT == "")
  49. {
  50. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  51. return false;
  52. }
  53. if (ApiClass.isConnect())
  54. {
  55. return true;
  56. }
  57. return ApiClass.Connect(FEIIP, FEIPORT);
  58. }
  59. else
  60. {
  61. if (!hw.Init())
  62. {
  63. return false;
  64. }
  65. if (hw.IsConnected())
  66. {
  67. return true;
  68. }
  69. return hw.ConncetSem();
  70. }
  71. }
  72. public bool IsConnected()
  73. {
  74. if (isFEI)
  75. {
  76. return ApiClass.isConnect();
  77. }
  78. else
  79. {
  80. return hw.IsConnected();
  81. }
  82. }
  83. public bool DisConnect()
  84. {
  85. if (isFEI)
  86. {
  87. return ApiClass.DisConnect();
  88. }
  89. else
  90. {
  91. if (hw.IsConnected())
  92. {
  93. return hw.DisconnectSem();
  94. }
  95. return true;
  96. }
  97. }
  98. public bool GetSEMDataGnrFromHw(ref CSEMDataGnr SemDataGnr)
  99. {
  100. double kv = 0, brightness = 0, contrast = 0;
  101. if (isFEI)
  102. {
  103. kv = ApiClass.GetHightVoltage() / 1000;
  104. brightness = ApiClass.GetDetectorBrightness();
  105. contrast = ApiClass.GetDetectorContrast();
  106. }
  107. else
  108. {
  109. if (!hw.IsConnected())
  110. {
  111. return false;
  112. }
  113. hw.GetSemHighTension(ref kv);
  114. hw.GetSemBrightness(ref brightness);
  115. hw.GetSemContrast(ref contrast);
  116. }
  117. SemDataGnr.SetValue(kv, brightness, contrast);
  118. return true;
  119. }
  120. public bool GetMagnification(ref double a_dMagnification)
  121. {
  122. if (isFEI)
  123. {
  124. return ApiClass.GetMagnification(ref a_dMagnification);
  125. }
  126. else
  127. {
  128. if (!hw.IsConnected())
  129. {
  130. return false;
  131. }
  132. return hw.GetSemMagnification(ref a_dMagnification);
  133. }
  134. }
  135. public bool GetScanFieldSize(ref double dScanFieldSizeX, ref double dScanFieldSizeY)
  136. {
  137. if (isFEI)
  138. {
  139. return ApiClass.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
  140. }
  141. else
  142. {
  143. if (!hw.IsConnected())
  144. {
  145. return false;
  146. }
  147. return hw.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
  148. }
  149. }
  150. public bool SetScanFieldSize100(double dScanFieldSizeX, double dScanFieldSizeY)
  151. {
  152. if (isFEI)
  153. {
  154. ApiClass.SetMagnification(100);
  155. return ApiClass.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
  156. }
  157. else
  158. {
  159. if (!hw.IsConnected())
  160. {
  161. return false;
  162. }
  163. Size size = new Size();
  164. hw.SetSemScanField100(size);
  165. dScanFieldSizeX = size.Width;
  166. dScanFieldSizeY = size.Height;
  167. return true;
  168. }
  169. }
  170. public bool GetScanFieldSize100(ref double dScanFieldSizeX, ref double dScanFieldSizeY)
  171. {
  172. if (isFEI)
  173. {
  174. ApiClass.SetMagnification(100);
  175. return ApiClass.GetSemScanFieldSize(ref dScanFieldSizeX, ref dScanFieldSizeY);
  176. }
  177. else
  178. {
  179. if (!hw.IsConnected())
  180. {
  181. return false;
  182. }
  183. Size size = hw.GetSemScanField100();
  184. dScanFieldSizeX = size.Width;
  185. dScanFieldSizeY = size.Height;
  186. return true;
  187. }
  188. }
  189. public bool GetSemPositionXY(ref double a_dPositionX, ref double a_dPositionY, ref double a_dPositionR)
  190. {
  191. if (isFEI)
  192. {
  193. double a_dPositionZ = 0;
  194. double a_dPositionT = 0;
  195. return ApiClass.GetSemPositionXYZRT(ref a_dPositionX, ref a_dPositionY, ref a_dPositionZ, ref a_dPositionR, ref a_dPositionT);
  196. }
  197. else
  198. {
  199. if (!hw.IsConnected())
  200. {
  201. return false;
  202. }
  203. return hw.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR);
  204. }
  205. }
  206. public bool GetWorkingDistance(ref double a_distance)
  207. {
  208. if (isFEI)
  209. {
  210. return ApiClass.GetWorkingDistance(ref a_distance);
  211. }
  212. else
  213. {
  214. if (!hw.IsConnected())
  215. {
  216. return false;
  217. }
  218. return hw.GetSemWorkingDistance(ref a_distance);
  219. }
  220. }
  221. public bool MoveSEMToPoint(double a_dPositionX, double a_dPositionY, double a_dRotation)
  222. {
  223. if (isFEI)
  224. {
  225. return ApiClass.SetSemPositionXYR(a_dPositionX, a_dPositionY, a_dRotation);
  226. }
  227. else
  228. {
  229. if (!hw.IsConnected())
  230. {
  231. return false;
  232. }
  233. return hw.MoveSEMToPoint(a_dPositionX, a_dPositionY, a_dRotation);
  234. }
  235. }
  236. public bool MoveSEMToPoint(double a_dPositionX, double a_dPositionY)
  237. {
  238. if (isFEI)
  239. {
  240. return ApiClass.SetSemPositionXY(a_dPositionX, a_dPositionY);
  241. }
  242. else
  243. {
  244. if (!hw.IsConnected())
  245. {
  246. return false;
  247. }
  248. return hw.MoveSEMToPoint(a_dPositionX, a_dPositionY);
  249. }
  250. }
  251. public bool SetMagnification(double a_dMagnification)
  252. {
  253. if (isFEI)
  254. {
  255. return ApiClass.SetMagnification(a_dMagnification);
  256. }
  257. else
  258. {
  259. if (!hw.IsConnected())
  260. {
  261. return false;
  262. }
  263. NLog.LogManager.GetCurrentClassLogger().Warn("Set Magnification:" + a_dMagnification.ToString("F2"));
  264. hw.SetSemMagnification(a_dMagnification);
  265. return true;
  266. }
  267. }
  268. public bool SetScanExternal(bool b)
  269. {
  270. if (isFEI)
  271. {
  272. return ApiClass.SetSemScanExternal(b);
  273. }
  274. else
  275. {
  276. if (!hw.IsConnected())
  277. {
  278. return false;
  279. }
  280. return hw.SetSemScanExternal(b);
  281. }
  282. }
  283. public bool SetWorkingDistance(double a_distance)
  284. {
  285. if (isFEI)
  286. {
  287. return ApiClass.SetWorkingDistance(a_distance);
  288. }
  289. else
  290. {
  291. if (!hw.IsConnected())
  292. {
  293. return false;
  294. }
  295. return hw.SetSemWorkingDistance(a_distance);
  296. }
  297. System.Threading.Thread.Sleep(1000);
  298. }
  299. public bool GetSemBrightness(ref double a_dBrightness)
  300. {
  301. if (isFEI)
  302. {
  303. a_dBrightness = ApiClass.GetDetectorBrightness();
  304. return true;
  305. }
  306. else
  307. {
  308. if (!hw.IsConnected())
  309. {
  310. return false;
  311. }
  312. return hw.GetSemBrightness(ref a_dBrightness);
  313. }
  314. }
  315. public bool SetSemBrightness(double a_dBrightness)
  316. {
  317. if (isFEI)
  318. {
  319. return ApiClass.SetDetectorBrightness(a_dBrightness);
  320. }
  321. else
  322. {
  323. if (!hw.IsConnected())
  324. {
  325. return false;
  326. }
  327. return hw.SetSemBrightness(a_dBrightness);
  328. }
  329. }
  330. public bool GetSemContrast(ref double a_dContrast)
  331. {
  332. if (isFEI)
  333. {
  334. a_dContrast = ApiClass.GetDetectorContrast();
  335. return true;
  336. }
  337. else
  338. {
  339. if (!hw.IsConnected())
  340. {
  341. return false;
  342. }
  343. return hw.GetSemContrast(ref a_dContrast);
  344. }
  345. }
  346. public bool SetSemContrast(double a_dContrast)
  347. {
  348. if (isFEI)
  349. {
  350. return ApiClass.SetDetectorContrast(a_dContrast);
  351. }
  352. else
  353. {
  354. if (!hw.IsConnected())
  355. {
  356. return false;
  357. }
  358. return hw.SetSemContrast(a_dContrast);
  359. }
  360. }
  361. public bool GetSemHighTension(ref double a_dKV)
  362. {
  363. if (isFEI)
  364. {
  365. a_dKV = ApiClass.GetHightVoltage() / 1000;
  366. return true;
  367. }
  368. else
  369. {
  370. if (!hw.IsConnected())
  371. {
  372. return false;
  373. }
  374. return hw.GetSemHighTension(ref a_dKV);
  375. }
  376. }
  377. public bool SetSemHighTension(double a_dKV)
  378. {
  379. if (isFEI)
  380. {
  381. return ApiClass.SetHightVoltage(a_dKV);
  382. }
  383. else
  384. {
  385. if (!hw.IsConnected())
  386. {
  387. return false;
  388. }
  389. return hw.SetSemHighTension(a_dKV);
  390. }
  391. }
  392. public bool SetSemBeamCurrent(bool a_dKV)
  393. {
  394. if (isFEI)
  395. {
  396. if (a_dKV)
  397. {
  398. return ApiClass.SetBeamStateOn();
  399. }
  400. else
  401. {
  402. return ApiClass.SetBeamStateOff();
  403. }
  404. }
  405. else
  406. {
  407. if (!hw.IsConnected())
  408. {
  409. return false;
  410. }
  411. return hw.SetSemBeamCurrent(a_dKV);
  412. }
  413. }
  414. public bool SetSemBeamBlank(bool a_dKV)
  415. {
  416. if (isFEI)
  417. {
  418. if (a_dKV)
  419. {
  420. return ApiClass.SetBeamStateOn();
  421. }
  422. else
  423. {
  424. return ApiClass.SetBeamStateOff();
  425. }
  426. }
  427. else
  428. {
  429. if (!hw.IsConnected())
  430. {
  431. return false;
  432. }
  433. return hw.SetSemBeamBlank(a_dKV);
  434. }
  435. }
  436. public bool GetSemBeamBlank(ref int a_nBeamBlank)
  437. {
  438. if (isFEI)
  439. {
  440. if (ApiClass.GetIsBlanked())
  441. {
  442. a_nBeamBlank = 1;
  443. }
  444. else
  445. {
  446. a_nBeamBlank = 0;
  447. }
  448. return true;
  449. }
  450. else
  451. {
  452. if (!hw.IsConnected())
  453. {
  454. return false;
  455. }
  456. return hw.GetSemBeamBlank(ref a_nBeamBlank);
  457. }
  458. }
  459. public bool StopXrayAcquisition()
  460. {
  461. if (isFEI)
  462. {
  463. return ApiClass.DisConnect();
  464. }
  465. else
  466. {
  467. if (hw.IsConnected())
  468. {
  469. return hw.StopXrayAcquisition();
  470. }
  471. return true;
  472. }
  473. }
  474. public OTSCLRINTERFACE.COTSControlFunExport GetHardwareInterface()
  475. {
  476. if (!hw.IsConnected())
  477. {
  478. return null;
  479. }
  480. return hw;
  481. }
  482. }
  483. }