SetVoltageDialog.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.IO.Ports;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using PaintDotNet.Base.CommTool;
  13. using PaintDotNet.Base.SettingModel;
  14. using StageController;
  15. using StageController.M3H;
  16. namespace PaintDotNet.Hardware
  17. {
  18. public partial class SetVoltageDialog : Form
  19. {
  20. #region
  21. /// <summary>
  22. /// Required designer variable.
  23. /// </summary>
  24. private System.ComponentModel.IContainer components = null;
  25. /// <summary>
  26. /// Clean up any resources being used.
  27. /// </summary>
  28. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  29. protected override void Dispose(bool disposing)
  30. {
  31. if (disposing && (components != null))
  32. {
  33. components.Dispose();
  34. }
  35. base.Dispose(disposing);
  36. }
  37. #region Windows Form Designer generated code
  38. private void InitializeLanguageText()
  39. {
  40. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  41. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  42. this.btnCommit.Text = PdnResources.GetString("Form.OkButton.Text");
  43. this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
  44. this.label10.Text = PdnResources.GetString("Menu.Baudrate.text") + ":";
  45. this.label11.Text = PdnResources.GetString("Menu.Theportnumber.Text") + ":";
  46. this.label9.Text = PdnResources.GetString("Menu.Powerondefaultvoltagevalue.Text") + ":";
  47. this.btnSetVoltage.Text = PdnResources.GetString("Menu.Settothedefaultvalue.Text");
  48. this.label3.Text = PdnResources.GetString("Menu.Keysteppingvoltagevalue.Text") + ":";
  49. this.label2.Text = PdnResources.GetString("Menu.Theknobturnsthesteppingvoltagevalue.Text") + ":";
  50. this.label1.Text = PdnResources.GetString("Menu.Outputcontrolsource.Text") + ":";
  51. this.groupBox3.Text = PdnResources.GetString("Menu.Thecurrentstate.Text");
  52. this.btnSearch.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Inquire.text");
  53. this.label8.Text = PdnResources.GetString("Menu.Theoutputcurrent.Text") + ":";
  54. this.label7.Text = PdnResources.GetString("Menu.Theoutputvoltage.Text") + ":";
  55. this.label6.Text = PdnResources.GetString("Menu.Theinputvoltage.Text") + ":";
  56. this.label5.Text = PdnResources.GetString("Menu.Thepowersupplystatus.Text") + ":";
  57. this.label4.Text = PdnResources.GetString("Menu.potentiometer.Text") + ":";
  58. this.Text = PdnResources.GetString("Menu.HardwareControl.SetVoltage.Text");
  59. }
  60. /// <summary>
  61. /// Required method for Designer support - do not modify
  62. /// the contents of this method with the code editor.
  63. /// </summary>
  64. private void InitializeComponent()
  65. {
  66. this.groupBox1 = new System.Windows.Forms.GroupBox();
  67. this.btnClose = new System.Windows.Forms.Button();
  68. this.btnCommit = new System.Windows.Forms.Button();
  69. this.groupBox2 = new System.Windows.Forms.GroupBox();
  70. this.pnlVoltage = new System.Windows.Forms.Panel();
  71. this.btnDel1 = new System.Windows.Forms.Button();
  72. this.btnVoltage1 = new System.Windows.Forms.Button();
  73. this.label14 = new System.Windows.Forms.Label();
  74. this.label13 = new System.Windows.Forms.Label();
  75. this.label12 = new System.Windows.Forms.Label();
  76. this.txtBaudRate = new System.Windows.Forms.TextBox();
  77. this.label10 = new System.Windows.Forms.Label();
  78. this.cmbPort = new System.Windows.Forms.ComboBox();
  79. this.label11 = new System.Windows.Forms.Label();
  80. this.txtDefaultVoltage = new System.Windows.Forms.TextBox();
  81. this.label9 = new System.Windows.Forms.Label();
  82. this.btnSetVoltage = new System.Windows.Forms.Button();
  83. this.trbVoltage = new System.Windows.Forms.TrackBar();
  84. this.txtVoltage = new System.Windows.Forms.TextBox();
  85. this.txtButtonStepping = new System.Windows.Forms.TextBox();
  86. this.label3 = new System.Windows.Forms.Label();
  87. this.txtEC11Stepping = new System.Windows.Forms.TextBox();
  88. this.label2 = new System.Windows.Forms.Label();
  89. this.rdoBoth = new System.Windows.Forms.RadioButton();
  90. this.rdoEC11 = new System.Windows.Forms.RadioButton();
  91. this.rdoUSB = new System.Windows.Forms.RadioButton();
  92. this.label1 = new System.Windows.Forms.Label();
  93. this.groupBox3 = new System.Windows.Forms.GroupBox();
  94. this.lblPower = new System.Windows.Forms.Label();
  95. this.lblVoltageOut = new System.Windows.Forms.Label();
  96. this.lblState = new System.Windows.Forms.Label();
  97. this.lblVoltageIn = new System.Windows.Forms.Label();
  98. this.lblPotentiometer = new System.Windows.Forms.Label();
  99. this.btnSearch = new System.Windows.Forms.Button();
  100. this.label8 = new System.Windows.Forms.Label();
  101. this.label7 = new System.Windows.Forms.Label();
  102. this.label6 = new System.Windows.Forms.Label();
  103. this.label5 = new System.Windows.Forms.Label();
  104. this.label4 = new System.Windows.Forms.Label();
  105. this.groupBox1.SuspendLayout();
  106. this.groupBox2.SuspendLayout();
  107. this.pnlVoltage.SuspendLayout();
  108. ((System.ComponentModel.ISupportInitialize)(this.trbVoltage)).BeginInit();
  109. this.groupBox3.SuspendLayout();
  110. this.SuspendLayout();
  111. //
  112. // groupBox1
  113. //
  114. this.groupBox1.Controls.Add(this.btnClose);
  115. this.groupBox1.Controls.Add(this.btnCommit);
  116. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  117. this.groupBox1.Name = "groupBox1";
  118. this.groupBox1.Size = new System.Drawing.Size(776, 88);
  119. this.groupBox1.TabIndex = 0;
  120. this.groupBox1.TabStop = false;
  121. //
  122. // btnClose
  123. //
  124. this.btnClose.Location = new System.Drawing.Point(663, 32);
  125. this.btnClose.Name = "btnClose";
  126. this.btnClose.Size = new System.Drawing.Size(79, 36);
  127. this.btnClose.TabIndex = 3;
  128. this.btnClose.UseVisualStyleBackColor = true;
  129. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  130. //
  131. // btnCommit
  132. //
  133. this.btnCommit.Location = new System.Drawing.Point(550, 32);
  134. this.btnCommit.Name = "btnCommit";
  135. this.btnCommit.Size = new System.Drawing.Size(79, 36);
  136. this.btnCommit.TabIndex = 2;
  137. this.btnCommit.UseVisualStyleBackColor = true;
  138. this.btnCommit.Click += new System.EventHandler(this.btnCommit_Click);
  139. //
  140. // groupBox2
  141. //
  142. this.groupBox2.Controls.Add(this.pnlVoltage);
  143. this.groupBox2.Controls.Add(this.label14);
  144. this.groupBox2.Controls.Add(this.label13);
  145. this.groupBox2.Controls.Add(this.label12);
  146. this.groupBox2.Controls.Add(this.txtBaudRate);
  147. this.groupBox2.Controls.Add(this.label10);
  148. this.groupBox2.Controls.Add(this.cmbPort);
  149. this.groupBox2.Controls.Add(this.label11);
  150. this.groupBox2.Controls.Add(this.txtDefaultVoltage);
  151. this.groupBox2.Controls.Add(this.label9);
  152. this.groupBox2.Controls.Add(this.btnSetVoltage);
  153. this.groupBox2.Controls.Add(this.trbVoltage);
  154. this.groupBox2.Controls.Add(this.txtVoltage);
  155. this.groupBox2.Controls.Add(this.txtButtonStepping);
  156. this.groupBox2.Controls.Add(this.label3);
  157. this.groupBox2.Controls.Add(this.txtEC11Stepping);
  158. this.groupBox2.Controls.Add(this.label2);
  159. this.groupBox2.Controls.Add(this.rdoBoth);
  160. this.groupBox2.Controls.Add(this.rdoEC11);
  161. this.groupBox2.Controls.Add(this.rdoUSB);
  162. this.groupBox2.Controls.Add(this.label1);
  163. this.groupBox2.Location = new System.Drawing.Point(12, 210);
  164. this.groupBox2.Name = "groupBox2";
  165. this.groupBox2.Size = new System.Drawing.Size(776, 313);
  166. this.groupBox2.TabIndex = 1;
  167. this.groupBox2.TabStop = false;
  168. //
  169. // pnlVoltage
  170. //
  171. this.pnlVoltage.Controls.Add(this.btnDel1);
  172. this.pnlVoltage.Controls.Add(this.btnVoltage1);
  173. this.pnlVoltage.Location = new System.Drawing.Point(32, 250);
  174. this.pnlVoltage.Name = "pnlVoltage";
  175. this.pnlVoltage.Size = new System.Drawing.Size(722, 57);
  176. this.pnlVoltage.TabIndex = 30;
  177. //
  178. // btnDel1
  179. //
  180. this.btnDel1.Location = new System.Drawing.Point(78, 0);
  181. this.btnDel1.Name = "btnDel1";
  182. this.btnDel1.Size = new System.Drawing.Size(38, 31);
  183. this.btnDel1.TabIndex = 14;
  184. this.btnDel1.Text = "X";
  185. this.btnDel1.UseVisualStyleBackColor = true;
  186. //
  187. // btnVoltage1
  188. //
  189. this.btnVoltage1.Location = new System.Drawing.Point(0, 0);
  190. this.btnVoltage1.Name = "btnVoltage1";
  191. this.btnVoltage1.Size = new System.Drawing.Size(78, 31);
  192. this.btnVoltage1.TabIndex = 13;
  193. this.btnVoltage1.Text = "0.85V";
  194. this.btnVoltage1.UseVisualStyleBackColor = true;
  195. //
  196. // label14
  197. //
  198. this.label14.AutoSize = true;
  199. this.label14.Location = new System.Drawing.Point(583, 164);
  200. this.label14.Name = "label14";
  201. this.label14.Size = new System.Drawing.Size(15, 15);
  202. this.label14.TabIndex = 29;
  203. this.label14.Text = "V";
  204. //
  205. // label13
  206. //
  207. this.label13.AutoSize = true;
  208. this.label13.Location = new System.Drawing.Point(300, 164);
  209. this.label13.Name = "label13";
  210. this.label13.Size = new System.Drawing.Size(15, 15);
  211. this.label13.TabIndex = 28;
  212. this.label13.Text = "V";
  213. //
  214. // label12
  215. //
  216. this.label12.AutoSize = true;
  217. this.label12.Location = new System.Drawing.Point(298, 86);
  218. this.label12.Name = "label12";
  219. this.label12.Size = new System.Drawing.Size(15, 15);
  220. this.label12.TabIndex = 27;
  221. this.label12.Text = "V";
  222. //
  223. // txtBaudRate
  224. //
  225. this.txtBaudRate.Location = new System.Drawing.Point(348, 35);
  226. this.txtBaudRate.Name = "txtBaudRate";
  227. this.txtBaudRate.Size = new System.Drawing.Size(100, 25);
  228. this.txtBaudRate.TabIndex = 26;
  229. this.txtBaudRate.Text = "9600";
  230. this.txtBaudRate.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtBaudRate_KeyPress);
  231. //
  232. // label10
  233. //
  234. this.label10.AutoSize = true;
  235. this.label10.Location = new System.Drawing.Point(266, 40);
  236. this.label10.Name = "label10";
  237. this.label10.Size = new System.Drawing.Size(67, 15);
  238. this.label10.TabIndex = 25;
  239. //
  240. // cmbPort
  241. //
  242. this.cmbPort.FormattingEnabled = true;
  243. this.cmbPort.Location = new System.Drawing.Point(105, 37);
  244. this.cmbPort.Name = "cmbPort";
  245. this.cmbPort.Size = new System.Drawing.Size(121, 23);
  246. this.cmbPort.TabIndex = 24;
  247. //
  248. // label11
  249. //
  250. this.label11.AutoSize = true;
  251. this.label11.Location = new System.Drawing.Point(32, 40);
  252. this.label11.Name = "label11";
  253. this.label11.Size = new System.Drawing.Size(67, 15);
  254. this.label11.TabIndex = 23;
  255. //
  256. // txtDefaultVoltage
  257. //
  258. this.txtDefaultVoltage.Location = new System.Drawing.Point(215, 81);
  259. this.txtDefaultVoltage.Name = "txtDefaultVoltage";
  260. this.txtDefaultVoltage.Size = new System.Drawing.Size(79, 25);
  261. this.txtDefaultVoltage.TabIndex = 22;
  262. this.txtDefaultVoltage.Text = "10.25";
  263. this.txtDefaultVoltage.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress);
  264. //
  265. // label9
  266. //
  267. this.label9.AutoSize = true;
  268. this.label9.Location = new System.Drawing.Point(29, 84);
  269. this.label9.Name = "label9";
  270. this.label9.Size = new System.Drawing.Size(127, 15);
  271. this.label9.TabIndex = 21;
  272. //
  273. // btnSetVoltage
  274. //
  275. this.btnSetVoltage.Location = new System.Drawing.Point(611, 195);
  276. this.btnSetVoltage.Name = "btnSetVoltage";
  277. this.btnSetVoltage.Size = new System.Drawing.Size(143, 35);
  278. this.btnSetVoltage.TabIndex = 10;
  279. this.btnSetVoltage.UseVisualStyleBackColor = true;
  280. this.btnSetVoltage.Click += new System.EventHandler(this.btnSetVoltage_Click);
  281. //
  282. // trbVoltage
  283. //
  284. this.trbVoltage.AutoSize = false;
  285. this.trbVoltage.Location = new System.Drawing.Point(138, 205);
  286. this.trbVoltage.Maximum = 1220;
  287. this.trbVoltage.Minimum = 960;
  288. this.trbVoltage.Name = "trbVoltage";
  289. this.trbVoltage.Size = new System.Drawing.Size(467, 25);
  290. this.trbVoltage.TabIndex = 9;
  291. this.trbVoltage.TickStyle = System.Windows.Forms.TickStyle.None;
  292. this.trbVoltage.Value = 960;
  293. this.trbVoltage.ValueChanged += new System.EventHandler(this.trbVoltage_ValueChanged);
  294. //
  295. // txtVoltage
  296. //
  297. this.txtVoltage.Location = new System.Drawing.Point(32, 205);
  298. this.txtVoltage.Name = "txtVoltage";
  299. this.txtVoltage.ReadOnly = true;
  300. this.txtVoltage.Size = new System.Drawing.Size(100, 25);
  301. this.txtVoltage.TabIndex = 8;
  302. this.txtVoltage.Text = "9.6";
  303. //
  304. // txtButtonStepping
  305. //
  306. this.txtButtonStepping.Location = new System.Drawing.Point(477, 159);
  307. this.txtButtonStepping.Name = "txtButtonStepping";
  308. this.txtButtonStepping.Size = new System.Drawing.Size(100, 25);
  309. this.txtButtonStepping.TabIndex = 7;
  310. this.txtButtonStepping.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress);
  311. //
  312. // label3
  313. //
  314. this.label3.AutoSize = true;
  315. this.label3.Location = new System.Drawing.Point(333, 162);
  316. this.label3.Name = "label3";
  317. this.label3.Size = new System.Drawing.Size(127, 15);
  318. this.label3.TabIndex = 6;
  319. //
  320. // txtEC11Stepping
  321. //
  322. this.txtEC11Stepping.Location = new System.Drawing.Point(215, 159);
  323. this.txtEC11Stepping.Name = "txtEC11Stepping";
  324. this.txtEC11Stepping.Size = new System.Drawing.Size(79, 25);
  325. this.txtEC11Stepping.TabIndex = 5;
  326. this.txtEC11Stepping.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress);
  327. //
  328. // label2
  329. //
  330. this.label2.AutoSize = true;
  331. this.label2.Location = new System.Drawing.Point(29, 162);
  332. this.label2.Name = "label2";
  333. this.label2.Size = new System.Drawing.Size(189, 15);
  334. this.label2.TabIndex = 4;
  335. //
  336. // rdoBoth
  337. //
  338. this.rdoBoth.AutoSize = true;
  339. this.rdoBoth.Location = new System.Drawing.Point(319, 123);
  340. this.rdoBoth.Name = "rdoBoth";
  341. this.rdoBoth.Size = new System.Drawing.Size(108, 19);
  342. this.rdoBoth.TabIndex = 3;
  343. this.rdoBoth.Text = "USB && EC11";
  344. this.rdoBoth.UseVisualStyleBackColor = true;
  345. //
  346. // rdoEC11
  347. //
  348. this.rdoEC11.AutoSize = true;
  349. this.rdoEC11.Location = new System.Drawing.Point(239, 123);
  350. this.rdoEC11.Name = "rdoEC11";
  351. this.rdoEC11.Size = new System.Drawing.Size(60, 19);
  352. this.rdoEC11.TabIndex = 2;
  353. this.rdoEC11.Text = "EC11";
  354. this.rdoEC11.UseVisualStyleBackColor = true;
  355. //
  356. // rdoUSB
  357. //
  358. this.rdoUSB.AutoSize = true;
  359. this.rdoUSB.Checked = true;
  360. this.rdoUSB.Location = new System.Drawing.Point(157, 123);
  361. this.rdoUSB.Name = "rdoUSB";
  362. this.rdoUSB.Size = new System.Drawing.Size(52, 19);
  363. this.rdoUSB.TabIndex = 1;
  364. this.rdoUSB.TabStop = true;
  365. this.rdoUSB.Text = "USB";
  366. this.rdoUSB.UseVisualStyleBackColor = true;
  367. //
  368. // label1
  369. //
  370. this.label1.AutoSize = true;
  371. this.label1.Location = new System.Drawing.Point(29, 123);
  372. this.label1.Name = "label1";
  373. this.label1.Size = new System.Drawing.Size(97, 15);
  374. this.label1.TabIndex = 0;
  375. //
  376. // groupBox3
  377. //
  378. this.groupBox3.Controls.Add(this.lblPower);
  379. this.groupBox3.Controls.Add(this.lblVoltageOut);
  380. this.groupBox3.Controls.Add(this.lblState);
  381. this.groupBox3.Controls.Add(this.lblVoltageIn);
  382. this.groupBox3.Controls.Add(this.lblPotentiometer);
  383. this.groupBox3.Controls.Add(this.btnSearch);
  384. this.groupBox3.Controls.Add(this.label8);
  385. this.groupBox3.Controls.Add(this.label7);
  386. this.groupBox3.Controls.Add(this.label6);
  387. this.groupBox3.Controls.Add(this.label5);
  388. this.groupBox3.Controls.Add(this.label4);
  389. this.groupBox3.Location = new System.Drawing.Point(12, 106);
  390. this.groupBox3.Name = "groupBox3";
  391. this.groupBox3.Size = new System.Drawing.Size(776, 98);
  392. this.groupBox3.TabIndex = 2;
  393. this.groupBox3.TabStop = false;
  394. //
  395. // lblPower
  396. //
  397. this.lblPower.AutoSize = true;
  398. this.lblPower.Location = new System.Drawing.Point(466, 63);
  399. this.lblPower.Name = "lblPower";
  400. this.lblPower.Size = new System.Drawing.Size(0, 15);
  401. this.lblPower.TabIndex = 10;
  402. //
  403. // lblVoltageOut
  404. //
  405. this.lblVoltageOut.AutoSize = true;
  406. this.lblVoltageOut.Location = new System.Drawing.Point(283, 63);
  407. this.lblVoltageOut.Name = "lblVoltageOut";
  408. this.lblVoltageOut.Size = new System.Drawing.Size(0, 15);
  409. this.lblVoltageOut.TabIndex = 9;
  410. //
  411. // lblState
  412. //
  413. this.lblState.AutoSize = true;
  414. this.lblState.Location = new System.Drawing.Point(283, 33);
  415. this.lblState.Name = "lblState";
  416. this.lblState.Size = new System.Drawing.Size(0, 15);
  417. this.lblState.TabIndex = 8;
  418. //
  419. // lblVoltageIn
  420. //
  421. this.lblVoltageIn.AutoSize = true;
  422. this.lblVoltageIn.Location = new System.Drawing.Point(107, 63);
  423. this.lblVoltageIn.Name = "lblVoltageIn";
  424. this.lblVoltageIn.Size = new System.Drawing.Size(0, 15);
  425. this.lblVoltageIn.TabIndex = 7;
  426. //
  427. // lblPotentiometer
  428. //
  429. this.lblPotentiometer.AutoSize = true;
  430. this.lblPotentiometer.Location = new System.Drawing.Point(107, 33);
  431. this.lblPotentiometer.Name = "lblPotentiometer";
  432. this.lblPotentiometer.Size = new System.Drawing.Size(0, 15);
  433. this.lblPotentiometer.TabIndex = 6;
  434. //
  435. // btnSearch
  436. //
  437. this.btnSearch.Location = new System.Drawing.Point(651, 38);
  438. this.btnSearch.Name = "btnSearch";
  439. this.btnSearch.Size = new System.Drawing.Size(91, 33);
  440. this.btnSearch.TabIndex = 5;
  441. this.btnSearch.UseVisualStyleBackColor = true;
  442. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  443. //
  444. // label8
  445. //
  446. this.label8.AutoSize = true;
  447. this.label8.Location = new System.Drawing.Point(378, 63);
  448. this.label8.Name = "label8";
  449. this.label8.Size = new System.Drawing.Size(82, 15);
  450. this.label8.TabIndex = 4;
  451. //
  452. // label7
  453. //
  454. this.label7.AutoSize = true;
  455. this.label7.Location = new System.Drawing.Point(195, 63);
  456. this.label7.Name = "label7";
  457. this.label7.Size = new System.Drawing.Size(82, 15);
  458. this.label7.TabIndex = 3;
  459. //
  460. // label6
  461. //
  462. this.label6.AutoSize = true;
  463. this.label6.Location = new System.Drawing.Point(29, 63);
  464. this.label6.Name = "label6";
  465. this.label6.Size = new System.Drawing.Size(82, 15);
  466. this.label6.TabIndex = 2;
  467. //
  468. // label5
  469. //
  470. this.label5.AutoSize = true;
  471. this.label5.Location = new System.Drawing.Point(195, 33);
  472. this.label5.Name = "label5";
  473. this.label5.Size = new System.Drawing.Size(82, 15);
  474. this.label5.TabIndex = 1;
  475. //
  476. // label4
  477. //
  478. this.label4.AutoSize = true;
  479. this.label4.Location = new System.Drawing.Point(29, 33);
  480. this.label4.Name = "label4";
  481. this.label4.Size = new System.Drawing.Size(67, 15);
  482. this.label4.TabIndex = 0;
  483. //
  484. // SetVoltageDialog
  485. //
  486. this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
  487. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  488. this.ClientSize = new System.Drawing.Size(799, 535);
  489. this.Controls.Add(this.groupBox3);
  490. this.Controls.Add(this.groupBox2);
  491. this.Controls.Add(this.groupBox1);
  492. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  493. this.MaximizeBox = false;
  494. this.MinimizeBox = false;
  495. this.Name = "SetVoltageDialog";
  496. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SetVoltageDialog_FormClosing);
  497. this.groupBox1.ResumeLayout(false);
  498. this.groupBox2.ResumeLayout(false);
  499. this.groupBox2.PerformLayout();
  500. this.pnlVoltage.ResumeLayout(false);
  501. ((System.ComponentModel.ISupportInitialize)(this.trbVoltage)).EndInit();
  502. this.groupBox3.ResumeLayout(false);
  503. this.groupBox3.PerformLayout();
  504. this.ResumeLayout(false);
  505. }
  506. #endregion
  507. private System.Windows.Forms.GroupBox groupBox1;
  508. private System.Windows.Forms.GroupBox groupBox2;
  509. private System.Windows.Forms.Label label1;
  510. private System.Windows.Forms.TextBox txtButtonStepping;
  511. private System.Windows.Forms.Label label3;
  512. private System.Windows.Forms.TextBox txtEC11Stepping;
  513. private System.Windows.Forms.Label label2;
  514. private System.Windows.Forms.RadioButton rdoBoth;
  515. private System.Windows.Forms.RadioButton rdoEC11;
  516. private System.Windows.Forms.RadioButton rdoUSB;
  517. private System.Windows.Forms.Button btnClose;
  518. private System.Windows.Forms.Button btnCommit;
  519. private System.Windows.Forms.TextBox txtVoltage;
  520. private System.Windows.Forms.Button btnSetVoltage;
  521. private System.Windows.Forms.TrackBar trbVoltage;
  522. private System.Windows.Forms.GroupBox groupBox3;
  523. private System.Windows.Forms.Button btnSearch;
  524. private System.Windows.Forms.Label label8;
  525. private System.Windows.Forms.Label label7;
  526. private System.Windows.Forms.Label label6;
  527. private System.Windows.Forms.Label label5;
  528. private System.Windows.Forms.Label label4;
  529. private System.Windows.Forms.TextBox txtDefaultVoltage;
  530. private System.Windows.Forms.Label label9;
  531. private System.Windows.Forms.TextBox txtBaudRate;
  532. private System.Windows.Forms.Label label10;
  533. private System.Windows.Forms.ComboBox cmbPort;
  534. private System.Windows.Forms.Label label11;
  535. private System.Windows.Forms.Label label14;
  536. private System.Windows.Forms.Label label13;
  537. private System.Windows.Forms.Label label12;
  538. private System.Windows.Forms.Panel pnlVoltage;
  539. private System.Windows.Forms.Button btnDel1;
  540. private System.Windows.Forms.Button btnVoltage1;
  541. private System.Windows.Forms.Label lblPower;
  542. private System.Windows.Forms.Label lblVoltageOut;
  543. private System.Windows.Forms.Label lblState;
  544. private System.Windows.Forms.Label lblVoltageIn;
  545. private System.Windows.Forms.Label lblPotentiometer;
  546. #endregion
  547. private VoltageModel m_voltageModel;
  548. private List<VoltageModel.Item> m_voltages = new List<VoltageModel.Item>();
  549. private VoltageController m_voltageController;
  550. private string m_portName;
  551. private int m_baudRate;
  552. private bool m_isOpen;
  553. public SetVoltageDialog()
  554. {
  555. InitializeComponent();
  556. InitializeLanguageText();
  557. GetSerialLst();
  558. InitializeData();
  559. }
  560. private void InitializeData()
  561. {
  562. m_voltageModel = Startup.instance.voltageModel;
  563. m_portName = m_voltageModel.PortName;
  564. m_baudRate = m_voltageModel.BaudRate;
  565. cmbPort.SelectedItem = m_portName;
  566. txtBaudRate.Text = m_baudRate.ToString();
  567. txtDefaultVoltage.Text = m_voltageModel.DefaultVoltage.ToString();
  568. txtEC11Stepping.Text = m_voltageModel.EC11Stepping.ToString();
  569. txtButtonStepping.Text = m_voltageModel.ButtonStepping.ToString();
  570. switch (m_voltageModel.Controls)
  571. {
  572. case "USB":
  573. rdoUSB.Checked = true;
  574. break;
  575. case "EC11":
  576. rdoEC11.Checked = true;
  577. break;
  578. default:
  579. rdoBoth.Checked = true;
  580. break;
  581. }
  582. m_voltages = m_voltageModel.items;
  583. this.SetVoltages();
  584. m_voltageController = VoltageController.GetInstance();
  585. m_voltageController.Close();
  586. m_voltageController.VoltageReceived += new VoltageEvent(CallbackDataReceived);
  587. if(cmbPort.Text.Length != 0)
  588. {
  589. this.Search();
  590. }
  591. }
  592. private void SetVoltages()
  593. {
  594. Button voltageButton;
  595. Button delButton;
  596. pnlVoltage.Controls.Clear();
  597. for (int i=0; i< m_voltages.Count; i++)
  598. {
  599. voltageButton = new Button();
  600. voltageButton.Size = new Size(60, 25);
  601. voltageButton.Name = "voltage" + i.ToString();
  602. voltageButton.Text = m_voltages[i].Voltage.ToString()+"V";
  603. voltageButton.Click += new System.EventHandler(this.Voltage_Click);
  604. voltageButton.Location = new Point(i * 100, 0);
  605. pnlVoltage.Controls.Add(voltageButton);
  606. delButton = new Button();
  607. delButton.Size = new Size(20, 25);
  608. delButton.Name = "del" + i.ToString();
  609. delButton.Text = "X";
  610. //delButton.FlatStyle = FlatStyle.Flat;
  611. //delButton.FlatAppearance.BorderSize = 0;
  612. //delButton.BackgroundImageLayout = ImageLayout.Zoom;
  613. //delButton.BackgroundImage = PdnResources.GetImageResource("Images.ButtonUp.png").Reference;
  614. delButton.Click += new System.EventHandler(this.VoltageDel_Click);
  615. delButton.Location = new Point(i * 100 + 60, 0);
  616. pnlVoltage.Controls.Add(delButton);
  617. }
  618. }
  619. private void Voltage_Click(object sender, EventArgs e)
  620. {
  621. Button button = (Button)sender;
  622. int index = int.Parse(button.Name.Trim().Replace("voltage", ""));
  623. trbVoltage.Value = (int)(m_voltages[index].Voltage * 100);
  624. this.Open();
  625. if (m_isOpen)
  626. {
  627. string value = "0" + m_voltages[index].Voltage * 100;
  628. string commandText = "*309*" + value.Substring(value.Length > 4 ? 1 : 0) + "#";
  629. CommandVoltage command = new CommandVoltage(commandText);
  630. m_voltageController.AddCommand(command);
  631. }
  632. }
  633. private void VoltageDel_Click(object sender, EventArgs e)
  634. {
  635. Button button = (Button)sender;
  636. int index = int.Parse(button.Name.Trim().Replace("del", ""));
  637. m_voltages.RemoveAt(index);
  638. this.SetVoltages();
  639. }
  640. private void btnSetVoltage_Click(object sender, EventArgs e)
  641. {
  642. if (m_voltages.Count >= 5)
  643. {
  644. MessageBox.Show(PdnResources.GetString("Menu.Upto5presets.Text"));
  645. return;
  646. }
  647. for (int i = 0; i < m_voltages.Count; i++)
  648. {
  649. if (m_voltages[i].Voltage.ToString().Equals(txtVoltage.Text.Trim()))
  650. {
  651. return;
  652. }
  653. }
  654. VoltageModel.Item item = new VoltageModel.Item();
  655. item.Voltage = decimal.Parse(txtVoltage.Text.Trim());
  656. m_voltages.Add(item);
  657. this.SetVoltages();
  658. }
  659. private void CallbackDataReceived(CommandBase command, Result result, string msg)
  660. {
  661. if (this == null || this.IsDisposed)
  662. {
  663. return;
  664. }
  665. switch (result)
  666. {
  667. case Result.ERR_PARSE:
  668. MessageBox.Show(PdnResources.GetString("Menu.Replydataarsingerror.Text")+":" + msg);
  669. return;
  670. case Result.ERR_TIMEOUT:
  671. MessageBox.Show(PdnResources.GetString("Menu.Theconsoleresponsetimeout.Text"));
  672. return;
  673. }
  674. if (command is CommandVoltage)
  675. {
  676. // *301*0723,1,1500,1100,07000#
  677. if (msg.Substring(0, 4).Equals("*301"))
  678. {
  679. this.Invoke(new Action(() =>
  680. {
  681. lblPotentiometer.Text = msg.Substring(5, 4);
  682. switch (msg.Substring(10, 1))
  683. {
  684. case "0":
  685. lblState.Text = PdnResources.GetString("Menu.Normalhutdow.Text");
  686. break;
  687. case "1":
  688. lblState.Text = PdnResources.GetString("Menu.Normalboot.Text");
  689. break;
  690. case "2":
  691. lblState.Text = PdnResources.GetString("Menu.Abnormaloperation.Text");
  692. break;
  693. case "3":
  694. lblState.Text = PdnResources.GetString("Menu.Abnormalshutdown.Text");
  695. break;
  696. }
  697. lblVoltageIn.Text = (decimal.Parse( msg.Substring(12, 4)) / 100).ToString() + "V";
  698. lblVoltageOut.Text = (decimal.Parse(msg.Substring(17, 4)) / 100).ToString() + "V";
  699. lblPower.Text = (decimal.Parse(msg.Substring(22, 5)) / 10000).ToString() + "A";
  700. }));
  701. }
  702. }
  703. }
  704. private void Open()
  705. {
  706. if (this.cmbPort.Text.Trim().Length == 0)
  707. {
  708. MessageBox.Show(PdnResources.GetString("Menu.Theportnumbercannobeempty.Text"));
  709. return;
  710. }
  711. if (this.txtBaudRate.Text.Trim().Length == 0)
  712. {
  713. MessageBox.Show(PdnResources.GetString("Menu.Baudrempty.text"));
  714. return;
  715. }
  716. try
  717. {
  718. m_portName = this.cmbPort.Text.Trim();
  719. m_baudRate = int.Parse(this.txtBaudRate.Text.Trim());
  720. m_voltageController.Open(m_portName, m_baudRate);
  721. m_isOpen = true;
  722. }
  723. catch (Exception)
  724. {
  725. m_isOpen = false;
  726. // 串口无法打开时,打开参数设置界面
  727. //MessageBox.Show(ex.Message);
  728. }
  729. }
  730. private void GetSerialLst()
  731. {
  732. //清除cmbPort显示
  733. cmbPort.SelectedIndex = -1;
  734. cmbPort.Items.Clear();
  735. //获取串口列表
  736. string[] serialLst = SerialPort.GetPortNames();
  737. if (serialLst.Length > 0)
  738. {
  739. //取串口列表进行排序
  740. Array.Sort(serialLst);
  741. //将串口列表输出到comboBox
  742. cmbPort.Items.AddRange(serialLst);
  743. cmbPort.SelectedIndex = 0;
  744. }
  745. }
  746. public const int WM_DEVICE_CHANGE = 0x219; //设备改变
  747. public const int DBT_DEVICEARRIVAL = 0x8000; //设备插入
  748. public const int DBT_DEVICE_REMOVE_COMPLETE = 0x8004; //设备移除
  749. //消息处理
  750. protected override void WndProc(ref Message m)
  751. {
  752. switch (m.Msg) //判断消息类型
  753. {
  754. case WM_DEVICE_CHANGE: //设备改变消息
  755. {
  756. GetSerialLst(); //设备改变时重新获取串口列表
  757. }
  758. break;
  759. }
  760. base.WndProc(ref m);
  761. }
  762. private void CheckKeyPress(object sender, KeyPressEventArgs e)
  763. {
  764. TextBox textBox = (TextBox)sender;
  765. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  766. e.Handled = true;
  767. //小数点的处理。
  768. if ((int)e.KeyChar == 46) //小数点
  769. {
  770. if (textBox.Text.Length <= 0)
  771. e.Handled = true; //小数点不能在第一位
  772. else
  773. {
  774. float f;
  775. float oldf;
  776. bool b1 = false, b2 = false;
  777. b1 = float.TryParse(textBox.Text, out oldf);
  778. b2 = float.TryParse(textBox.Text + e.KeyChar.ToString(), out f);
  779. if (b2 == false)
  780. {
  781. if (b1 == true)
  782. e.Handled = true;
  783. else
  784. e.Handled = false;
  785. }
  786. }
  787. }
  788. }
  789. private void btnClose_Click(object sender, EventArgs e)
  790. {
  791. this.Close();
  792. }
  793. private void trbVoltage_ValueChanged(object sender, EventArgs e)
  794. {
  795. txtVoltage.Text = (trbVoltage.Value * 0.01).ToString();
  796. }
  797. private void btnSearch_Click(object sender, EventArgs e)
  798. {
  799. this.Search();
  800. }
  801. private void Search()
  802. {
  803. this.Open();
  804. if (m_isOpen)
  805. {
  806. CommandVoltage command = new CommandVoltage("*301#");
  807. m_voltageController.AddCommand(command);
  808. }
  809. }
  810. private void btnCommit_Click(object sender, EventArgs e)
  811. {
  812. if (this.cmbPort.Text.Trim().Length == 0)
  813. {
  814. MessageBox.Show(PdnResources.GetString("Menu.Theportnumbercannobeempty.Text"));
  815. return;
  816. }
  817. if (this.txtBaudRate.Text.Trim().Length == 0)
  818. {
  819. MessageBox.Show(PdnResources.GetString("Menu.Baudrempty.text"));
  820. return;
  821. }
  822. decimal defaultVoltage = decimal.Parse(txtDefaultVoltage.Text.Trim());
  823. if (defaultVoltage < (decimal)9.6 || defaultVoltage > (decimal)12.2)
  824. {
  825. MessageBox.Show(PdnResources.GetString("Menu.Voltagesettingrange.Text")+"9.6V ~ 12.2V");
  826. return;
  827. }
  828. decimal ec11Stepping = decimal.Parse(txtEC11Stepping.Text.Trim());
  829. decimal buttonStepping = decimal.Parse(txtButtonStepping.Text.Trim());
  830. if (ec11Stepping < (decimal)0.01)
  831. {
  832. MessageBox.Show(PdnResources.GetString("Menu.EC11rotarysteppingvoltagevalueunitV.Text"));
  833. return;
  834. }
  835. if (buttonStepping < (decimal)0.01)
  836. {
  837. MessageBox.Show(PdnResources.GetString("Menu.Buttonsteppingvoltagevalueuni.Text"));
  838. return;
  839. }
  840. m_voltageModel.PortName = m_portName;
  841. m_voltageModel.BaudRate = m_baudRate;
  842. m_voltageModel.DefaultVoltage = decimal.Parse(txtDefaultVoltage.Text.Trim());
  843. string code;
  844. if (rdoUSB.Checked)
  845. {
  846. m_voltageModel.Controls = "USB";
  847. code = "01";
  848. }
  849. else if (rdoEC11.Checked)
  850. {
  851. m_voltageModel.Controls = "EC11";
  852. code = "10";
  853. }
  854. else
  855. {
  856. m_voltageModel.Controls = "BOTH";
  857. code = "11";
  858. }
  859. m_voltageModel.EC11Stepping = decimal.Parse(txtEC11Stepping.Text.Trim());
  860. m_voltageModel.ButtonStepping = decimal.Parse(txtButtonStepping.Text.Trim());
  861. string stageModelXml = XmlSerializeHelper.XmlSerialize<VoltageModel>(m_voltageModel);
  862. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\VoltageModel.xml";
  863. if (!FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create))
  864. {
  865. MessageBox.Show(PdnResources.GetString("Menu.Savefailed.text"));
  866. }
  867. else
  868. {
  869. this.Open();
  870. if (m_isOpen)
  871. {
  872. // 设置开机默认电压
  873. string defaultValue = ("0" + m_voltageModel.DefaultVoltage * 100);
  874. CommandVoltage command = new CommandVoltage("*305*" + defaultValue.Substring(defaultValue.Length > 4 ? 1 : 0) + "#");
  875. m_voltageController.AddCommand(command);
  876. // 设置控制源
  877. command = new CommandVoltage("*307*" + code + "#");
  878. m_voltageController.AddCommand(command);
  879. // *308*0008,0050#
  880. string ecValue = "000" + m_voltageModel.EC11Stepping * 100;
  881. string btnValue = "000" + m_voltageModel.ButtonStepping * 100;
  882. command = new CommandVoltage("*308*" + ecValue.Substring(ecValue.Length - 4, 4) + "," + btnValue.Substring(btnValue.Length - 4, 4) + "#");
  883. m_voltageController.AddCommand(command);
  884. }
  885. MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  886. }
  887. }
  888. private void SetVoltageDialog_FormClosing(object sender, FormClosingEventArgs e)
  889. {
  890. m_voltageController.VoltageReceived -= new VoltageEvent(CallbackDataReceived);
  891. m_voltageController.Close();
  892. }
  893. private void txtBaudRate_KeyPress(object sender, KeyPressEventArgs e)
  894. {
  895. if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
  896. {
  897. e.Handled = true;
  898. return;
  899. }
  900. }
  901. }
  902. }