SerialConfig.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:14k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: SerialConfig.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Drawing;
  7. using System.Collections;
  8. using System.ComponentModel;
  9. using System.Windows.Forms;
  10. using Poderosa.Toolkit;
  11. using EnumDescAttributeT = Poderosa.Toolkit.EnumDescAttribute;
  12. using Poderosa.Communication;
  13. using Poderosa.Terminal;
  14. using Poderosa.ConnectionParam;
  15. namespace Poderosa.Forms
  16. {
  17. /// <summary>
  18. /// 愙懕屻偵僔儕傾儖偺僷儔儊乕僞傪曄峏偡傞偨傔偺UI
  19. /// 儘僌僀儞僟僀傾儘僌偲偐傇偭偰偄傞張棟偼懡偄偺偱壗偲偐偟偨偄偲偙傠偱偼偁傞偑...
  20. /// </summary>
  21. internal class SerialConfigForm : System.Windows.Forms.Form
  22. {
  23. /// <summary>
  24. /// 昁梫側僨僓僀僫曄悢偱偡丅
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. private System.Windows.Forms.Button _loginButton;
  28. private System.Windows.Forms.Button _cancelButton;
  29. private ComboBox _flowControlBox;
  30. private System.Windows.Forms.Label _flowControlLabel;
  31. private ComboBox _stopBitsBox;
  32. private System.Windows.Forms.Label _stopBitsLabel;
  33. private ComboBox _parityBox;
  34. private System.Windows.Forms.Label _parityLabel;
  35. private ComboBox _dataBitsBox;
  36. private System.Windows.Forms.Label _dataBitsLabel;
  37. private ComboBox _baudRateBox;
  38. private System.Windows.Forms.Label _baudRateLabel;
  39. private Label _portBox; //億乕僩偼曄峏偱偒側偄
  40. private System.Windows.Forms.Label _portLabel;
  41. private Label _transmitDelayPerCharLabel;
  42. private TextBox _transmitDelayPerCharBox;
  43. private Label _transmitDelayPerLineLabel;
  44. private TextBox _transmitDelayPerLineBox;
  45. public SerialConfigForm()
  46. {
  47. //
  48. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  49. //
  50. InitializeComponent();
  51. //
  52. // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
  53. //
  54. this._portLabel.Text = GApp.Strings.GetString("Form.SerialConfig._portLabel");
  55. this._baudRateLabel.Text = GApp.Strings.GetString("Form.SerialConfig._baudRateLabel");
  56. this._dataBitsLabel.Text = GApp.Strings.GetString("Form.SerialConfig._dataBitsLabel");
  57. this._parityLabel.Text = GApp.Strings.GetString("Form.SerialConfig._parityLabel");
  58. this._stopBitsLabel.Text = GApp.Strings.GetString("Form.SerialConfig._stopBitsLabel");
  59. this._flowControlLabel.Text = GApp.Strings.GetString("Form.SerialConfig._flowControlLabel");
  60. string bits = GApp.Strings.GetString("Caption.SerialConfig.Bits");
  61. this._dataBitsBox.Items.AddRange(new object[] {
  62.   String.Format("{0}{1}", 7, bits),
  63.   String.Format("{0}{1}", 8, bits)});
  64. this.Text = GApp.Strings.GetString("Form.SerialConfig.Text");
  65. this._loginButton.Text = GApp.Strings.GetString("Common.OK");
  66. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  67. this._transmitDelayPerLineLabel.Text = "Transmit Delay(msec/line)";
  68. this._transmitDelayPerCharLabel.Text = "Transmit Delay(msec/char)";
  69. }
  70. /// <summary>
  71. /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
  72. /// </summary>
  73. protected override void Dispose( bool disposing )
  74. {
  75. if( disposing )
  76. {
  77. if(components != null)
  78. {
  79. components.Dispose();
  80. }
  81. }
  82. base.Dispose( disposing );
  83. }
  84. // this._flowControlBox.Items.AddRange(EnumDescAttributeT.For(typeof(FlowControl)).DescriptionCollection());
  85. // this._stopBitsBox.Items.AddRange(EnumDescAttributeT.For(typeof(StopBits)).DescriptionCollection());
  86. // this._parityBox.Items.AddRange(EnumDescAttributeT.For(typeof(Parity)).DescriptionCollection());
  87. // this._baudRateBox.Items.AddRange(TerminalUtil.BaudRates);
  88. #region Windows Form Designer generated code
  89. /// <summary>
  90. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  91. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  92. /// </summary>
  93. private void InitializeComponent()
  94. {
  95. this._portLabel = new System.Windows.Forms.Label();
  96. this._portBox = new System.Windows.Forms.Label();
  97. this._baudRateLabel = new System.Windows.Forms.Label();
  98. this._baudRateBox = new ComboBox();
  99. this._dataBitsLabel = new System.Windows.Forms.Label();
  100. this._dataBitsBox = new ComboBox();
  101. this._parityLabel = new System.Windows.Forms.Label();
  102. this._parityBox = new ComboBox();
  103. this._stopBitsLabel = new System.Windows.Forms.Label();
  104. this._stopBitsBox = new ComboBox();
  105. this._flowControlLabel = new System.Windows.Forms.Label();
  106. this._flowControlBox = new ComboBox();
  107. this._transmitDelayPerCharLabel = new Label();
  108. this._transmitDelayPerCharBox = new TextBox();
  109. this._transmitDelayPerLineLabel = new Label();
  110. this._transmitDelayPerLineBox = new TextBox();
  111. this._loginButton = new System.Windows.Forms.Button();
  112. this._cancelButton = new System.Windows.Forms.Button();
  113. this.SuspendLayout();
  114. // 
  115. // _portLabel
  116. // 
  117. this._portLabel.Location = new System.Drawing.Point(8, 16);
  118. this._portLabel.Name = "_portLabel";
  119. this._portLabel.Size = new System.Drawing.Size(88, 23);
  120. this._portLabel.TabIndex = 0;
  121. this._portLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  122. // 
  123. // _portBox
  124. // 
  125. this._portBox.Location = new System.Drawing.Point(112, 20);
  126. this._portBox.Name = "_portBox";
  127. this._portBox.Size = new System.Drawing.Size(96, 20);
  128. this._portBox.TabIndex = 1;
  129. // 
  130. // _baudRateLabel
  131. // 
  132. this._baudRateLabel.Location = new System.Drawing.Point(8, 40);
  133. this._baudRateLabel.Name = "_baudRateLabel";
  134. this._baudRateLabel.Size = new System.Drawing.Size(88, 23);
  135. this._baudRateLabel.TabIndex = 2;
  136. this._baudRateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  137. // 
  138. // _baudRateBox
  139. // 
  140. this._baudRateBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  141. this._baudRateBox.Items.AddRange(TerminalUtil.BaudRates);
  142. this._baudRateBox.Location = new System.Drawing.Point(112, 40);
  143. this._baudRateBox.Name = "_baudRateBox";
  144. this._baudRateBox.Size = new System.Drawing.Size(96, 20);
  145. this._baudRateBox.TabIndex = 3;
  146. // 
  147. // _dataBitsLabel
  148. // 
  149. this._dataBitsLabel.Location = new System.Drawing.Point(8, 64);
  150. this._dataBitsLabel.Name = "_dataBitsLabel";
  151. this._dataBitsLabel.Size = new System.Drawing.Size(88, 23);
  152. this._dataBitsLabel.TabIndex = 4;
  153. this._dataBitsLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  154. // 
  155. // _dataBitsBox
  156. // 
  157. this._dataBitsBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  158. this._dataBitsBox.Location = new System.Drawing.Point(112, 64);
  159. this._dataBitsBox.Name = "_dataBitsBox";
  160. this._dataBitsBox.Size = new System.Drawing.Size(96, 20);
  161. this._dataBitsBox.TabIndex = 5;
  162. // 
  163. // _parityLabel
  164. // 
  165. this._parityLabel.Location = new System.Drawing.Point(8, 88);
  166. this._parityLabel.Name = "_parityLabel";
  167. this._parityLabel.Size = new System.Drawing.Size(88, 23);
  168. this._parityLabel.TabIndex = 6;
  169. this._parityLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  170. // 
  171. // _parityBox
  172. // 
  173. this._parityBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  174. this._parityBox.Items.AddRange(EnumDescAttribute.For(typeof(Parity)).DescriptionCollection());
  175. this._parityBox.Location = new System.Drawing.Point(112, 88);
  176. this._parityBox.Name = "_parityBox";
  177. this._parityBox.Size = new System.Drawing.Size(96, 20);
  178. this._parityBox.TabIndex = 7;
  179. // 
  180. // _stopBitsLabel
  181. // 
  182. this._stopBitsLabel.Location = new System.Drawing.Point(8, 112);
  183. this._stopBitsLabel.Name = "_stopBitsLabel";
  184. this._stopBitsLabel.Size = new System.Drawing.Size(88, 23);
  185. this._stopBitsLabel.TabIndex = 8;
  186. this._stopBitsLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  187. // 
  188. // _stopBitsBox
  189. // 
  190. this._stopBitsBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  191. this._stopBitsBox.Items.AddRange(EnumDescAttribute.For(typeof(StopBits)).DescriptionCollection());
  192. this._stopBitsBox.Location = new System.Drawing.Point(112, 112);
  193. this._stopBitsBox.Name = "_stopBitsBox";
  194. this._stopBitsBox.Size = new System.Drawing.Size(96, 20);
  195. this._stopBitsBox.TabIndex = 9;
  196. // 
  197. // _flowControlLabel
  198. // 
  199. this._flowControlLabel.Location = new System.Drawing.Point(8, 136);
  200. this._flowControlLabel.Name = "_flowControlLabel";
  201. this._flowControlLabel.Size = new System.Drawing.Size(88, 23);
  202. this._flowControlLabel.TabIndex = 10;
  203. this._flowControlLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  204. // 
  205. // _flowControlBox
  206. // 
  207. this._flowControlBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  208. this._flowControlBox.Items.AddRange(EnumDescAttribute.For(typeof(FlowControl)).DescriptionCollection());
  209. this._flowControlBox.Location = new System.Drawing.Point(112, 136);
  210. this._flowControlBox.Name = "_flowControlBox";
  211. this._flowControlBox.Size = new System.Drawing.Size(96, 20);
  212. this._flowControlBox.TabIndex = 11;
  213. // 
  214. // _transmitDelayPerCharLabel
  215. // 
  216. this._transmitDelayPerCharLabel.Location = new System.Drawing.Point(8, 160);
  217. this._transmitDelayPerCharLabel.Name = "_transmitDelayPerCharLabel";
  218. this._transmitDelayPerCharLabel.Size = new System.Drawing.Size(88, 23);
  219. this._transmitDelayPerCharLabel.TabIndex = 12;
  220. this._transmitDelayPerCharLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  221. // 
  222. // _transmitDelayPerCharBox
  223. // 
  224. this._transmitDelayPerCharBox.Location = new System.Drawing.Point(112, 160);
  225. this._transmitDelayPerCharBox.Name = "_transmitDelayPerCharBox";
  226. this._transmitDelayPerCharBox.Size = new System.Drawing.Size(96, 20);
  227. this._transmitDelayPerCharBox.TabIndex = 13;
  228. this._transmitDelayPerCharBox.MaxLength = 3;
  229. // 
  230. // _transmitDelayPerLineLabel
  231. // 
  232. this._transmitDelayPerLineLabel.Location = new System.Drawing.Point(8, 184);
  233. this._transmitDelayPerLineLabel.Name = "_transmitDelayPerLineLabel";
  234. this._transmitDelayPerLineLabel.Size = new System.Drawing.Size(88, 23);
  235. this._transmitDelayPerLineLabel.TabIndex = 14;
  236. this._transmitDelayPerLineLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  237. // 
  238. // _transmitDelayPerLineBox
  239. // 
  240. this._transmitDelayPerLineBox.Location = new System.Drawing.Point(112, 184);
  241. this._transmitDelayPerLineBox.Name = "_transmitDelayPerLineBox";
  242. this._transmitDelayPerLineBox.Size = new System.Drawing.Size(96, 20);
  243. this._transmitDelayPerLineBox.TabIndex = 15;
  244. this._transmitDelayPerLineBox.MaxLength = 3;
  245. // 
  246. // _loginButton
  247. // 
  248. this._loginButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  249. this._loginButton.Location = new System.Drawing.Point(48, 216);
  250. this._loginButton.Name = "_loginButton";
  251. this._loginButton.FlatStyle = FlatStyle.System;
  252. this._loginButton.TabIndex = 16;
  253. this._loginButton.Click += new System.EventHandler(this.OnOK);
  254. // 
  255. // _cancelButton
  256. // 
  257. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  258. this._cancelButton.Location = new System.Drawing.Point(136, 216);
  259. this._cancelButton.Name = "_cancelButton";
  260. this._cancelButton.FlatStyle = FlatStyle.System;
  261. this._cancelButton.TabIndex = 17;
  262. // 
  263. // SerialConfig
  264. // 
  265. this.AcceptButton = this._loginButton;
  266. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  267. this.CancelButton = this._cancelButton;
  268. this.ClientSize = new System.Drawing.Size(218, 247);
  269. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  270. this._transmitDelayPerCharLabel,
  271. this._transmitDelayPerCharBox,
  272. this._transmitDelayPerLineLabel,
  273. this._transmitDelayPerLineBox,
  274.   this._flowControlBox,
  275.   this._flowControlLabel,
  276.   this._stopBitsBox,
  277.   this._stopBitsLabel,
  278.   this._parityBox,
  279.   this._parityLabel,
  280.   this._dataBitsBox,
  281.   this._dataBitsLabel,
  282.   this._baudRateBox,
  283.   this._baudRateLabel,
  284.   this._portBox,
  285.   this._portLabel,
  286.   this._loginButton,
  287.   this._cancelButton});
  288. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  289. this.MaximizeBox = false;
  290. this.MinimizeBox = false;
  291. this.Name = "SerialConfig";
  292. this.ShowInTaskbar = false;
  293. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  294. this.ResumeLayout(false);
  295. }
  296. #endregion
  297. private TerminalConnection _con;
  298. public void ApplyParam(TerminalConnection con) {
  299. _con = con;
  300. SerialTerminalParam param = (SerialTerminalParam)con.Param;
  301. _portBox.Text = "COM"+param.Port;
  302. _baudRateBox.SelectedIndex = _baudRateBox.FindStringExact(param.BaudRate.ToString());
  303. _dataBitsBox.SelectedIndex = param.ByteSize==7? 0 : 1;
  304. _parityBox.SelectedIndex = (int)param.Parity;
  305. _stopBitsBox.SelectedIndex = (int)param.StopBits;
  306. _flowControlBox.SelectedIndex = (int)param.FlowControl;
  307. _transmitDelayPerCharBox.Text = param.TransmitDelayPerChar.ToString();
  308. _transmitDelayPerLineBox.Text = param.TransmitDelayPerLine.ToString();
  309. }
  310. private void OnOK(object sender, EventArgs args) {
  311. SerialTerminalParam p = (SerialTerminalParam)_con.Param.Clone();
  312. p.BaudRate = Int32.Parse(_baudRateBox.Text);
  313. p.ByteSize = (byte)(_dataBitsBox.SelectedIndex==0? 7 : 8);
  314. p.StopBits = (StopBits)_stopBitsBox.SelectedIndex;
  315. p.Parity = (Parity)_parityBox.SelectedIndex;
  316. p.FlowControl = (FlowControl)_flowControlBox.SelectedIndex;
  317. try {
  318. p.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text);
  319. p.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text);
  320. }
  321. catch(Exception ex) {
  322. GUtil.Warning(this, ex.Message);
  323. this.DialogResult = DialogResult.None;
  324. return;
  325. }
  326. try {
  327. ((SerialTerminalConnection)_con).ApplySerialParam(p);
  328. this.DialogResult = DialogResult.OK;
  329. }
  330. catch(Exception ex) {
  331. GUtil.Warning(this, ex.Message);
  332. this.DialogResult = DialogResult.None;
  333. }
  334. }
  335. }
  336. }