using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; using StageController; using StageController.M3H; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace PaintDotNet.Hardware { public delegate void SetHandler(LoadingStageModel loadingStageModel); public class ParamSetingDialog : PdnBaseForm, IStageEvent { public event SetHandler Setted; // int i = 1; LoadingStageModel loadingStageModel = null; List lists = new List(); TableLayoutPanel table = new TableLayoutPanel(); private int m_speedCheckedCnt = 0; //声明组件 private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnSave; private System.Windows.Forms.GroupBox groupBox6; private System.Windows.Forms.TextBox tbxspeed; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox tbzspeed; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox tbyspeed; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox tbtripx; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox tbnav; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox tbtripy; private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label14; private System.Windows.Forms.TextBox tboecheck; private System.Windows.Forms.Label label13; private System.Windows.Forms.TextBox tbbps; private System.Windows.Forms.Label label12; private System.Windows.Forms.Button btnGetVersion; private System.Windows.Forms.Label lblVersion; private System.Windows.Forms.Label label15; private System.Windows.Forms.TextBox tbz; private System.Windows.Forms.Label label19; private System.Windows.Forms.TextBox tbxy; private System.Windows.Forms.Label label18; private System.Windows.Forms.Label label17; private System.Windows.Forms.Button btnadd; private System.Windows.Forms.Label label20; private System.Windows.Forms.ComboBox cmbPort; private DataGridView dgvSpeed; private DataGridViewCheckBoxColumn isShow; private DataGridViewTextBoxColumn name; private DataGridViewTextBoxColumn lSpeed; private DataGridViewTextBoxColumn zSpeed; private DataGridViewButtonColumn btnDel; private System.Windows.Forms.Panel panel1; private Form parentForm; private Label label10; private Label label16; private GroupBox groupBox3_HDS; private TextBox textBoxIP; private Label label23; private AxisController m_axisController; public ParamSetingDialog(Form form) { parentForm = form; InitializeComponent(); InitializeLanguageText(); if (!AxisController.ControllerType.Equals("HDS")) this.groupBox3_HDS.Visible = false; else { this.groupBox2.Visible = false; this.groupBox6.Location = new System.Drawing.Point(12, 74); this.groupBox6.Size = new System.Drawing.Size(382 + 243, 111); this.label11.Visible = false; int offsetX = 5; this.tbtripx.Location = new System.Drawing.Point(27 + offsetX, 20); this.tbtripy.Location = new System.Drawing.Point(27 + offsetX, 58); this.label6.Location = new System.Drawing.Point(108 + offsetX, 61); this.label5.Location = new System.Drawing.Point(108 + offsetX, 23); this.label7.Location = new System.Drawing.Point(4 + offsetX, 61); this.label4.Location = new System.Drawing.Point(4 + offsetX, 23); } loadingStageModel = Startup.instance.loadingStageModel; lists = loadingStageModel.items; try { string addrvalue = this.loadingStageModel.BaseSetAddr; this.textBoxIP.Text = addrvalue;//.ToString(); } catch (Exception) { } int bpsvalue = this.loadingStageModel.BaseSetBps; string port = this.loadingStageModel.BaseSetPort; string oddevencheckvalue = this.loadingStageModel.BaseSetOddEvenCheck; string navvalue = this.loadingStageModel.TripNavWin; string tripxvalue = this.loadingStageModel.TripX; string tripyvalue = this.loadingStageModel.TripY; string stepxvalue = this.loadingStageModel.SteppingX; string stepyvalue = this.loadingStageModel.SteppingY; string stepzvalue = this.loadingStageModel.SteppingZ; //设备值存储 this.tbbps.Text = bpsvalue.ToString(); this.tboecheck.Text = oddevencheckvalue; //基础值存储 this.tbtripx.Text = tripxvalue; this.tbtripy.Text = tripyvalue; this.tbnav.Text = navvalue; //cbport.Text this.tbxspeed.Text = stepxvalue; this.tbyspeed.Text = stepyvalue; this.tbzspeed.Text = stepzvalue; // 串口列表 GetSerialLst(); // 运行速度列表 dgvSpeedLoad(); } private void GetSerialLst() { //清除cmbPort显示 cmbPort.SelectedIndex = -1; cmbPort.Items.Clear(); //获取串口列表 string[] serialLst = SerialPort.GetPortNames(); if (serialLst.Length > 0) { //取串口列表进行排序 Array.Sort(serialLst); //将串口列表输出到comboBox cmbPort.Items.AddRange(serialLst); cmbPort.SelectedIndex = 0; } } public const int WM_DEVICE_CHANGE = 0x219; //设备改变 public const int DBT_DEVICEARRIVAL = 0x8000; //设备插入 public const int DBT_DEVICE_REMOVE_COMPLETE = 0x8004; //设备移除 //消息处理 protected override void WndProc(ref Message m) { switch (m.Msg) //判断消息类型 { case WM_DEVICE_CHANGE: //设备改变消息 { GetSerialLst(); //设备改变时重新获取串口列表 } break; } base.WndProc(ref m); } private void dgvSpeed_CellContentClick(object sender, DataGridViewCellEventArgs e) { // 修改显示是否选中 if (dgvSpeed.Columns[e.ColumnIndex].Name == "isShow" && e.RowIndex >= 0) { bool selectValue = Convert.ToBoolean(dgvSpeed.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue); if (selectValue) { if (m_speedCheckedCnt < 9) { lists[e.RowIndex].SChecked = 1; m_speedCheckedCnt++; } else { dgvSpeedLoad(); MessageBox.Show("最多选择9条记录"); } } else { if (lists[e.RowIndex].SChecked == 1) { m_speedCheckedCnt--; } lists[e.RowIndex].SChecked = 0; if (m_speedCheckedCnt > 9) { MessageBox.Show(PdnResources.GetString("Menu.Selectupto9records.Text")); } } } //点击button按钮事件 if (dgvSpeed.Columns[e.ColumnIndex].Name == "btnDel" && e.RowIndex >= 0) { DialogResult result = MessageBox.Show(PdnResources.GetString("Menu.suredeletit.Text") + "?", PdnResources.GetString("Menu.Tips.text"), MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { lists.RemoveAt(e.RowIndex); //dgvSpeed.Rows.RemoveAt(e.RowIndex); dgvSpeedLoad(); } } } /// /// 运行速度列表加载 /// private void dgvSpeedLoad() { dgvSpeed.Columns[0].Width = 80; dgvSpeed.Columns[1].Width = 80; m_speedCheckedCnt = 0; this.dgvSpeed.Rows.Clear(); foreach (LoadingStageModel.Item item in lists) { int index = this.dgvSpeed.Rows.Add(); if (item.SChecked == 1) { this.dgvSpeed.Rows[index].Cells[0].Value = true; m_speedCheckedCnt++; } else { this.dgvSpeed.Rows[index].Cells[0].Value = false; } //string lspeed = ("00" + item.LSpeed); //lspeed = lspeed.Substring(lspeed.Length - 3); //string zspeed = ("00" + item.ZSpeed); //zspeed = zspeed.Substring(zspeed.Length - 3); this.dgvSpeed.Rows[index].Cells[1].Value = (index + 1).ToString(); this.dgvSpeed.Rows[index].Cells[2].Value = item.LSpeed; this.dgvSpeed.Rows[index].Cells[3].Value = item.ZSpeed; } this.dgvSpeed.ClearSelection(); this.dgvSpeed.CurrentCell = null; if (dgvSpeed.Rows.Count > 0) this.dgvSpeed.Rows[0].Selected = false; } private void InitializeLanguageText() { this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text"); this.btnSave.Text = PdnResources.GetString("Menu.ensure.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.steppingaccuracy.text"); this.label20.Text = PdnResources.GetString("Menu.unit.text") + ":" + PdnResources.GetString("Menu.Micron.text"); this.groupBox3_HDS.Text = PdnResources.GetString("Menu.BasicSettings.text"); this.groupBox3.Text = PdnResources.GetString("Menu.BasicSettings.text"); this.label14.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.Paritycorrection.text") + ":"; this.label13.Text = PdnResources.GetString("Menu.Baudrate.text") + ":"; this.label12.Text = PdnResources.GetString("Menu.Deviceport.text") + ":"; this.groupBox4.Text = PdnResources.GetString("Menu.model.text"); this.btnGetVersion.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.Read.text"); this.label15.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.Currentstagemodel.text") + ":"; this.groupBox5.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.Speedsetting.text"); this.isShow.HeaderText = PdnResources.GetString("Menu.display.text"); this.lSpeed.HeaderText = PdnResources.GetString("Menu.Stage.text"); this.zSpeed.HeaderText = PdnResources.GetString("Menu.Zaxis.text"); this.name.HeaderText = PdnResources.GetString("Menu.name.text"); this.btnDel.HeaderText = PdnResources.GetString("Menu.operation.text"); this.btnDel.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.btnDel.ToolTipText = PdnResources.GetString("Menu.Edit.Delete.Text"); this.btnadd.Text = PdnResources.GetString("Menu.Addto.text"); this.label19.Text = PdnResources.GetString("Menu.Zaxis.text"); this.label18.Text = PdnResources.GetString("Menu.Stage.text"); this.label17.Text = PdnResources.GetString("Menu.Runningspeed.text") + ":"; this.groupBox6.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.travel.text"); this.label8.Text = PdnResources.GetString("Menu.Micron.text"); this.label9.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.navigatewindow.text") + ":"; this.label6.Text = PdnResources.GetString("Menu.Micron.text"); this.label5.Text = PdnResources.GetString("Menu.Micron.text"); this.Text = PdnResources.GetString("Menu.Hardwantrol.Locatavtion.Locationnavigationparamssettings.text"); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btnClose = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.label20 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.tbzspeed = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.tbyspeed = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.tbxspeed = new System.Windows.Forms.TextBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.cmbPort = new System.Windows.Forms.ComboBox(); this.label14 = new System.Windows.Forms.Label(); this.tboecheck = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); this.tbbps = new System.Windows.Forms.TextBox(); this.label12 = new System.Windows.Forms.Label(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.btnGetVersion = new System.Windows.Forms.Button(); this.lblVersion = new System.Windows.Forms.Label(); this.label15 = new System.Windows.Forms.Label(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.label16 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); this.dgvSpeed = new System.Windows.Forms.DataGridView(); this.isShow = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.name = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lSpeed = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.zSpeed = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.btnDel = new System.Windows.Forms.DataGridViewButtonColumn(); this.btnadd = new System.Windows.Forms.Button(); this.tbz = new System.Windows.Forms.TextBox(); this.label19 = new System.Windows.Forms.Label(); this.tbxy = new System.Windows.Forms.TextBox(); this.label18 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.label11 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.tbnav = new System.Windows.Forms.TextBox(); this.tbtripy = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.tbtripx = new System.Windows.Forms.TextBox(); this.groupBox3_HDS = new System.Windows.Forms.GroupBox(); this.textBoxIP = new System.Windows.Forms.TextBox(); this.label23 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgvSpeed)).BeginInit(); this.groupBox6.SuspendLayout(); this.groupBox3_HDS.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.btnClose); this.groupBox1.Controls.Add(this.btnSave); this.groupBox1.Location = new System.Drawing.Point(12, 3); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(625, 65); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // btnClose // this.btnClose.Location = new System.Drawing.Point(526, 24); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(75, 23); this.btnClose.TabIndex = 1; this.btnClose.Text = "关闭"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // btnSave // this.btnSave.Location = new System.Drawing.Point(434, 24); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 0; this.btnSave.Text = "确定"; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.label20); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.tbzspeed); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.tbyspeed); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.tbxspeed); this.groupBox2.Location = new System.Drawing.Point(12, 74); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(237, 111); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "步进精度"; // // label20 // this.label20.Location = new System.Drawing.Point(126, 61); this.label20.Name = "label20"; this.label20.Size = new System.Drawing.Size(96, 22); this.label20.TabIndex = 12; this.label20.Text = "单位:微米"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(6, 61); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(17, 12); this.label3.TabIndex = 5; this.label3.Text = "Z:"; // // tbzspeed // this.tbzspeed.Location = new System.Drawing.Point(29, 58); this.tbzspeed.Name = "tbzspeed"; this.tbzspeed.Size = new System.Drawing.Size(75, 21); this.tbzspeed.TabIndex = 4; this.tbzspeed.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(124, 23); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(17, 12); this.label2.TabIndex = 3; this.label2.Text = "Y:"; // // tbyspeed // this.tbyspeed.Location = new System.Drawing.Point(147, 20); this.tbyspeed.Name = "tbyspeed"; this.tbyspeed.Size = new System.Drawing.Size(75, 21); this.tbyspeed.TabIndex = 2; this.tbyspeed.Text = "0.762"; this.tbyspeed.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(6, 23); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(17, 12); this.label1.TabIndex = 1; this.label1.Text = "X:"; // // tbxspeed // this.tbxspeed.Location = new System.Drawing.Point(29, 20); this.tbxspeed.Name = "tbxspeed"; this.tbxspeed.Size = new System.Drawing.Size(75, 21); this.tbxspeed.TabIndex = 0; this.tbxspeed.Text = "0.762"; this.tbxspeed.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // groupBox3 // this.groupBox3.Controls.Add(this.cmbPort); this.groupBox3.Controls.Add(this.label14); this.groupBox3.Controls.Add(this.tboecheck); this.groupBox3.Controls.Add(this.label13); this.groupBox3.Controls.Add(this.tbbps); this.groupBox3.Controls.Add(this.label12); this.groupBox3.Location = new System.Drawing.Point(12, 191); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(625, 76); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "基础设置"; // // cmbPort // this.cmbPort.FormattingEnabled = true; this.cmbPort.Location = new System.Drawing.Point(85, 31); this.cmbPort.Name = "cmbPort"; this.cmbPort.Size = new System.Drawing.Size(81, 20); this.cmbPort.TabIndex = 12; // // label14 // this.label14.Location = new System.Drawing.Point(389, 34); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(103, 20); this.label14.TabIndex = 11; this.label14.Visible = false; // // tboecheck // this.tboecheck.Location = new System.Drawing.Point(498, 31); this.tboecheck.Name = "tboecheck"; this.tboecheck.Size = new System.Drawing.Size(103, 21); this.tboecheck.TabIndex = 10; this.tboecheck.Visible = false; // // label13 // this.label13.Location = new System.Drawing.Point(221, 34); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(62, 18); this.label13.TabIndex = 9; this.label13.Text = "波特率:"; // // tbbps // this.tbbps.Location = new System.Drawing.Point(289, 31); this.tbbps.Name = "tbbps"; this.tbbps.Size = new System.Drawing.Size(75, 21); this.tbbps.TabIndex = 8; this.tbbps.Text = "9600"; this.tbbps.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbbps_KeyPress); // // label12 // this.label12.Location = new System.Drawing.Point(6, 34); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(78, 24); this.label12.TabIndex = 7; this.label12.Text = "设备端口:"; // // groupBox4 // this.groupBox4.Controls.Add(this.btnGetVersion); this.groupBox4.Controls.Add(this.lblVersion); this.groupBox4.Controls.Add(this.label15); this.groupBox4.Location = new System.Drawing.Point(12, 273); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(625, 65); this.groupBox4.TabIndex = 4; this.groupBox4.TabStop = false; this.groupBox4.Text = "型号"; // // btnGetVersion // this.btnGetVersion.Location = new System.Drawing.Point(532, 24); this.btnGetVersion.Name = "btnGetVersion"; this.btnGetVersion.Size = new System.Drawing.Size(75, 23); this.btnGetVersion.TabIndex = 10; this.btnGetVersion.Text = "读取"; this.btnGetVersion.UseVisualStyleBackColor = true; this.btnGetVersion.Click += new System.EventHandler(this.btnGetVersion_Click); // // lblVersion // this.lblVersion.Location = new System.Drawing.Point(136, 28); this.lblVersion.Name = "lblVersion"; this.lblVersion.Size = new System.Drawing.Size(98, 19); this.lblVersion.TabIndex = 9; this.lblVersion.Text = "XXX"; // // label15 // this.label15.Location = new System.Drawing.Point(6, 28); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(133, 19); this.label15.TabIndex = 8; this.label15.Text = "当前载物台型号:"; // // groupBox5 // this.groupBox5.Controls.Add(this.label16); this.groupBox5.Controls.Add(this.label10); this.groupBox5.Controls.Add(this.panel1); this.groupBox5.Controls.Add(this.btnadd); this.groupBox5.Controls.Add(this.tbz); this.groupBox5.Controls.Add(this.label19); this.groupBox5.Controls.Add(this.tbxy); this.groupBox5.Controls.Add(this.label18); this.groupBox5.Controls.Add(this.label17); this.groupBox5.Location = new System.Drawing.Point(12, 344); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(625, 361); this.groupBox5.TabIndex = 5; this.groupBox5.TabStop = false; // // label16 // this.label16.AutoSize = true; this.label16.Location = new System.Drawing.Point(419, 33); this.label16.Name = "label16"; this.label16.Size = new System.Drawing.Size(29, 12); this.label16.TabIndex = 18; this.label16.Text = "um/s"; // // label10 // this.label10.AutoSize = true; this.label10.Location = new System.Drawing.Point(386, 33); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(35, 12); this.label10.TabIndex = 17; this.label10.Text = "Unit:"; // // panel1 // this.panel1.AutoScroll = true; this.panel1.Controls.Add(this.dgvSpeed); this.panel1.Location = new System.Drawing.Point(9, 62); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(610, 294); this.panel1.TabIndex = 16; // // dgvSpeed // this.dgvSpeed.AllowUserToAddRows = false; this.dgvSpeed.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dgvSpeed.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvSpeed.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.isShow, this.name, this.lSpeed, this.zSpeed, this.btnDel}); this.dgvSpeed.Location = new System.Drawing.Point(4, 3); this.dgvSpeed.Name = "dgvSpeed"; this.dgvSpeed.RowHeadersVisible = false; this.dgvSpeed.RowHeadersWidth = 51; this.dgvSpeed.RowTemplate.Height = 27; this.dgvSpeed.Size = new System.Drawing.Size(594, 282); this.dgvSpeed.TabIndex = 0; this.dgvSpeed.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSpeed_CellContentClick); // // isShow // this.isShow.MinimumWidth = 6; this.isShow.Name = "isShow"; this.isShow.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.isShow.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; // // name // this.name.MinimumWidth = 6; this.name.Name = "name"; this.name.ReadOnly = true; // // lSpeed // this.lSpeed.MinimumWidth = 6; this.lSpeed.Name = "lSpeed"; this.lSpeed.ReadOnly = true; // // zSpeed // this.zSpeed.MinimumWidth = 6; this.zSpeed.Name = "zSpeed"; this.zSpeed.ReadOnly = true; // // btnDel // this.btnDel.MinimumWidth = 6; this.btnDel.Name = "btnDel"; this.btnDel.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.btnDel.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; // // btnadd // this.btnadd.Location = new System.Drawing.Point(531, 32); this.btnadd.Name = "btnadd"; this.btnadd.Size = new System.Drawing.Size(75, 23); this.btnadd.TabIndex = 14; this.btnadd.Text = "添加"; this.btnadd.UseVisualStyleBackColor = true; this.btnadd.Click += new System.EventHandler(this.btnadd_Click); // // tbz // this.tbz.Location = new System.Drawing.Point(279, 30); this.tbz.MaxLength = 3; this.tbz.Name = "tbz"; this.tbz.Size = new System.Drawing.Size(80, 21); this.tbz.TabIndex = 13; this.tbz.Text = "100"; this.tbz.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbz_KeyPress); // // label19 // this.label19.Location = new System.Drawing.Point(246, 33); this.label19.Name = "label19"; this.label19.Size = new System.Drawing.Size(36, 19); this.label19.TabIndex = 12; this.label19.Text = "Z轴"; // // tbxy // this.tbxy.Location = new System.Drawing.Point(134, 30); this.tbxy.MaxLength = 3; this.tbxy.Name = "tbxy"; this.tbxy.Size = new System.Drawing.Size(88, 21); this.tbxy.TabIndex = 11; this.tbxy.Text = "100"; this.tbxy.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbxy_KeyPress); // // label18 // this.label18.Location = new System.Drawing.Point(74, 33); this.label18.Name = "label18"; this.label18.Size = new System.Drawing.Size(65, 19); this.label18.TabIndex = 10; this.label18.Text = "载物台"; // // label17 // this.label17.Location = new System.Drawing.Point(6, 33); this.label17.Name = "label17"; this.label17.Size = new System.Drawing.Size(62, 19); this.label17.TabIndex = 9; this.label17.Text = "运行速度:"; // // groupBox6 // this.groupBox6.Controls.Add(this.label11); this.groupBox6.Controls.Add(this.label8); this.groupBox6.Controls.Add(this.label6); this.groupBox6.Controls.Add(this.label9); this.groupBox6.Controls.Add(this.label7); this.groupBox6.Controls.Add(this.tbnav); this.groupBox6.Controls.Add(this.tbtripy); this.groupBox6.Controls.Add(this.label5); this.groupBox6.Controls.Add(this.label4); this.groupBox6.Controls.Add(this.tbtripx); this.groupBox6.Location = new System.Drawing.Point(255, 74); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(382, 111); this.groupBox6.TabIndex = 3; this.groupBox6.TabStop = false; this.groupBox6.Text = "行程"; // // label11 // this.label11.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.label11.Location = new System.Drawing.Point(143, 20); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(2, 81); this.label11.TabIndex = 18; // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(331, 79); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(0, 12); this.label8.TabIndex = 12; this.label8.Visible = false; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(108, 61); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(29, 12); this.label6.TabIndex = 9; this.label6.Text = "微米"; // // label9 // this.label9.Location = new System.Drawing.Point(162, 79); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(86, 22); this.label9.TabIndex = 11; this.label9.Visible = false; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(4, 61); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(17, 12); this.label7.TabIndex = 8; this.label7.Text = "Y:"; // // tbnav // this.tbnav.Location = new System.Drawing.Point(250, 76); this.tbnav.Name = "tbnav"; this.tbnav.Size = new System.Drawing.Size(75, 21); this.tbnav.TabIndex = 10; this.tbnav.Visible = false; this.tbnav.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // tbtripy // this.tbtripy.Location = new System.Drawing.Point(27, 58); this.tbtripy.Name = "tbtripy"; this.tbtripy.Size = new System.Drawing.Size(75, 21); this.tbtripy.TabIndex = 7; this.tbtripy.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(108, 23); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(29, 12); this.label5.TabIndex = 6; this.label5.Text = "微米"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(4, 23); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(17, 12); this.label4.TabIndex = 5; this.label4.Text = "X:"; // // tbtripx // this.tbtripx.Location = new System.Drawing.Point(27, 20); this.tbtripx.Name = "tbtripx"; this.tbtripx.Size = new System.Drawing.Size(75, 21); this.tbtripx.TabIndex = 4; this.tbtripx.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.CheckKeyPress); // // groupBox3_HDS // this.groupBox3_HDS.Controls.Add(this.textBoxIP); this.groupBox3_HDS.Controls.Add(this.label23); this.groupBox3_HDS.Location = new System.Drawing.Point(12, 191); this.groupBox3_HDS.Name = "groupBox3_HDS"; this.groupBox3_HDS.Size = new System.Drawing.Size(625, 76); this.groupBox3_HDS.TabIndex = 13; this.groupBox3_HDS.TabStop = false; this.groupBox3_HDS.Text = "基础设置"; // // textBoxIP // this.textBoxIP.Location = new System.Drawing.Point(76, 31); this.textBoxIP.Name = "textBoxIP"; this.textBoxIP.Size = new System.Drawing.Size(161, 21); this.textBoxIP.TabIndex = 10; this.textBoxIP.Text = "10.0.0.100"; // // label23 // this.label23.Location = new System.Drawing.Point(6, 34); this.label23.Name = "label23"; this.label23.Size = new System.Drawing.Size(78, 24); this.label23.TabIndex = 7; this.label23.Text = "设备IP:"; // // ParamSetingDialog // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.ClientSize = new System.Drawing.Size(653, 711); this.Controls.Add(this.groupBox3_HDS); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ParamSetingDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "位置导航参数设置"; this.Load += new System.EventHandler(this.ParamSetingDialog_Load); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox3_HDS, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); this.panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dgvSpeed)).EndInit(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); this.groupBox3_HDS.ResumeLayout(false); this.groupBox3_HDS.PerformLayout(); this.ResumeLayout(false); } //参数设置点击了确定按钮 private void btnSave_Click(object sender, EventArgs e) { //取得界面中输入的值 string navvalue = this.tbnav.Text.Trim(); string tripxvalue = this.tbtripx.Text.Trim(); string tripyvalue = this.tbtripy.Text.Trim(); string oddevencheckvalue = this.tboecheck.Text.Trim(); string stepxvalue = this.tbxspeed.Text.Trim(); string stepyvalue = this.tbyspeed.Text.Trim(); string stepzvalue = this.tbzspeed.Text.Trim(); if (string.IsNullOrEmpty(stepxvalue) || string.IsNullOrEmpty(stepyvalue) || string.IsNullOrEmpty(stepzvalue)) { MessageBox.Show(PdnResources.GetString("Menu.Stepaccuracyannotbeempty.Text")); return; } if (string.IsNullOrEmpty(tripxvalue) || string.IsNullOrEmpty(tripyvalue)) { MessageBox.Show(PdnResources.GetString("Menu.Theitinerarycannotbeempty.Text")); return; } if (string.IsNullOrEmpty(navvalue)) { MessageBox.Show(PdnResources.GetString("Menu.henavigationwindowcannotbeempty.Text")); return; } if (AxisController.ControllerType.Equals("HDS")) { string addr = this.textBoxIP.Text.Trim(); if (string.IsNullOrEmpty(addr)) { MessageBox.Show(PdnResources.GetString("Menu.Thedeviceportannotbeempty.Text")); return; } //if (string.IsNullOrEmpty(bpsvalue)) //{ // MessageBox.Show(PdnResources.GetString("Menu.Baudrempty.text")); // return; //} //设备值存储 this.loadingStageModel.BaseSetAddr = addr; } else { string bpsvalue = this.tbbps.Text.Trim(); string port = this.cmbPort.Text.Trim(); if (string.IsNullOrEmpty(port)) { MessageBox.Show(PdnResources.GetString("Menu.Thedeviceportannotbeempty.Text")); return; } if (string.IsNullOrEmpty(bpsvalue)) { MessageBox.Show(PdnResources.GetString("Menu.Baudrempty.text")); return; } //设备值存储 this.loadingStageModel.BaseSetPort = port; this.loadingStageModel.BaseSetBps = int.Parse(bpsvalue); } this.loadingStageModel.BaseSetOddEvenCheck = oddevencheckvalue; //基础值存储 this.loadingStageModel.TripX = tripxvalue; this.loadingStageModel.TripY = tripyvalue; this.loadingStageModel.TripNavWin = navvalue; this.loadingStageModel.SteppingX = stepxvalue; this.loadingStageModel.SteppingY = stepyvalue; this.loadingStageModel.SteppingZ = stepzvalue; string stageModelXml = XmlSerializeHelper.XmlSerialize(loadingStageModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\LoadingStage.xml"; if (FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create)) { if (Setted != null) { Setted(loadingStageModel); } //((LocationNavigationDialog)parentForm).ReloadingStageModel(loadingStageModel); MessageBox.Show(PdnResources.GetString("Menu.Thestagsuccessfully.text")); this.Close(); } else { MessageBox.Show(PdnResources.GetString("Menu.Failedtosaveplatforminformation.Text")); } m_axisController.LoadingStageModel = loadingStageModel; } //关闭按钮点击 private void btnClose_Click(object sender, EventArgs e) { this.Close(); } //点击添加按钮 private void btnadd_Click(object sender, EventArgs e) { loadingStageModel.items = lists; string xyvalue = this.tbxy.Text; string zvalue = this.tbz.Text; LoadingStageModel.Item it = new LoadingStageModel.Item(); it.SChecked = 0; it.LSpeed = Int32.Parse(xyvalue); it.ZSpeed = Int32.Parse(zvalue); lists.Add(it); int index = this.dgvSpeed.Rows.Add();//获取新的一行 string lspeed = ("00" + it.LSpeed); lspeed = lspeed.Substring(lspeed.Length - 3); string zspeed = ("00" + it.ZSpeed); zspeed = zspeed.Substring(zspeed.Length - 3); this.dgvSpeed.Rows[index].Cells[1].Value = (index + 1).ToString(); this.dgvSpeed.Rows[index].Cells[2].Value = lspeed; this.dgvSpeed.Rows[index].Cells[3].Value = zspeed; } private void tbxy_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)) { e.Handled = true; return; } } private void tbz_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)) { e.Handled = true; return; } } private void tbbps_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar)) { e.Handled = true; return; } } private void CheckKeyPress(object sender, KeyPressEventArgs e) { TextBox textBox = (TextBox)sender; if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) e.Handled = true; //小数点的处理。 if ((int)e.KeyChar == 46) //小数点 { if (textBox.Text.Length <= 0) e.Handled = true; //小数点不能在第一位 else { float f, oldf; var b1 = float.TryParse(textBox.Text, out oldf); var b2 = float.TryParse(textBox.Text + e.KeyChar.ToString(), out f); if (b2 == false) { if (b1 == true) e.Handled = true; else e.Handled = false; } } } } private void btnGetVersion_Click(object sender, EventArgs e) { try { m_axisController = AxisController.GetInstance(); if (AxisController.ControllerType.Equals("HDS")) { string m_ipName = this.textBoxIP.Text.Trim();//groupBox3 ((StageController.HDS.HDSController)m_axisController).Adrr = m_ipName; m_axisController.Close(); m_axisController.Open(); if (!m_axisController.IsOpen) { lblVersion.Text = ""; MessageBox.Show("连接失败"); } else { new Task(() => { Thread.Sleep(300); this.Invoke(new Action(() => { lblVersion.Text = m_axisController.Version; })); }).Start(); } } else { string m_portName = this.cmbPort.Text.Trim(); int m_baudRate = int.Parse(this.tbbps.Text.Trim()); m_axisController.Open(m_portName, m_baudRate, Parity.None, 8, StopBits.One); new Task(() => { Thread.Sleep(300); this.Invoke(new Action(() => { lblVersion.Text = m_axisController.Version; })); }).Start(); } } catch (Exception ex) { // 串口无法打开时,打开参数设置界面 MessageBox.Show(ex.Message); } } public void OnUpdatePosition() { // throw new NotImplementedException(); } public void OnTimeoutConnect() { MessageBox.Show(PdnResources.GetString("Menu.Theconsoleresponsetimeout.Text")); } public void OnErrorSend() { MessageBox.Show(PdnResources.GetString("Menu.Replydataarsingerror.Text")); } private void ParamSetingDialog_Load(object sender, EventArgs e) { m_axisController = AxisController.GetInstance(); } } }