|
|
|
@ -22,9 +22,9 @@ 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();
|
|
|
|
|
}
|
|
|
|
@ -85,6 +90,7 @@ namespace Rs.MotionPlat.SysConfig
|
|
|
|
|
{
|
|
|
|
|
string msg = "$RD=9999#";
|
|
|
|
|
sp.Write(msg);
|
|
|
|
|
LogHelper.Debug(" <<< " + msg);
|
|
|
|
|
reciveMsg = "";
|
|
|
|
|
Dictionary<string, string> kv = new Dictionary<string, string>();
|
|
|
|
|
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;
|
|
|
|
@ -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)
|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|