You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
11 KiB
C#
318 lines
11 KiB
C#
using gts;
|
|
using Rs.Framework;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Flow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO.Ports;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace Rs.MotionPlat.SysConfig
|
|
{
|
|
public partial class LightConfig : BaseForm
|
|
{
|
|
SerialPort sp;
|
|
public LightConfig()
|
|
{
|
|
InitializeComponent();
|
|
sp = new SerialPort();
|
|
sp.BaudRate = 19200;
|
|
sp.DataBits= 8;
|
|
sp.Parity = Parity.None;
|
|
sp.StopBits= StopBits.One;
|
|
sp.PortName = "COM2";
|
|
|
|
sp.DataReceived += Sp_DataReceived;
|
|
}
|
|
|
|
List<byte> reciveData = new List<byte>();
|
|
string reciveMsg = string.Empty;
|
|
private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
|
{
|
|
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")
|
|
{
|
|
reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray());
|
|
reciveData.Clear();
|
|
Invoke(new Action(() => {
|
|
txtRunResult.AppendText(reciveMsg + Environment.NewLine);
|
|
}));
|
|
}
|
|
else if (buf.IndexOf("#") > 0)
|
|
{
|
|
reciveMsg = Encoding.ASCII.GetString(reciveData.ToArray());
|
|
reciveData.Clear();
|
|
Invoke(new Action(() => {
|
|
txtRunResult.AppendText(reciveMsg+Environment.NewLine);
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnOpen_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if(sp!=null &&sp.IsOpen)
|
|
{
|
|
sp.Close();
|
|
}
|
|
sp.Open();
|
|
txtRunResult.AppendText("Open serial success!" + Environment.NewLine);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
txtRunResult.AppendText("Open serial fail!!!" + Environment.NewLine);
|
|
}
|
|
|
|
}
|
|
|
|
private void btnLoadParam_Click(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
if (sp.IsOpen)
|
|
{
|
|
string msg = "$RD=9999#";
|
|
sp.Write(msg);
|
|
reciveMsg = "";
|
|
Dictionary<string, string> kv = new Dictionary<string, string>();
|
|
while (true)
|
|
{
|
|
if (!string.IsNullOrEmpty(reciveMsg))
|
|
{
|
|
reciveMsg = reciveMsg.Replace("$", "").Replace("#", "");
|
|
string[] items = reciveMsg.Split(',');
|
|
foreach (string item in items)
|
|
{
|
|
string[] keyvalue = item.Split('=');
|
|
if (!kv.ContainsKey(keyvalue[0]))
|
|
{
|
|
kv.Add(keyvalue[0], keyvalue[1]);
|
|
}
|
|
}
|
|
|
|
string val = kv[$"TR"];
|
|
Control[] ctls = this.Controls.Find($"rbtnTR{val}", true);
|
|
if(ctls!=null&& ctls.Length>0)
|
|
{
|
|
Invoke(new Action(() => {
|
|
((RadioButton)ctls[0]).Checked = true;
|
|
}));
|
|
}
|
|
|
|
val = kv[$"GR"];
|
|
ctls = this.Controls.Find($"rbtnGR{val}", true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
Invoke(new Action(() => {
|
|
((RadioButton)ctls[0]).Checked = true;
|
|
}));
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
Invoke(new Action(() => {
|
|
val = kv[$"F{i}"];
|
|
ctls = this.Controls.Find($"cboxF{i}", true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
((CheckBox)ctls[0]).Checked = val == "1" ? true : false;
|
|
}
|
|
|
|
val = kv[$"L{i}"];
|
|
ctls = this.Controls.Find($"txtL{i}", true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
((TextBox)ctls[0]).Text = val;
|
|
}
|
|
|
|
val = kv[$"T{i}"];
|
|
ctls = this.Controls.Find($"txtT{i}", true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
((TextBox)ctls[0]).Text = val;
|
|
}
|
|
|
|
val = kv[$"P{i}"];
|
|
ctls = this.Controls.Find($"txtP{i}", true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
((TextBox)ctls[0]).Text = val;
|
|
}
|
|
}));
|
|
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
//sp.Write(datas, 0, datas.Length);
|
|
//byte[] readBuffer = new byte[1024];
|
|
//int totalNum = 0;
|
|
//Stopwatch stopwatch = new Stopwatch();
|
|
//stopwatch.Start();
|
|
//while (true && stopwatch.ElapsedMilliseconds < 3000)
|
|
//{
|
|
// int len = sp.BytesToRead;
|
|
// if (len > 0)
|
|
// {
|
|
// sp.Read(readBuffer, totalNum, len);
|
|
// totalNum += len;
|
|
// string buf = Encoding.ASCII.GetString(readBuffer, 0, totalNum);
|
|
// if (buf.IndexOf("#") > 0)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
//}
|
|
//stopwatch.Stop();
|
|
//if (stopwatch.ElapsedMilliseconds > 3000)
|
|
//{
|
|
// Msg.ShowError("read timeout");
|
|
// return;
|
|
//}
|
|
//Dictionary<string, string> kv = new Dictionary<string, string>();
|
|
//string showInfo = Encoding.ASCII.GetString(readBuffer, 0, totalNum) + Environment.NewLine;
|
|
//Invoke(new Action(() => {
|
|
// txtRunResult.AppendText(showInfo);
|
|
|
|
//}));
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void btnSendParam_Click(object sender, EventArgs e)
|
|
{
|
|
if (sp.IsOpen)
|
|
{
|
|
string msg = "$SA=1#";
|
|
byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
sp.Write(datas, 0, datas.Length);
|
|
|
|
}
|
|
}
|
|
|
|
private void enable_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
string msg = "";
|
|
CheckBox cbox = (CheckBox)sender;
|
|
int val = cbox.Checked ? 1 : 0;
|
|
msg = $"${cbox.Name.Replace("cbox", "")}={val}#";
|
|
if (sp.IsOpen)
|
|
{
|
|
byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
sp.Write(datas, 0, datas.Length);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void txtParam_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
string msg = "";
|
|
TextBox txt = (TextBox)sender;
|
|
msg = $"${txt.Name.Replace("txt", "")}={txt.Text}#";
|
|
if (sp.IsOpen)
|
|
{
|
|
byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
sp.Write(datas, 0, datas.Length);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void triggerMode_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
string msg = "";
|
|
RadioButton rbtn = (RadioButton)sender;
|
|
if(rbtn.Checked)
|
|
{
|
|
msg = $"$TR={rbtn.Name.GetLastChar()}#";
|
|
if (sp.IsOpen)
|
|
{
|
|
byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
sp.Write(datas, 0, datas.Length);
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
private void outLevel_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
string msg = "";
|
|
RadioButton rbtn = (RadioButton)sender;
|
|
if (rbtn.Checked)
|
|
{
|
|
msg = $"$GR={rbtn.Name.GetLastChar()}#";
|
|
if (sp.IsOpen)
|
|
{
|
|
byte[] datas = Encoding.ASCII.GetBytes(msg);
|
|
sp.Write(datas, 0, datas.Length);
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
SlotPoint sp = TrayPointManager.GetSlotPoint(GlobalVar.CurRecipe, "Input", 1, EPointType.BASE);
|
|
SlotPoint dist = TrayPointManager.GetDistToNozzle1(2);
|
|
sp.X += dist.X;
|
|
sp.Y += dist.Y;
|
|
AxisControl.LoadX.MovePos(sp.X, 4);
|
|
AxisControl.LoadY.MovePos(sp.Y, 4);
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (sp != null && sp.IsOpen)
|
|
{
|
|
sp.Close();
|
|
txtRunResult.AppendText("serial closed!" + Environment.NewLine);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
if (sp != null && sp.IsOpen)
|
|
{
|
|
sp.Close();
|
|
txtRunResult.AppendText("serial closed!" + Environment.NewLine);
|
|
}
|
|
base.OnClosed(e);
|
|
}
|
|
}
|
|
}
|