优化光源控制器控制软件

develop
lhiven 6 months ago
parent b339b29b67
commit 3219f81d38

@ -1,40 +0,0 @@
namespace LightControl
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
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
}
}

@ -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();
}
}
}

@ -22,11 +22,11 @@ namespace Rs.MotionPlat.SysConfig
InitializeComponent(); InitializeComponent();
sp = new SerialPort(); sp = new SerialPort();
sp.BaudRate = 19200; sp.BaudRate = 19200;
sp.DataBits= 8; sp.DataBits = 8;
sp.Parity = Parity.None; sp.Parity = Parity.None;
sp.StopBits= StopBits.One; sp.StopBits = StopBits.One;
sp.PortName = "COM2"; sp.PortName = "COM2";
sp.DataReceived += Sp_DataReceived; sp.DataReceived += Sp_DataReceived;
} }
@ -34,28 +34,33 @@ namespace Rs.MotionPlat.SysConfig
string reciveMsg = string.Empty; string reciveMsg = string.Empty;
private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e) private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{ {
byte[] readBuffer=new byte[1024]; byte[] readBuffer = new byte[1024];
int len = sp.BytesToRead; int len = sp.BytesToRead;
if (len > 0) if (len > 0)
{ {
sp.Read(readBuffer, 0, len); sp.Read(readBuffer, 0, len);
reciveData.AddRange(readBuffer.Take(len)); reciveData.AddRange(readBuffer.Take(len));
string buf = Encoding.ASCII.GetString(readBuffer, 0, len); string buf = Encoding.ASCII.GetString(readBuffer, 0, len);
if(buf=="+OK") LogHelper.Debug(" >>> " + buf);
if (buf == "+OK")
{ {
reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray()); reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray());
reciveData.Clear();
Invoke(new Action(() => { 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) else if (buf.IndexOf("#") > 0)
{ {
reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray()); reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray());
reciveData.Clear();
Invoke(new Action(() => { 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 try
{ {
if(sp!=null &&sp.IsOpen) if (sp != null && sp.IsOpen)
{ {
sp.Close(); sp.Close();
} }
@ -75,7 +80,7 @@ namespace Rs.MotionPlat.SysConfig
{ {
txtRunResult.AppendText("Open serial fail!!!" + Environment.NewLine); txtRunResult.AppendText("Open serial fail!!!" + Environment.NewLine);
} }
} }
private void btnLoadParam_Click(object sender, EventArgs e) private void btnLoadParam_Click(object sender, EventArgs e)
@ -85,6 +90,7 @@ namespace Rs.MotionPlat.SysConfig
{ {
string msg = "$RD=9999#"; string msg = "$RD=9999#";
sp.Write(msg); sp.Write(msg);
LogHelper.Debug(" <<< " + msg);
reciveMsg = ""; reciveMsg = "";
Dictionary<string, string> kv = new Dictionary<string, string>(); Dictionary<string, string> kv = new Dictionary<string, string>();
while (true) while (true)
@ -104,7 +110,7 @@ namespace Rs.MotionPlat.SysConfig
string val = kv[$"TR"]; string val = kv[$"TR"];
Control[] ctls = this.Controls.Find($"rbtnTR{val}", true); Control[] ctls = this.Controls.Find($"rbtnTR{val}", true);
if(ctls!=null&& ctls.Length>0) if (ctls != null && ctls.Length > 0)
{ {
Invoke(new Action(() => { Invoke(new Action(() => {
((RadioButton)ctls[0]).Checked = true; ((RadioButton)ctls[0]).Checked = true;
@ -151,14 +157,14 @@ namespace Rs.MotionPlat.SysConfig
((TextBox)ctls[0]).Text = val; ((TextBox)ctls[0]).Text = val;
} }
})); }));
} }
break; break;
} }
} }
} }
}); });
} }
private void btnSendParam_Click(object sender, EventArgs e) private void btnSendParam_Click(object sender, EventArgs e)
@ -168,7 +174,7 @@ namespace Rs.MotionPlat.SysConfig
string msg = "$SA=1#"; string msg = "$SA=1#";
byte[] datas = Encoding.ASCII.GetBytes(msg); byte[] datas = Encoding.ASCII.GetBytes(msg);
sp.Write(datas, 0, datas.Length); sp.Write(datas, 0, datas.Length);
LogHelper.Debug(" <<< " + msg);
} }
} }
@ -197,6 +203,7 @@ namespace Rs.MotionPlat.SysConfig
{ {
byte[] datas = Encoding.ASCII.GetBytes(msg); byte[] datas = Encoding.ASCII.GetBytes(msg);
sp.Write(datas, 0, datas.Length); sp.Write(datas, 0, datas.Length);
LogHelper.Debug(" <<< " + msg);
} }
}); });
} }
@ -206,7 +213,7 @@ namespace Rs.MotionPlat.SysConfig
Task.Run(() => { Task.Run(() => {
string msg = ""; string msg = "";
RadioButton rbtn = (RadioButton)sender; RadioButton rbtn = (RadioButton)sender;
if(rbtn.Checked) if (rbtn.Checked)
{ {
msg = $"$TR={rbtn.Name.GetLastChar()}#"; msg = $"$TR={rbtn.Name.GetLastChar()}#";
if (sp.IsOpen) if (sp.IsOpen)
@ -215,7 +222,7 @@ namespace Rs.MotionPlat.SysConfig
sp.Write(datas, 0, datas.Length); sp.Write(datas, 0, datas.Length);
} }
} }
}); });
} }
@ -250,7 +257,7 @@ namespace Rs.MotionPlat.SysConfig
} }
catch (Exception) catch (Exception)
{ {
} }
} }
@ -267,7 +274,7 @@ namespace Rs.MotionPlat.SysConfig
private void LightConfig_Load(object sender, EventArgs e) private void LightConfig_Load(object sender, EventArgs e)
{ {
string[] ionames = System.IO.Ports.SerialPort.GetPortNames(); string[] ionames = System.IO.Ports.SerialPort.GetPortNames();
if(ionames!=null && ionames.Length>0) if (ionames != null && ionames.Length > 0)
{ {
foreach (var item in ionames) foreach (var item in ionames)
{ {
@ -279,7 +286,7 @@ namespace Rs.MotionPlat.SysConfig
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ {
if(sp!=null && sp.IsOpen) if (sp != null && sp.IsOpen)
{ {
sp.Close(); sp.Close();
} }
@ -288,7 +295,7 @@ namespace Rs.MotionPlat.SysConfig
private void btnClose_Click_1(object sender, EventArgs e) private void btnClose_Click_1(object sender, EventArgs e)
{ {
if(sp != null && sp.IsOpen) if (sp != null && sp.IsOpen)
{ {
sp.Close(); sp.Close();
} }

@ -50,12 +50,6 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="LightConfig.cs"> <Compile Include="LightConfig.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

Loading…
Cancel
Save