using iWareCC.BLL;
|
using iWareCC.SrmService;
|
using iWareCommon;
|
using iWareCommon.Utils;
|
using iWareModel;
|
using iWareSql;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Net;
|
using System.Net.NetworkInformation;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace iWareCC.Forms
|
{
|
public partial class SystemCheckForm : Form
|
{
|
private string strOK = "成功!";
|
private string strFail = "失败!";
|
Boolean DeviceStats = false;
|
public SystemCheckForm()
|
{
|
InitializeComponent();
|
|
this.BtnDection.Enabled = false;
|
this.btn_Skip.Enabled = false;
|
}
|
|
/// <summary>
|
/// 显示登陆窗体.(公共静态方法)
|
/// </summary>
|
public static bool Frm_SystemCheckResult()
|
{
|
SystemCheckForm LoadDetectionFM = new SystemCheckForm();
|
LoadDetectionFM.StartPosition = FormStartPosition.CenterScreen;
|
DialogResult result = LoadDetectionFM.ShowDialog();
|
return (result == DialogResult.OK);
|
}
|
|
private void Bgw1_DoWork(object sender, DoWorkEventArgs e)
|
{
|
StartDection();
|
}
|
|
private void StartDection()
|
{
|
this.BtnDection.Enabled = false;
|
this.btn_Skip.Enabled = false;
|
|
Boolean result1, result2, result3, result4, result5, result6, result7;
|
result1 = result2 = result3 = result4 = result5 = result6 = result7 = false;
|
|
int checkAllCount = 7;
|
int checkIndex = 0;
|
|
var tipsMsg = "";
|
//1、通讯检测
|
tipsMsg = "正在检测 WCS通讯...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(10, tipsMsg);
|
result1 = this.DeviceDection(txt_WCS, txt_WCS, "WCS通讯检测", "");
|
Thread.Sleep(500);
|
|
//2、MES接口反馈
|
tipsMsg = "正在检测 MES服务...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(20, tipsMsg);
|
result2 = this.MesDection();
|
Thread.Sleep(500);
|
|
//3、堆垛机反馈
|
tipsMsg = "正在检测 1号堆垛机连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(30, tipsMsg);
|
result3 = this.SrmDection(EDevice.一号堆垛机, "1号堆垛机");
|
Thread.Sleep(500);
|
|
tipsMsg = "正在检测 2号堆垛机连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(40, tipsMsg);
|
result4 = this.SrmDection(EDevice.二号堆垛机, "2号堆垛机");
|
Thread.Sleep(500);
|
|
//4、RGV和输送线反馈
|
|
|
tipsMsg = "正在检测 RGV连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(60, tipsMsg);
|
result6 = this.RgvDection();
|
Thread.Sleep(500);
|
|
tipsMsg = "正在检测 输送线连接...(" + (++checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
this.Bgw1.ReportProgress(70, tipsMsg);
|
//result7 = this.ConveyorDection();
|
Thread.Sleep(500);
|
|
tipsMsg = "检测完成...(" + (checkIndex) + "/" + checkAllCount + ")";
|
SetLablelMsg(tipsMsg);
|
DeviceStats = result1 && result2 && result3 && result4 && result5 && result6 && result7;
|
this.Bgw1.ReportProgress(100, "检测完成...(" + checkIndex + "/" + checkAllCount + ")");
|
|
Thread.Sleep(2000);
|
|
this.BtnDection.Enabled = true;
|
this.btn_Skip.Enabled = true;
|
|
}
|
|
#region MES检测
|
|
private bool MesDection()
|
{
|
try
|
{
|
////根据MatId取MES那里获取Mat对象,,这里还没写
|
//MesMatInfo matInfo = new MesMatInfo()
|
//{
|
// MatID = "DBCWMJS18_B2",
|
// MatName = ""
|
//};
|
//string resData = new MesWebService.MesWebServiceSoapClient().GetMesMatInfo(JsonConvert.SerializeObject(matInfo));
|
//ResEntity re = JsonConvert.DeserializeObject<ResEntity>(resData);
|
//if (re.resCode == "1")
|
//{
|
// txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.Salmon; }));
|
// txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测失败!" + re.resMsg; }));
|
// return false;
|
//}
|
|
//txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.LimeGreen; }));
|
//txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测成功!"; }));
|
return true;
|
}
|
catch (Exception ex)
|
{
|
txtMESDec.Invoke(new Action(() => { txtMESDec.BackColor = Color.Salmon; }));
|
txtMESDec.Invoke(new Action(() => { txtMESDec.Text = "MES服务检测失败!出现异常:" + ex.Message; }));
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region 堆垛机检测
|
|
/// <summary>
|
/// 堆垛机检测
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
private bool SrmDection(EDevice deviceId, string msg)
|
{
|
TextBox tb = null;
|
switch (deviceId)
|
{
|
case EDevice.一号堆垛机:
|
tb = txt_Srm1;
|
break;
|
case EDevice.二号堆垛机:
|
tb = txt_Srm2;
|
break;
|
}
|
try
|
{
|
var result = false;
|
string errMsg = "";
|
int int_deviceId = (int)deviceId;
|
using (var srmService = new SrmService.SrmServiceClient())
|
{
|
|
var isHandShare = SrmBLL.IsHandShare(srmService, deviceId);
|
if (!isHandShare)
|
{
|
errMsg = deviceId.ToString() + "没有心跳";
|
tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
|
tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + errMsg; }));
|
return false;
|
}
|
|
SdaResEntity sdaResult = srmService.IsReady(int_deviceId, out errMsg);
|
if (sdaResult.result == false)
|
{
|
Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_BZ39_IssueInboundTask, "验证堆垛机是否可以接受任务出现错误,int_deviceId:" + int_deviceId + ",sdaResultStr:" + JsonConvert.SerializeObject(sdaResult));
|
result = false;
|
}
|
else
|
{
|
result = true;
|
}
|
|
if (result)
|
{
|
tb.Invoke(new Action(() => { tb.BackColor = Color.LimeGreen; }));
|
tb.Invoke(new Action(() => { tb.Text = msg + "检测成功!"; }));
|
}
|
else
|
{
|
if (sdaResult.resMsg == ESrmAlarm.无报警.ToString())
|
{
|
tb.Invoke(new Action(() => { tb.BackColor = Color.LimeGreen; }));
|
tb.Invoke(new Action(() => { tb.Text = msg + "检测成功!"; }));
|
return true;
|
}
|
tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
|
tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + sdaResult.resMsg; }));
|
return false;
|
}
|
|
return true;
|
}
|
}
|
catch (Exception ex)
|
{
|
tb.Invoke(new Action(() => { tb.BackColor = Color.Salmon; }));
|
tb.Invoke(new Action(() => { tb.Text = msg + "检测失败!" + ex.Message; }));
|
return false;
|
}
|
}
|
|
#endregion
|
|
#region 桁架、RGV、输送线
|
|
|
/// <summary>
|
/// RGV检测
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
private bool RgvDection()
|
{
|
var msg = "RGV";
|
try
|
{
|
string errMsg = "";
|
using (var rgvService = new RgvService.RgvServiceClient())
|
{
|
//检测是否有心跳
|
var isRgvHandShare = RgvBLL.IsRgvHandShare(rgvService);
|
if (!isRgvHandShare)
|
{
|
text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
|
text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!RGV没有心跳"; }));
|
return false;
|
}
|
|
|
iWareCC.RgvService.SdaResEntity sdaResult = rgvService.IsRgvAuto((int)EDevice.RGV, Convert.ToInt32(EDevice.RGV).ToString());
|
if (sdaResult.result == false)
|
{
|
Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.DataProcess_RobotBuffer_ModeChange, "验证RGV是否可以接受任务出现错误,int_deviceId:" + (int)EDevice.RGV + ",sdaResultStr:" + JsonConvert.SerializeObject(sdaResult));
|
text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
|
text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!" + sdaResult.resMsg; }));
|
return false;
|
}
|
else
|
{
|
text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.LimeGreen; }));
|
text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测成功!"; }));
|
return true;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
text_RGV.Invoke(new Action(() => { text_RGV.BackColor = Color.Salmon; }));
|
text_RGV.Invoke(new Action(() => { text_RGV.Text = msg + "检测失败!" + ex.Message; }));
|
return false;
|
}
|
}
|
|
|
#endregion
|
|
#region 通讯测试
|
private bool DeviceDection(TextBox txt1, TextBox txt2, string strMsg1, string strMsg2)
|
{
|
try
|
{
|
string _sip = "192.168.1.29";
|
Ping ping = new Ping();
|
|
PingReply pingReply = ping.Send(IPAddress.Parse(_sip));
|
if (pingReply.Status == IPStatus.Success)
|
{
|
|
txt1.Invoke(new Action(() => { txt1.BackColor = Color.LimeGreen; }));
|
txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strOK; }));
|
if (txt2.Name != txt1.Name)
|
{
|
txt2.Invoke(new Action(() => { txt2.BackColor = Color.LimeGreen; }));
|
txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strOK; }));
|
}
|
return true;
|
}
|
else
|
{
|
//SysLog.saveLog(strMsg1 + strFail);
|
txt1.Invoke(new Action(() => { txt1.BackColor = Color.Salmon; }));
|
txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strFail; }));
|
|
if (txt2.Name != txt1.Name)
|
{
|
//SysLog.saveLog(strMsg2 + strFail);
|
txt2.Invoke(new Action(() => { txt2.BackColor = Color.Salmon; }));
|
txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strFail; }));
|
}
|
return false;
|
}
|
}
|
catch (Exception ex)
|
{
|
//SysLog.saveLog(strMsg1 + strFail + ex);
|
txt1.Invoke(new Action(() => { txt1.BackColor = Color.Salmon; }));
|
txt1.Invoke(new Action(() => { txt1.Text = strMsg1 + strFail; }));
|
|
if (txt2.Name != txt1.Name)
|
{
|
//SysLog.saveLog(strMsg2 + strFail + ex);
|
txt2.Invoke(new Action(() => { txt2.BackColor = Color.Salmon; }));
|
txt2.Invoke(new Action(() => { txt2.Text = strMsg2 + strFail; }));
|
}
|
return false;
|
}
|
}
|
#endregion
|
|
#region 消息赋值
|
private void SetLablelMsg(string strMsg)
|
{
|
lbl_Msg.Invoke(new Action(() => { lbl_Msg.Text = strMsg; }));
|
}
|
#endregion
|
|
private void Bgw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
{
|
if (e == null)
|
{
|
this.DialogResult = DialogResult.OK;
|
return;
|
}
|
if (e.Error != null)
|
{
|
MessageBox.Show(e.Error.Message);
|
}
|
else if (e.Cancelled)
|
{
|
MessageBox.Show("任务取消。");
|
}
|
else if (!DeviceStats)
|
{
|
//WZ.Useful.Commons.MessageUtil.ShowError("通讯设备检测失败!");
|
}
|
else
|
{
|
//MessageBox.Show("检测完成!");
|
this.DialogResult = DialogResult.OK;
|
}
|
}
|
|
private void Bgw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
{
|
this.pgbDec.Value = e.ProgressPercentage;
|
}
|
|
private void SystemCheckForm_Load(object sender, EventArgs e)
|
{
|
this.Bgw1.RunWorkerAsync(); // 运行 backgroundWorker 组件
|
}
|
|
private void BtnDection_Click(object sender, EventArgs e)
|
{
|
this.pgbDec.Value = 0;
|
TxtClear();
|
this.Bgw1.RunWorkerAsync(); // 运行 backgroundWorker 组件
|
}
|
|
private void TxtClear()
|
{
|
|
TextBox[] txts = new TextBox[] { txt_WCS, txtMESDec, txt_Srm1, txt_Srm2, txt_Truss, txt_Conveyor, text_RGV };
|
|
foreach (TextBox txt in txts)
|
{
|
string strTxt = txt.Text.ToString().Trim();
|
txt.BackColor = Color.WhiteSmoke;
|
txt.Text = strTxt.Contains(strOK) ? strTxt.Substring(0, strTxt.Length - 3) : strTxt;
|
txt.Text = strTxt.Contains(strFail) ? strTxt.Substring(0, strTxt.Length - 3) : strTxt;
|
}
|
}
|
|
private void btn_Skip_Click(object sender, EventArgs e)
|
{
|
this.DeviceStats = true;
|
Bgw1_RunWorkerCompleted(null, null);
|
}
|
}
|
}
|