FormUnitControl.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.IO;
  13. using SmartSEMControl;
  14. namespace HOZProject
  15. {
  16. public partial class FormUnitControl : Form
  17. {
  18. #region 系统参数
  19. private String path= Directory.GetCurrentDirectory();
  20. private SmartSEM sem = new SmartSEM();
  21. #endregion
  22. #region 远程处理服务器可能发送给您的通知代码。
  23. // Notification codes that the Remoting server may send to you.
  24. public enum ZeissNotificationCode
  25. {
  26. PARAMETER_CHANGE = 0,
  27. PARAMETER_XY_CHANGE = 6,
  28. EMSERVER_HAS_LOADED = 1111111,
  29. EMSERVER_HAS_EXITED = 2222222,
  30. EMSERVER_USER_LOGGED_ON = 3333333,
  31. EMSERVER_USER_LOGGED_OFF = 4444444,
  32. REMOTING_SERVER_EXITED = 5555555,
  33. EMSERVER_FIBUI_HAS_LOADED = 6666666
  34. }
  35. #endregion
  36. #region 返回错误代码
  37. public enum ZeissErrorCode
  38. {
  39. // Failed to translate parameter into an id
  40. API_E_GET_TRANSLATE_FAIL = 1000,
  41. // Failed to get analogue value
  42. API_E_GET_AP_FAIL = 1001,
  43. // Failed to get digital value
  44. API_E_GET_DP_FAIL = 1002,
  45. // Parameter supplied is not analogue nor digital
  46. API_E_GET_BAD_PARAMETER = 1003,
  47. // Failed to translate parameter into an id
  48. API_E_SET_TRANSLATE_FAIL = 1004,
  49. // Failed to set a digital state
  50. API_E_SET_STATE_FAIL = 1005,
  51. // Failed to set a float value
  52. API_E_SET_FLOAT_FAIL = 1006,
  53. // Value supplied is too low
  54. API_E_SET_FLOAT_LIMIT_LOW = 1007,
  55. // Value supplied is too high
  56. API_E_SET_FLOAT_LIMIT_HIGH = 1008,
  57. // Value supplied is is of wrong type
  58. API_E_SET_BAD_VALUE = 1009,
  59. // Parameter supplied is not analogue nor digital
  60. API_E_SET_BAD_PARAMETER = 1010,
  61. // Failed to translate command into an id
  62. API_E_EXEC_TRANSLATE_FAIL = 1011,
  63. // Failed to execute command=
  64. API_E_EXEC_CMD_FAIL = 1012,
  65. // Failed to execute file macro
  66. API_E_EXEC_MCF_FAIL = 1013,
  67. // Failed to execute library macro
  68. API_E_EXEC_MCL_FAIL = 1014,
  69. // Command supplied is not implemented
  70. API_E_EXEC_BAD_COMMAND = 1015,
  71. // Grab command failed
  72. API_E_GRAB_FAIL = 1016,
  73. // Get Stage position failed
  74. API_E_GET_STAGE_FAIL = 1017,
  75. // Move Stage position failed
  76. API_E_MOVE_STAGE_FAIL = 1018,
  77. // API not initialised
  78. API_E_NOT_INITIALISED = 1019,
  79. // Failed to translate parameter to an id
  80. API_E_NOTIFY_TRANSLATE_FAIL = 1020,
  81. // Set notification failed
  82. API_E_NOTIFY_SET_FAIL = 1021,
  83. // Get limits failed
  84. API_E_GET_LIMITS_FAIL = 1022,
  85. // Get multiple parameters failed
  86. API_E_GET_MULTI_FAIL = 1023,
  87. // Set multiple parameters failed
  88. API_E_SET_MULTI_FAIL = 1024,
  89. // Missing API license
  90. API_E_NOT_LICENSED = 1025,
  91. // Reserved or not implemented
  92. API_E_NOT_IMPLEMENTED = 1026,
  93. // Failed to get user name (Remoting Interface only)
  94. API_E_GET_USER_NAME_FAIL = 1027,
  95. // Failed to get user idle state (Remoting Interface only)
  96. API_E_GET_USER_IDLE_FAIL = 1028,
  97. // Failed to get the last remoting connection error string (Remoting Interface Only)
  98. API_E_GET_LAST_REMOTING_CONNECT_ERROR_FAIL = 1029,
  99. // Failed to remotely logon to the EM Server (username and password may be incorrect or EM Server is not running or User is already logged on
  100. API_E_EMSERVER_LOGON_FAILED = 1030,
  101. // Failed to start the EM Server - this may be because the Server is already running or has an internal error.
  102. API_E_EMSERVER_START_FAILED = 1031,
  103. // The command or parameter is currently disabled (you cannot execute or set it).
  104. API_E_PARAMETER_IS_DISABLED = 1032,
  105. // Remoting incorrectly configured, use RConfigure to correct
  106. API_E_REMOTING_NOT_CONFIGURED = 2027,
  107. // Remoting did not connect to the server
  108. API_E_REMOTING_FAILED_TO_CONNECT = 2028,
  109. // Remoting could not start (unknown reason)
  110. API_E_REMOTING_COULD_NOT_CREATE_INTERFACE = 2029,
  111. // Remoting: Remote server is not running currently.
  112. API_E_REMOTING_EMSERVER_NOT_RUNNING = 2030,
  113. // Remoting: Remote server has no user logged in
  114. API_E_REMOTING_NO_USER_LOGGED_IN = 2031,
  115. // Internal Defines, although they may be useful in your own program. TRS.
  116. API_FIRST_REMOTING_ERROR_CODE = API_E_REMOTING_NOT_CONFIGURED,
  117. API_LAST_REMOTING_ERROR_CODE = API_E_REMOTING_NO_USER_LOGGED_IN,
  118. API_FIRST_ERROR_CODE = API_E_GET_TRANSLATE_FAIL,
  119. API_LAST_ERROR_CODE = API_E_REMOTING_NO_USER_LOGGED_IN
  120. }
  121. #endregion
  122. #region 构造函数
  123. public FormUnitControl()
  124. {
  125. InitializeComponent();
  126. //Calling Notification for updated status
  127. //CZEMApi.Notify += new _EMApiEvents_NotifyEventHandler(CZEMApi_Notify);
  128. //CZEMApi.NotifyWithCurrentValue += new _EMApiEvents_NotifyWithCurrentValueEventHandler(CZEMApi_NotifyWithCurrentValue);
  129. //加载参数
  130. }
  131. #endregion
  132. #region 控件加载事件1
  133. public void CZEMApi_Notify(string strParameter, int reason)
  134. {
  135. Notify(strParameter, reason);
  136. }
  137. #endregion
  138. #region 控件加载事件2
  139. public void CZEMApi_NotifyWithCurrentValue(string strParameter, int reason, int paramid, double dLastKnownValue)
  140. {
  141. Notify(strParameter, reason);
  142. }
  143. #endregion
  144. #region 加载事件调用函数
  145. public void Notify(string strParameter, int reason)
  146. {
  147. //string strGetEMSERVERMsg = "";
  148. //switch ((ZeissNotificationCode)reason)
  149. //{
  150. // case ZeissNotificationCode.PARAMETER_CHANGE: // Parameter Change
  151. // if (strParameter == "DP_VACSTATUS" || strParameter == "DP_RUNUPSTATE" || strParameter == "DP_COLUMN_TYPE" || strParameter == "DP_OPERATING_MODE"
  152. // || strParameter == "DP_SCANRATE" || strParameter == "DP_AUTO_FUNCTION" || strParameter == "DP_DETECTOR_TYPE" || strParameter == "DP_STAGE_INIT"
  153. // || strParameter == "DP_STAGE_IS" || strParameter == "DP_FIB_MODE" || strParameter == "DP_FIB_GUN_STATE" || strParameter == "AP_ACTUALKV"
  154. // || strParameter == "AP_ACTUALCURRENT" || strParameter == "AP_MAG" || strParameter == "AP_WD" || strParameter == "AP_IPROBE" || strParameter== "AP_CONTRAST")
  155. // {
  156. // UpdateStatus(strParameter);
  157. // }
  158. // break;
  159. // case ZeissNotificationCode.REMOTING_SERVER_EXITED:
  160. // //listServerMsg.Items.Add("Remote Server Exited");
  161. // strGetEMSERVERMsg = "Remote Server Exited";
  162. // DisplayError("Remote Server closed", "");
  163. // m_bInitialised = false;
  164. // //txtEditInit.Text = "Not Initialised";
  165. // //txtEditNotify.Text = "No Notification";
  166. // //txtEditInit.BackColor = Color.Red;
  167. // //txtEditNotify.BackColor = Color.Red;
  168. // break;
  169. // default:
  170. // strGetEMSERVERMsg = strParameter;
  171. // break;
  172. //}
  173. //if (strGetEMSERVERMsg.Length > 0)
  174. //{
  175. // //if (txtNotifyEdit.Text.Length > 0)
  176. // //{
  177. // // txtNotifyEdit.Text += "\r\n" + strGetEMSERVERMsg;
  178. // // txtNotifyEdit.SelectionStart = txtNotifyEdit.Text.Length;
  179. // // txtNotifyEdit.SelectionLength = 0;
  180. // //}
  181. // //else
  182. // //{
  183. // // txtNotifyEdit.Text = strGetEMSERVERMsg;
  184. // //}
  185. //}
  186. }
  187. #endregion
  188. #region 更新状态
  189. public void UpdateStatus(string szParam)
  190. {
  191. //object varStr = new VariantWrapper("");
  192. //object varfloat = new VariantWrapper((float)0.0f);
  193. //if(szParam.IndexOf("AP")==0)
  194. //{
  195. // lrt = CZEMApi.Get(szParam, ref varfloat);
  196. // if (lrt != 0)
  197. // {
  198. // ReportError(lrt, "Update Status", szParam);
  199. // return;
  200. // }
  201. // lblgetValue.Text = Convert.ToDecimal(varfloat).ToString();
  202. //}
  203. //else
  204. //{
  205. // lrt = CZEMApi.Get(szParam, ref varStr);
  206. // if (lrt != 0)
  207. // {
  208. // ReportError(lrt, "Update Status", szParam);
  209. // return;
  210. // }
  211. // lblgetValue.Text = varStr.ToString();
  212. //}
  213. //if (szParam == "DP_VACSTATUS")
  214. //{
  215. // txtEditVacStatus.Text = "VAC status = " + varStr;
  216. //}
  217. //else if (szParam == "DP_RUNUPSTATE")
  218. //{
  219. // txtEditRunupstate.Text = "Beam Status = " + varStr;
  220. //}
  221. //else if (szParam == "DP_COLUMN_TYPE")
  222. //{
  223. // txtEditColumnType.Text = "Column Type = " + varStr;
  224. //}
  225. //else if (szParam == "DP_STAGE_INIT")
  226. //{
  227. // txtEditStageInit.Text = "Stage Initialised = " + varStr;
  228. //}
  229. //else if (szParam == "DP_STAGE_IS")
  230. //{
  231. // txtEditStageIs.Text = "Stage = " + varStr;
  232. //}
  233. //else if (szParam == "DP_OPERATING_MODE")
  234. //{
  235. // txtEditOperatingMode.Text = "Operating Mode = " + varStr;
  236. //}
  237. //else if (szParam == "DP_SCANRATE")
  238. //{
  239. // txtEditScanrate.Text = "Scan Rate = " + varStr;
  240. //}
  241. //else if (szParam == "DP_AUTO_FUNCTION")
  242. //{
  243. // txtEditAutoFunction.Text = "Auto Function = " + varStr;
  244. //}
  245. //else if (szParam == "DP_DETECTOR_TYPE")
  246. //{
  247. // txtEditDetectorType.Text = "Detector = " + varStr;
  248. //}
  249. //else if (szParam == "DP_FIB_MODE")
  250. //{
  251. // txtEditFibMode.Text = "FIB Mode = " + varStr;
  252. //}
  253. //else if (szParam == "DP_FIB_GUN_STATE")
  254. //{
  255. // txtEditFibGunState.Text = "FIB Gun = " + varStr;
  256. //}
  257. //else if (szParam == "AP_ACTUALKV")
  258. //{
  259. // txtEditActualkv.Text = "EHT " + varStr;
  260. //}
  261. //else if (szParam == "AP_ACTUALCURRENT")
  262. //{
  263. // txtEditActualcurrent.Text = "I " + varStr;
  264. //}
  265. //else if (szParam == "AP_MAG")
  266. //{
  267. // txtEditMag.Text = "Mag " + varStr;
  268. //}
  269. //else if (szParam == "AP_WD")
  270. //{
  271. // txtEditWd.Text = "WD " + varStr;
  272. //}
  273. //else if (szParam == "AP_IPROBE")
  274. //{
  275. // txtEditIprobe.Text = "Probe I " + varStr;
  276. //}
  277. }
  278. #endregion
  279. #region 显示错误代码
  280. internal void DisplayError(string strCaller, string strComment)
  281. {
  282. //if (m_bInitialised)
  283. //{
  284. // object objError = new VariantWrapper("");
  285. // long lResult = CZEMApi.GetLastError(ref objError);
  286. // if (lResult == 0)
  287. // {
  288. // if (objError != null)
  289. // {
  290. // ReportError(objError.ToString(), strCaller, strComment);
  291. // }
  292. // else
  293. // {
  294. // ReportError("No error occured", strCaller, strComment);
  295. // }
  296. // }
  297. // else
  298. // {
  299. // ReportError("Cannot get last error", strCaller, strComment);
  300. // }
  301. //}
  302. }
  303. #endregion
  304. #region 输出错误号1
  305. internal void ReportError(string strError, string strCaller, string strComment)
  306. {
  307. if (strCaller.Length != 0 || strComment.Length != 0)
  308. {
  309. // listmsg.Items.Add(string.Format("{0}\r\nCaller: {1}\r\nComment: {2}", strError, strCaller, strComment));
  310. }
  311. else
  312. {
  313. //listmsg.Items.Add(strError);
  314. }
  315. }
  316. #endregion
  317. #region 输出错误2
  318. internal void ReportError(long lReturn, string strCaller, string strComment)
  319. {
  320. ReportError(ErrorToString(lReturn), strCaller, strComment);
  321. }
  322. #endregion
  323. #region 错误代码转换
  324. string ErrorToString(long lError)
  325. {
  326. string strError;
  327. switch ((ZeissErrorCode)lError)
  328. {
  329. case 0:
  330. strError = "OK";
  331. break;
  332. case ZeissErrorCode.API_E_GET_TRANSLATE_FAIL:
  333. strError = "Failed to translate parameter into an ID";
  334. break;
  335. case ZeissErrorCode.API_E_GET_AP_FAIL:
  336. strError = "Failed to get analogue value";
  337. break;
  338. case ZeissErrorCode.API_E_GET_DP_FAIL:
  339. strError = "Failed to get digital value";
  340. break;
  341. case ZeissErrorCode.API_E_GET_BAD_PARAMETER:
  342. strError = "Parameter supplied is neither analogue nor digital";
  343. break;
  344. case ZeissErrorCode.API_E_SET_TRANSLATE_FAIL:
  345. strError = "Failed to translate parameter into an ID";
  346. break;
  347. case ZeissErrorCode.API_E_SET_STATE_FAIL:
  348. strError = "Failed to set a digital state";
  349. break;
  350. case ZeissErrorCode.API_E_SET_FLOAT_FAIL:
  351. strError = "Failed to set a float value";
  352. break;
  353. case ZeissErrorCode.API_E_SET_FLOAT_LIMIT_LOW:
  354. strError = "Value supplied is too low";
  355. break;
  356. case ZeissErrorCode.API_E_SET_FLOAT_LIMIT_HIGH:
  357. strError = "Value supplied is too high";
  358. break;
  359. case ZeissErrorCode.API_E_SET_BAD_VALUE:
  360. strError = "Value supplied is of wrong type";
  361. break;
  362. case ZeissErrorCode.API_E_SET_BAD_PARAMETER:
  363. strError = "Parameter supplied is not analogue nor digital";
  364. break;
  365. case ZeissErrorCode.API_E_EXEC_TRANSLATE_FAIL:
  366. strError = "Failed to translate command into an ID";
  367. break;
  368. case ZeissErrorCode.API_E_EXEC_CMD_FAIL:
  369. strError = "Failed to execute command";
  370. break;
  371. case ZeissErrorCode.API_E_EXEC_MCF_FAIL:
  372. strError = "Failed to execute file macro";
  373. break;
  374. case ZeissErrorCode.API_E_EXEC_MCL_FAIL:
  375. strError = "Failed to execute library macro";
  376. break;
  377. case ZeissErrorCode.API_E_EXEC_BAD_COMMAND:
  378. strError = "Command supplied is not implemented";
  379. break;
  380. case ZeissErrorCode.API_E_GRAB_FAIL:
  381. strError = "Grab command failed";
  382. break;
  383. case ZeissErrorCode.API_E_GET_STAGE_FAIL:
  384. strError = "Get Stage position failed";
  385. break;
  386. case ZeissErrorCode.API_E_MOVE_STAGE_FAIL:
  387. strError = "Move Stage position failed";
  388. break;
  389. case ZeissErrorCode.API_E_NOT_INITIALISED:
  390. strError = "API not initialised";
  391. break;
  392. case ZeissErrorCode.API_E_NOTIFY_TRANSLATE_FAIL: // 1020L
  393. strError = "Failed to translate parameter to an ID";
  394. break;
  395. case ZeissErrorCode.API_E_NOTIFY_SET_FAIL:
  396. strError = "Set notification failed";
  397. break;
  398. case ZeissErrorCode.API_E_GET_LIMITS_FAIL:
  399. strError = "Get limits failed";
  400. break;
  401. case ZeissErrorCode.API_E_GET_MULTI_FAIL:
  402. strError = "Get multiple parameters failed";
  403. break;
  404. case ZeissErrorCode.API_E_SET_MULTI_FAIL:
  405. strError = "Set multiple parameters failed";
  406. break;
  407. case ZeissErrorCode.API_E_NOT_LICENSED:
  408. strError = "Missing API license";
  409. break;
  410. case ZeissErrorCode.API_E_NOT_IMPLEMENTED:
  411. strError = "Reserved or not implemented";
  412. break;
  413. case ZeissErrorCode.API_E_GET_USER_NAME_FAIL:
  414. strError = "Failed to get user name";
  415. break;
  416. case ZeissErrorCode.API_E_GET_USER_IDLE_FAIL:
  417. strError = "Failed to get user idle state";
  418. break;
  419. case ZeissErrorCode.API_E_GET_LAST_REMOTING_CONNECT_ERROR_FAIL:
  420. strError = "Failed to get the last remoting connection error string";
  421. break;
  422. case ZeissErrorCode.API_E_EMSERVER_LOGON_FAILED:
  423. strError = "Failed to remotely logon to the EM Server. Username and password may be incorrect or EM Server is not running or User is already logged on";
  424. break;
  425. case ZeissErrorCode.API_E_EMSERVER_START_FAILED:
  426. strError = "Failed to start the EM Server. This may be because the Server is already running or has an internal error.";
  427. break;
  428. case ZeissErrorCode.API_E_REMOTING_NOT_CONFIGURED:
  429. strError = "Remoting incorrectly configured, use RConfigure to correct";
  430. break;
  431. case ZeissErrorCode.API_E_REMOTING_FAILED_TO_CONNECT:
  432. strError = "Remoting did not connect to the server";
  433. break;
  434. case ZeissErrorCode.API_E_REMOTING_COULD_NOT_CREATE_INTERFACE:
  435. strError = "Remoting could not start (unknown reason)";
  436. break;
  437. case ZeissErrorCode.API_E_REMOTING_EMSERVER_NOT_RUNNING:
  438. strError = "EMServer is not running on the remote machine";
  439. break;
  440. case ZeissErrorCode.API_E_REMOTING_NO_USER_LOGGED_IN:
  441. strError = "No user is logged into EM Server on the remote machine";
  442. break;
  443. default:
  444. strError = string.Format("Unknown error code {0}", lError);
  445. break;
  446. }
  447. return strError;
  448. }
  449. #endregion
  450. #region 设备初始化按键
  451. private void btnInit_Click(object sender, EventArgs e)
  452. {
  453. if(sem.Init())
  454. {
  455. btnInit.BackColor = Color.Lime;
  456. }
  457. else
  458. {
  459. btnInit.BackColor = Color.Red;
  460. }
  461. }
  462. #endregion
  463. #region 设备关闭按键
  464. private void btnCloseCtrl_Click(object sender, EventArgs e)
  465. {
  466. if (sem.UnInit())
  467. {
  468. btnInit.BackColor = Control.DefaultBackColor;
  469. }
  470. }
  471. #endregion
  472. #region 设置参数更新通知
  473. private void btnSetNotify_Click(object sender, EventArgs e)
  474. {
  475. //if (m_bInitialised)
  476. //{
  477. // // Magnification
  478. // if (CZEMApi.SetNotify("AP_MAG", 1) != 0)
  479. // {
  480. // DisplayError("SetNotify", "AP_MAG");
  481. // return;
  482. // }
  483. // // Working distance
  484. // if (CZEMApi.SetNotify("AP_WD", 1) != 0)
  485. // {
  486. // DisplayError("SetNotify", "AP_WD");
  487. // return;
  488. // }
  489. // // BRIGHTNESS 亮度
  490. // if (CZEMApi.SetNotify("AP_BRIGHTNESS", 1) != 0)
  491. // {
  492. // DisplayError("SetNotify", "AP_BRIGHTNESS");
  493. // return;
  494. // }
  495. // // AP_CONTRAST,对比度
  496. // if (CZEMApi.SetNotify("AP_CONTRAST", 1) != 0)
  497. // {
  498. // DisplayError("SetNotify", "AP_CONTRAST");
  499. // return;
  500. // }
  501. // // Vacuum
  502. // if (CZEMApi.SetNotify("DP_VACSTATUS", 1) != 0)
  503. // {
  504. // DisplayError("SetNotify", "DP_VACSTATUS");
  505. // return;
  506. // }
  507. // // Gun / EHT state
  508. // if (CZEMApi.SetNotify("DP_RUNUPSTATE", 1) != 0)
  509. // {
  510. // DisplayError("SetNotify", "DP_RUNUPSTATE");
  511. // return;
  512. // }
  513. // // actual KV / EHT
  514. // if (CZEMApi.SetNotify("AP_ACTUALKV", 1) != 0)
  515. // {
  516. // DisplayError("SetNotify", "AP_ACTUALKV");
  517. // return;
  518. // }
  519. // // actual current
  520. // if (CZEMApi.SetNotify("AP_ACTUALCURRENT", 1) != 0)
  521. // {
  522. // DisplayError("SetNotify", "AP_ACTUALCURRENT");
  523. // return;
  524. // }
  525. // // column type
  526. // if (CZEMApi.SetNotify("DP_COLUMN_TYPE", 1) != 0)
  527. // {
  528. // DisplayError("SetNotify", "DP_COLUMN_TYPE");
  529. // return;
  530. // }
  531. // // mode
  532. // if (CZEMApi.SetNotify("DP_OPERATING_MODE", 1) != 0)
  533. // {
  534. // DisplayError("SetNotify", "DP_OPERATING_MODE");
  535. // return;
  536. // }
  537. // // scan rate
  538. // if (CZEMApi.SetNotify("DP_SCANRATE", 1) != 0)
  539. // {
  540. // DisplayError("SetNotify", "DP_SCANRATE");
  541. // return;
  542. // }
  543. // // auto function active
  544. // if (CZEMApi.SetNotify("DP_AUTO_FUNCTION", 1) != 0)
  545. // {
  546. // DisplayError("SetNotify", "DP_AUTO_FUNCTION");
  547. // return;
  548. // }
  549. // // probe current
  550. // if (CZEMApi.SetNotify("AP_IPROBE", 1) != 0)
  551. // {
  552. // DisplayError("SetNotify", "AP_IPROBE");
  553. // return;
  554. // }
  555. // // detector
  556. // if (CZEMApi.SetNotify("DP_DETECTOR_TYPE", 1) != 0)
  557. // {
  558. // DisplayError("SetNotify", "DP_DETECTOR_TYPE");
  559. // return;
  560. // }
  561. // // stage initialised
  562. // if (CZEMApi.SetNotify("DP_STAGE_INIT", 1) != 0)
  563. // {
  564. // DisplayError("SetNotify", "DP_STAGE_INIT");
  565. // return;
  566. // }
  567. // // stage busy?
  568. // if (CZEMApi.SetNotify("DP_STAGE_IS", 1) != 0)
  569. // {
  570. // DisplayError("SetNotify", "DP_STAGE_IS");
  571. // return;
  572. // }
  573. // // fib mode
  574. // if (CZEMApi.SetNotify("DP_FIB_MODE", 1) != 0)
  575. // {
  576. // DisplayError("SetNotify", "DP_FIB_MODE");
  577. // return;
  578. // }
  579. // // fib gun state
  580. // if (CZEMApi.SetNotify("DP_FIB_GUN_STATE", 1) != 0)
  581. // {
  582. // DisplayError("SetNotify", "DP_FIB_GUN_STATE");
  583. // return;
  584. // }
  585. //listmsg.Items.Add("Notification enabled");
  586. // }
  587. }
  588. #endregion
  589. #region 缩放Get
  590. private void btnenlargeGet_Click(object sender, EventArgs e)
  591. {
  592. float ret = sem.GetMagnification();
  593. if(float.IsNaN(ret))
  594. {
  595. lblenlargeGet.Text = "NaN";
  596. txtenlargeSet.Enabled = false;
  597. btnenlargeSet.Enabled = false;
  598. }
  599. else
  600. {
  601. lblenlargeGet.Text = ret.ToString();
  602. txtenlargeSet.Text = ret.ToString();
  603. btnenlargeSet.Enabled = true;
  604. }
  605. }
  606. #endregion
  607. #region 缩放Set
  608. private void btnenlargeSet_Click(object sender, EventArgs e)
  609. {
  610. float set = 0;
  611. if(float.TryParse(txtenlargeSet.Text, out set))
  612. {
  613. sem.SetMagnification(set);
  614. }
  615. }
  616. #endregion
  617. #region 焦距Get
  618. private void btnWDGet_Click(object sender, EventArgs e)
  619. {
  620. float ret = sem.GetWorkingDistance();
  621. if (float.IsNaN(ret))
  622. {
  623. lblWDGet.Text = "NaN";
  624. txtWDSet.Enabled = false;
  625. btnWDSet.Enabled = false;
  626. }
  627. else
  628. {
  629. lblWDGet.Text = ret.ToString();
  630. txtWDSet.Text = ret.ToString();
  631. btnWDSet.Enabled = true;
  632. }
  633. }
  634. #endregion
  635. #region 焦距Set
  636. private void btnWDSet_Click(object sender, EventArgs e)
  637. {
  638. float set = 0;
  639. if (float.TryParse(txtWDSet.Text, out set))
  640. {
  641. sem.SetWorkingDistance(set);
  642. }
  643. }
  644. #endregion
  645. #region 亮度Get
  646. private void btnBrightnessGet_Click(object sender, EventArgs e)
  647. {
  648. float ret = sem.GetBrightness();
  649. if (float.IsNaN(ret))
  650. {
  651. lblBrightnessGet.Text = "NaN";
  652. txtBrightnessSet.Enabled = false;
  653. btnBrightnessSet.Enabled = false;
  654. }
  655. else
  656. {
  657. lblBrightnessGet.Text = ret.ToString();
  658. txtBrightnessSet.Text = ret.ToString();
  659. btnBrightnessSet.Enabled = true;
  660. }
  661. }
  662. #endregion
  663. #region 亮度Set
  664. private void btnBrightnessSet_Click(object sender, EventArgs e)
  665. {
  666. float set = 0;
  667. if (float.TryParse(txtBrightnessSet.Text, out set))
  668. {
  669. sem.SetBrightness(set);
  670. }
  671. }
  672. #endregion
  673. #region 对比度Get
  674. private void btnContrastGet_Click(object sender, EventArgs e)
  675. {
  676. float ret = sem.GetContrast();
  677. if (float.IsNaN(ret))
  678. {
  679. lblContrastGet.Text = "NaN";
  680. txtContrastSet.Enabled = false;
  681. btnContrastSet.Enabled = false;
  682. }
  683. else
  684. {
  685. lblContrastGet.Text = ret.ToString();
  686. txtContrastSet.Text = ret.ToString();
  687. btnContrastSet.Enabled = true;
  688. }
  689. }
  690. #endregion
  691. #region 对比度Set
  692. private void btnContrastSet_Click(object sender, EventArgs e)
  693. {
  694. float set = 0;
  695. if (float.TryParse(txtContrastSet.Text, out set))
  696. {
  697. sem.SetContrast(set);
  698. }
  699. }
  700. #endregion
  701. #region 消像散X Get
  702. private void btnAstigmatismXGet_Click(object sender, EventArgs e)
  703. {
  704. float ret = sem.GetAstigmatismX();
  705. if (float.IsNaN(ret))
  706. {
  707. lblAstigmatismXGet.Text = "NaN";
  708. txtAstigmatismXSet.Enabled = false;
  709. btnAstigmatismXSet.Enabled = false;
  710. }
  711. else
  712. {
  713. lblAstigmatismXGet.Text = ret.ToString();
  714. txtAstigmatismXSet.Text = ret.ToString();
  715. btnAstigmatismXSet.Enabled = true;
  716. }
  717. }
  718. #endregion
  719. #region 消像散X Set
  720. private void btnAstigmatismXSet_Click(object sender, EventArgs e)
  721. {
  722. float set = 0;
  723. if (float.TryParse(txtAstigmatismXSet.Text, out set))
  724. {
  725. sem.SetAstigmatismX(set);
  726. }
  727. }
  728. #endregion
  729. #region 消像散Y Get
  730. private void btnAstigmatismYGet_Click(object sender, EventArgs e)
  731. {
  732. float ret = sem.GetAstigmatismY();
  733. if (float.IsNaN(ret))
  734. {
  735. lblAstigmatismYGet.Text = "NaN";
  736. txtAstigmatismYSet.Enabled = false;
  737. btnAstigmatismYSet.Enabled = false;
  738. }
  739. else
  740. {
  741. lblAstigmatismYGet.Text = ret.ToString();
  742. txtAstigmatismYSet.Text = ret.ToString();
  743. btnAstigmatismYSet.Enabled = true;
  744. }
  745. }
  746. #endregion
  747. #region 消像散Y Set
  748. private void btnAstigmatismYSet_Click(object sender, EventArgs e)
  749. {
  750. float set = 0;
  751. if (float.TryParse(txtAstigmatismYSet.Text, out set))
  752. {
  753. sem.SetAstigmatismY(set);
  754. }
  755. }
  756. #endregion
  757. #region 角度补偿Get
  758. private void btnTiltAngleGet_Click(object sender, EventArgs e)
  759. {
  760. float ret = sem.GetTiltAngle();
  761. if (float.IsNaN(ret))
  762. {
  763. lblTiltAngleGet.Text = "NaN";
  764. txtTiltAngleSet.Enabled = false;
  765. btnTiltAngleSet.Enabled = false;
  766. }
  767. else
  768. {
  769. lblTiltAngleGet.Text = ret.ToString();
  770. txtTiltAngleSet.Text = ret.ToString();
  771. btnTiltAngleSet.Enabled = true;
  772. }
  773. }
  774. #endregion
  775. #region 角度补偿Set
  776. private void btnTiltAngleSet_Click(object sender, EventArgs e)
  777. {
  778. float set = 0;
  779. if (float.TryParse(txtTiltAngleSet.Text, out set))
  780. {
  781. sem.SetTiltAngle(set);
  782. }
  783. }
  784. #endregion
  785. #region 抓取图像
  786. private void btnGrabImage_Click(object sender, EventArgs e)
  787. {
  788. SaveFileDialog sfd = new SaveFileDialog();
  789. sfd.Title = "图像保存位置:";
  790. sfd.FileName = "test.tif";
  791. sfd.Filter = "TIF文件|*.tif";
  792. if (sfd.ShowDialog() == DialogResult.OK)
  793. {
  794. string fn = sfd.FileName;
  795. sem.GrabImage(fn, 0);
  796. }
  797. }
  798. #endregion
  799. #region ScanRotate Get
  800. private void btnScanRotationGet_Click(object sender, EventArgs e)
  801. {
  802. float ret = sem.GetScanRotation();
  803. if (float.IsNaN(ret))
  804. {
  805. lblScanRotationGet.Text = "NaN";
  806. txtScanRotationSet.Enabled = false;
  807. btnScanRotationSet.Enabled = false;
  808. }
  809. else
  810. {
  811. lblScanRotationGet.Text = ret.ToString();
  812. txtScanRotationSet.Text = ret.ToString();
  813. btnScanRotationSet.Enabled = true;
  814. }
  815. }
  816. #endregion
  817. #region ScanRotate Set
  818. private void btnScanRotationSet_Click(object sender, EventArgs e)
  819. {
  820. float set = 0;
  821. if (float.TryParse(txtScanRotationSet.Text, out set))
  822. {
  823. sem.SetScanRotation(set);
  824. }
  825. }
  826. #endregion
  827. #region PixelSize Get
  828. private void btnPixelSizeGet_Click(object sender, EventArgs e)
  829. {
  830. float ret = sem.GetScanRotation();
  831. if (float.IsNaN(ret))
  832. {
  833. lblScanRotationGet.Text = "NaN";
  834. txtScanRotationSet.Enabled = false;
  835. btnScanRotationSet.Enabled = false;
  836. }
  837. else
  838. {
  839. lblScanRotationGet.Text = ret.ToString();
  840. txtScanRotationSet.Text = ret.ToString();
  841. btnScanRotationSet.Enabled = true;
  842. }
  843. }
  844. #endregion
  845. #region PixelSize Set
  846. private void btnPixelSizeSet_Click(object sender, EventArgs e)
  847. {
  848. float set = 0;
  849. if (float.TryParse(txtScanRotationSet.Text, out set))
  850. {
  851. sem.SetScanRotation(set);
  852. }
  853. }
  854. #endregion
  855. #region 开启电压
  856. private void btnOpenVoltage_Click(object sender, EventArgs e)
  857. {
  858. sem.CmdOpenVoltage();
  859. }
  860. #endregion
  861. #region 关闭电压
  862. private void btnCloseVoltage_Click(object sender, EventArgs e)
  863. {
  864. sem.CmdCloseVoltage();
  865. }
  866. #endregion
  867. }
  868. }