123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065 |
- 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<LoadingStageModel.Item> lists = new List<LoadingStageModel.Item>();
- 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 AxisController m_axisController;
- public ParamSetingDialog(Form form)
- {
- parentForm = form;
- InitializeComponent();
- InitializeLanguageText();
- loadingStageModel = Startup.instance.loadingStageModel;
- lists = loadingStageModel.items;
- 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();
- }
- }
- }
- /// <summary>
- /// 运行速度列表加载
- /// </summary>
- 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.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");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- 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.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.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);
- //
- // ParamSetingDialog
- //
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
- this.ClientSize = new System.Drawing.Size(653, 711);
- 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.Location = new System.Drawing.Point(0, 0);
- 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.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.ResumeLayout(false);
- }
- //参数设置点击了确定按钮
- private void btnSave_Click(object sender, EventArgs e)
- {
- //取得界面中输入的值
- string bpsvalue = this.tbbps.Text.Trim();
- string navvalue = this.tbnav.Text.Trim();
- string tripxvalue = this.tbtripx.Text.Trim();
- string tripyvalue = this.tbtripy.Text.Trim();
- string port = this.cmbPort.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 (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>(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
- {
- string m_portName = this.cmbPort.Text.Trim();
- int m_baudRate = int.Parse(this.tbbps.Text.Trim());
- m_axisController = AxisController.GetInstance();
- 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();
- }
- }
- }
|