SemController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. }
  298. public bool GetSemBrightness(ref double a_dBrightness)
  299. {
  300. if (isFEI)
  301. {
  302. a_dBrightness = ApiClass.GetDetectorBrightness();
  303. return true;
  304. }
  305. else
  306. {
  307. if (!hw.IsConnected())
  308. {
  309. return false;
  310. }
  311. return hw.GetSemBrightness(ref a_dBrightness);
  312. }
  313. }
  314. public bool SetSemBrightness(double a_dBrightness)
  315. {
  316. if (isFEI)
  317. {
  318. return ApiClass.SetDetectorBrightness(a_dBrightness);
  319. }
  320. else
  321. {
  322. if (!hw.IsConnected())
  323. {
  324. return false;
  325. }
  326. return hw.SetSemBrightness(a_dBrightness);
  327. }
  328. }
  329. public bool GetSemContrast(ref double a_dContrast)
  330. {
  331. if (isFEI)
  332. {
  333. a_dContrast = ApiClass.GetDetectorContrast();
  334. return true;
  335. }
  336. else
  337. {
  338. if (!hw.IsConnected())
  339. {
  340. return false;
  341. }
  342. return hw.GetSemContrast(ref a_dContrast);
  343. }
  344. }
  345. public bool SetSemContrast(double a_dContrast)
  346. {
  347. if (isFEI)
  348. {
  349. return ApiClass.SetDetectorContrast(a_dContrast);
  350. }
  351. else
  352. {
  353. if (!hw.IsConnected())
  354. {
  355. return false;
  356. }
  357. return hw.SetSemContrast(a_dContrast);
  358. }
  359. }
  360. public bool GetSemHighTension(ref double a_dKV)
  361. {
  362. if (isFEI)
  363. {
  364. a_dKV = ApiClass.GetHightVoltage() / 1000;
  365. return true;
  366. }
  367. else
  368. {
  369. if (!hw.IsConnected())
  370. {
  371. return false;
  372. }
  373. return hw.GetSemHighTension(ref a_dKV);
  374. }
  375. }
  376. public bool SetSemHighTension(double a_dKV)
  377. {
  378. if (isFEI)
  379. {
  380. return ApiClass.SetHightVoltage(a_dKV);
  381. }
  382. else
  383. {
  384. if (!hw.IsConnected())
  385. {
  386. return false;
  387. }
  388. return hw.SetSemHighTension(a_dKV);
  389. }
  390. }
  391. public bool SetSemBeamCurrent(bool a_dKV)
  392. {
  393. if (isFEI)
  394. {
  395. if (a_dKV)
  396. {
  397. return ApiClass.SetBeamStateOn();
  398. }
  399. else
  400. {
  401. return ApiClass.SetBeamStateOff();
  402. }
  403. }
  404. else
  405. {
  406. if (!hw.IsConnected())
  407. {
  408. return false;
  409. }
  410. return hw.SetSemBeamCurrent(a_dKV);
  411. }
  412. }
  413. public bool SetSemBeamBlank(bool a_dKV)
  414. {
  415. if (isFEI)
  416. {
  417. if (a_dKV)
  418. {
  419. return ApiClass.SetBeamStateOn();
  420. }
  421. else
  422. {
  423. return ApiClass.SetBeamStateOff();
  424. }
  425. }
  426. else
  427. {
  428. if (!hw.IsConnected())
  429. {
  430. return false;
  431. }
  432. return hw.SetSemBeamBlank(a_dKV);
  433. }
  434. }
  435. public bool GetSemBeamBlank(ref int a_nBeamBlank)
  436. {
  437. if (isFEI)
  438. {
  439. if (ApiClass.GetIsBlanked())
  440. {
  441. a_nBeamBlank = 1;
  442. }
  443. else
  444. {
  445. a_nBeamBlank = 0;
  446. }
  447. return true;
  448. }
  449. else
  450. {
  451. if (!hw.IsConnected())
  452. {
  453. return false;
  454. }
  455. return hw.GetSemBeamBlank(ref a_nBeamBlank);
  456. }
  457. }
  458. public bool StopXrayAcquisition()
  459. {
  460. if (isFEI)
  461. {
  462. return ApiClass.DisConnect();
  463. }
  464. else
  465. {
  466. if (hw.IsConnected())
  467. {
  468. return hw.StopXrayAcquisition();
  469. }
  470. return true;
  471. }
  472. }
  473. public OTSCLRINTERFACE.COTSControlFunExport GetHardwareInterface()
  474. {
  475. if (!hw.IsConnected())
  476. {
  477. return null;
  478. }
  479. return hw;
  480. }
  481. }
  482. }