diff --git a/LightControl/Form1.Designer.cs b/LightControl/Form1.Designer.cs deleted file mode 100644 index ed0b013..0000000 --- a/LightControl/Form1.Designer.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace LightControl -{ - partial class Form1 - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows 窗体设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要修改 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} - diff --git a/LightControl/Form1.cs b/LightControl/Form1.cs deleted file mode 100644 index 5bdc214..0000000 --- a/LightControl/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace LightControl -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/LightControl/LightConfig.cs b/LightControl/LightConfig.cs index 75b31dd..56f8de9 100644 --- a/LightControl/LightConfig.cs +++ b/LightControl/LightConfig.cs @@ -22,11 +22,11 @@ namespace Rs.MotionPlat.SysConfig InitializeComponent(); sp = new SerialPort(); sp.BaudRate = 19200; - sp.DataBits= 8; + sp.DataBits = 8; sp.Parity = Parity.None; - sp.StopBits= StopBits.One; + sp.StopBits = StopBits.One; sp.PortName = "COM2"; - + sp.DataReceived += Sp_DataReceived; } @@ -34,28 +34,33 @@ namespace Rs.MotionPlat.SysConfig string reciveMsg = string.Empty; private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { - byte[] readBuffer=new byte[1024]; + byte[] readBuffer = new byte[1024]; int len = sp.BytesToRead; if (len > 0) { sp.Read(readBuffer, 0, len); reciveData.AddRange(readBuffer.Take(len)); string buf = Encoding.ASCII.GetString(readBuffer, 0, len); - if(buf=="+OK") + LogHelper.Debug(" >>> " + buf); + if (buf == "+OK") { reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray()); - reciveData.Clear(); + Invoke(new Action(() => { - txtRunResult.AppendText(reciveMsg + Environment.NewLine); + txtRunResult.AppendText(Encoding.ASCII.GetString(reciveData.ToArray()) + Environment.NewLine); })); + LogHelper.Debug(Encoding.ASCII.GetString(reciveData.ToArray())); + reciveData.Clear(); } else if (buf.IndexOf("#") > 0) { reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray()); - reciveData.Clear(); + Invoke(new Action(() => { - txtRunResult.AppendText(reciveMsg+Environment.NewLine); + txtRunResult.AppendText(Encoding.ASCII.GetString(reciveData.ToArray()) + Environment.NewLine); })); + LogHelper.Debug(Encoding.ASCII.GetString(reciveData.ToArray())); + reciveData.Clear(); } } } @@ -64,7 +69,7 @@ namespace Rs.MotionPlat.SysConfig { try { - if(sp!=null &&sp.IsOpen) + if (sp != null && sp.IsOpen) { sp.Close(); } @@ -75,7 +80,7 @@ namespace Rs.MotionPlat.SysConfig { txtRunResult.AppendText("Open serial fail!!!" + Environment.NewLine); } - + } private void btnLoadParam_Click(object sender, EventArgs e) @@ -85,6 +90,7 @@ namespace Rs.MotionPlat.SysConfig { string msg = "$RD=9999#"; sp.Write(msg); + LogHelper.Debug(" <<< " + msg); reciveMsg = ""; Dictionary kv = new Dictionary(); while (true) @@ -104,7 +110,7 @@ namespace Rs.MotionPlat.SysConfig string val = kv[$"TR"]; Control[] ctls = this.Controls.Find($"rbtnTR{val}", true); - if(ctls!=null&& ctls.Length>0) + if (ctls != null && ctls.Length > 0) { Invoke(new Action(() => { ((RadioButton)ctls[0]).Checked = true; @@ -151,14 +157,14 @@ namespace Rs.MotionPlat.SysConfig ((TextBox)ctls[0]).Text = val; } })); - + } break; } } } }); - + } private void btnSendParam_Click(object sender, EventArgs e) @@ -168,7 +174,7 @@ namespace Rs.MotionPlat.SysConfig string msg = "$SA=1#"; byte[] datas = Encoding.ASCII.GetBytes(msg); sp.Write(datas, 0, datas.Length); - + LogHelper.Debug(" <<< " + msg); } } @@ -197,6 +203,7 @@ namespace Rs.MotionPlat.SysConfig { byte[] datas = Encoding.ASCII.GetBytes(msg); sp.Write(datas, 0, datas.Length); + LogHelper.Debug(" <<< " + msg); } }); } @@ -206,7 +213,7 @@ namespace Rs.MotionPlat.SysConfig Task.Run(() => { string msg = ""; RadioButton rbtn = (RadioButton)sender; - if(rbtn.Checked) + if (rbtn.Checked) { msg = $"$TR={rbtn.Name.GetLastChar()}#"; if (sp.IsOpen) @@ -215,7 +222,7 @@ namespace Rs.MotionPlat.SysConfig sp.Write(datas, 0, datas.Length); } } - + }); } @@ -250,7 +257,7 @@ namespace Rs.MotionPlat.SysConfig } catch (Exception) { - + } } @@ -267,7 +274,7 @@ namespace Rs.MotionPlat.SysConfig private void LightConfig_Load(object sender, EventArgs e) { string[] ionames = System.IO.Ports.SerialPort.GetPortNames(); - if(ionames!=null && ionames.Length>0) + if (ionames != null && ionames.Length > 0) { foreach (var item in ionames) { @@ -279,7 +286,7 @@ namespace Rs.MotionPlat.SysConfig private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { - if(sp!=null && sp.IsOpen) + if (sp != null && sp.IsOpen) { sp.Close(); } @@ -288,7 +295,7 @@ namespace Rs.MotionPlat.SysConfig private void btnClose_Click_1(object sender, EventArgs e) { - if(sp != null && sp.IsOpen) + if (sp != null && sp.IsOpen) { sp.Close(); } diff --git a/LightControl/LightControl.csproj b/LightControl/LightControl.csproj index 992dcf6..e577732 100644 --- a/LightControl/LightControl.csproj +++ b/LightControl/LightControl.csproj @@ -50,12 +50,6 @@ - - Form - - - Form1.cs - Form