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.

130 lines
4.4 KiB
C#

using Estsh.Client.Base;
using System.Net.NetworkInformation;
namespace Estsh.Client.StepLibrary
{
public partial class SendRobotInfo : StepBase
{
private StepLibraryAPP app = null;
public SendRobotInfo()
{
InitializeComponent();
// 有用户界面的工步在初始化时需要设置为不可见
// 开始执行此工步后再置为可见
this.Visible = false;
}
public override bool Do()
{
try
{
ShowMessage(this, "green|发送搬运轨迹信息!");
// 置为可见并加载到最前端
this.Visible = true;
this.BringToFront();
string _sn = Context["serial_number"].ToString();
app = new StepLibraryAPP(httpClient);
List<dynamic> dtList = app.GetSendRobotList();
dgvList.AutoGenerateColumns = false;
dgvList.DataSource = dtList;
string lastSN = string.Empty;
if (dtList.Count > 0)
{
lastSN = dtList[0]["serial_number"].ToString();
}
List<dynamic> snInfo = app.GetSNInfo(_sn);
string partLocation = snInfo[0]["part_location"].ToString();
string locationSpec = snInfo[0]["enum_desc"].ToString();
string custPartNo = snInfo[0]["cust_part_no"].ToString();
txtJM.Text = custPartNo;
txtLoc.Text = locationSpec;
if (lastSN != _sn || string.IsNullOrEmpty(lastSN))
{
if (IsActive())
{
while (true)
{
if (app.robotIsReady())
{
bool updateResult = app.UpdateOPCPointRobot(partLocation + custPartNo, "robotWrite");
if (updateResult)
{
lblMsg.Text = "机器人轨迹信息已发送成功!";
lblMsg.ForeColor = Color.Green;
app.insertSendRobot(_sn, partLocation + custPartNo, locationSpec);
break;
}
else
{
lblMsg.Text = "机器人轨迹信息发送失败!";
lblMsg.ForeColor = Color.Red;
}
}
else
{
ShowMessage(this, "red|机器人准备未完成,请稍等!");
lblMsg.Text = "机器人准备未完成,请稍等!";
lblMsg.ForeColor = Color.Red;
}
Application.DoEvents();
Thread.Sleep(1500);
}
}
else
{
lblMsg.Text = "机器人网络异常!";
lblMsg.ForeColor = Color.Red;
}
}
// 工步执行完成后调用此方法
Complate(this, new EventArgs());
// 执行父类的 Do 方法并返回
return base.Do();
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "] ", ex.ToString()));
sw.Flush();
sw.Close();
}
return false;
}
}
private bool IsActive()
{
Ping ping = new Ping();
PingReply reply = ping.Send("172.16.10.133");
//PingReply reply = ping.Send("127.0.0.1");
return reply.Status == IPStatus.Success;
}
private void dgvList_SelectionChanged(object sender, EventArgs e)
{
dgvList.ClearSelection();
}
}
}