From 63330540fb5c7894a57ca0bb599d16ba433859ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E9=93=AD=20=E5=90=95?= <896951544@qq.com> Date: Fri, 16 May 2025 13:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9AGV=E4=BF=A1=E5=8F=B7?= =?UTF-8?q?=E7=9A=84PLC=E5=8D=8F=E8=AE=AE=EF=BC=8C=E5=B0=863=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E6=97=A0=E6=84=8F=E4=B9=89=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=8D=95=E6=98=BE=E7=A4=BA=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E3=80=82=E4=BF=AE=E6=94=B9=E7=94=B1=E4=BA=8E=E6=8E=89?= =?UTF-8?q?=E7=BA=BF=E5=AF=BC=E8=87=B4AGV=E5=AF=B9=E6=8E=A5=E7=AB=99?= =?UTF-8?q?=E5=8F=B0=E4=BF=A1=E6=81=AF=E7=9A=84=E7=8A=B6=E6=80=81=E4=B8=8D?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ControlMonitorClient/FrmDeviceStatus.cs | 7 +- WcfControlMonitorHost/FrmHost.Designer.cs | 31 ++-- WcfControlMonitorHost/FrmHost.cs | 55 ++++--- WcfControlMonitorLib/SControlMonitor.cs | 17 ++- webapi/WindowsFormsApp1/APIChannel.cs | 166 +++++++++++----------- 5 files changed, 153 insertions(+), 123 deletions(-) diff --git a/ControlMonitorClient/FrmDeviceStatus.cs b/ControlMonitorClient/FrmDeviceStatus.cs index 7ff2d9c..34fc5a9 100644 --- a/ControlMonitorClient/FrmDeviceStatus.cs +++ b/ControlMonitorClient/FrmDeviceStatus.cs @@ -321,16 +321,19 @@ namespace wcfControlMonitorClient case 0: lblDeviceStatus.Text = "��"; break; + case 3: + lblDeviceStatus.Text = "����"; + break; case 1: lblDeviceStatus.Text = "ȡ����(ȡ������)"; break; case 2: lblDeviceStatus.Text = "ȡ�����"; break; - case 3: + case 4: lblDeviceStatus.Text = "�Ż���(�Ż�����)"; break; - case 4: + case 5: lblDeviceStatus.Text = "�Ż����"; break; case 9: diff --git a/WcfControlMonitorHost/FrmHost.Designer.cs b/WcfControlMonitorHost/FrmHost.Designer.cs index 5dd99fc..1395052 100644 --- a/WcfControlMonitorHost/FrmHost.Designer.cs +++ b/WcfControlMonitorHost/FrmHost.Designer.cs @@ -94,7 +94,7 @@ this.listBox1.HorizontalScrollbar = true; this.listBox1.ItemHeight = 15; this.listBox1.Location = new System.Drawing.Point(16, 56); - this.listBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.listBox1.Margin = new System.Windows.Forms.Padding(4); this.listBox1.Name = "listBox1"; this.listBox1.ScrollAlwaysVisible = true; this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; @@ -196,7 +196,7 @@ this.tsStatus.Font = new System.Drawing.Font("黑体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.tsStatus.ForeColor = System.Drawing.Color.Red; this.tsStatus.Location = new System.Drawing.Point(13, 615); - this.tsStatus.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tsStatus.Margin = new System.Windows.Forms.Padding(4); this.tsStatus.Multiline = true; this.tsStatus.Name = "tsStatus"; this.tsStatus.ReadOnly = true; @@ -209,7 +209,7 @@ this.button1.Image = global::wcfControlMonitorClient.Properties.Resources.call_modul_volume_reduce; this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button1.Location = new System.Drawing.Point(727, 569); - this.button1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button1.Margin = new System.Windows.Forms.Padding(4); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(116, 42); this.button1.TabIndex = 1565; @@ -225,7 +225,7 @@ this.listBox2.FormattingEnabled = true; this.listBox2.ItemHeight = 15; this.listBox2.Location = new System.Drawing.Point(884, 56); - this.listBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.listBox2.Margin = new System.Windows.Forms.Padding(4); this.listBox2.Name = "listBox2"; this.listBox2.Size = new System.Drawing.Size(469, 499); this.listBox2.TabIndex = 1567; @@ -258,7 +258,7 @@ this.button4.Image = global::wcfControlMonitorClient.Properties.Resources.MSN; this.button4.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button4.Location = new System.Drawing.Point(1127, 569); - this.button4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button4.Margin = new System.Windows.Forms.Padding(4); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(209, 42); this.button4.TabIndex = 1569; @@ -407,7 +407,7 @@ this.button3.Image = global::wcfControlMonitorClient.Properties.Resources.SCDCNCLL; this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button3.Location = new System.Drawing.Point(892, 569); - this.button3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button3.Margin = new System.Windows.Forms.Padding(4); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(157, 42); this.button3.TabIndex = 1569; @@ -419,14 +419,14 @@ // timer1 // this.timer1.Enabled = true; - this.timer1.Interval = 10000; + this.timer1.Interval = 5000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // pbF1S7 // this.pbF1S7.Image = global::wcfControlMonitorClient.Properties.Resources.linkerror; this.pbF1S7.Location = new System.Drawing.Point(407, 32); - this.pbF1S7.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pbF1S7.Margin = new System.Windows.Forms.Padding(4); this.pbF1S7.Name = "pbF1S7"; this.pbF1S7.Size = new System.Drawing.Size(29, 21); this.pbF1S7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; @@ -448,7 +448,7 @@ // this.btcelltest.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btcelltest.Location = new System.Drawing.Point(580, 576); - this.btcelltest.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btcelltest.Margin = new System.Windows.Forms.Padding(4); this.btcelltest.Name = "btcelltest"; this.btcelltest.Size = new System.Drawing.Size(123, 36); this.btcelltest.TabIndex = 2668; @@ -461,7 +461,7 @@ // this.btStopOut.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btStopOut.Location = new System.Drawing.Point(296, 576); - this.btStopOut.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btStopOut.Margin = new System.Windows.Forms.Padding(4); this.btStopOut.Name = "btStopOut"; this.btStopOut.Size = new System.Drawing.Size(123, 36); this.btStopOut.TabIndex = 2667; @@ -474,7 +474,7 @@ // this.btStopIn.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btStopIn.Location = new System.Drawing.Point(427, 576); - this.btStopIn.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btStopIn.Margin = new System.Windows.Forms.Padding(4); this.btStopIn.Name = "btStopIn"; this.btStopIn.Size = new System.Drawing.Size(123, 36); this.btStopIn.TabIndex = 2666; @@ -487,7 +487,7 @@ // this.btStopTest.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btStopTest.Location = new System.Drawing.Point(165, 576); - this.btStopTest.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btStopTest.Margin = new System.Windows.Forms.Padding(4); this.btStopTest.Name = "btStopTest"; this.btStopTest.Size = new System.Drawing.Size(123, 36); this.btStopTest.TabIndex = 2665; @@ -500,7 +500,7 @@ // this.btStartTest.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btStartTest.Location = new System.Drawing.Point(35, 576); - this.btStartTest.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btStartTest.Margin = new System.Windows.Forms.Padding(4); this.btStartTest.Name = "btStartTest"; this.btStartTest.Size = new System.Drawing.Size(123, 36); this.btStartTest.TabIndex = 2664; @@ -521,7 +521,8 @@ // // timer2 // - this.timer2.Interval = 3500; + this.timer2.Enabled = true; + this.timer2.Interval = 1000; this.timer2.Tick += new System.EventHandler(this.Timer2_Tick); // // InOutModelChange @@ -552,7 +553,7 @@ this.Controls.Add(this.button3); this.Controls.Add(this.button1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "FrmHost"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; diff --git a/WcfControlMonitorHost/FrmHost.cs b/WcfControlMonitorHost/FrmHost.cs index 045d6e6..9f748d7 100644 --- a/WcfControlMonitorHost/FrmHost.cs +++ b/WcfControlMonitorHost/FrmHost.cs @@ -1006,10 +1006,12 @@ namespace wcfControlMonitorClient if (mi.S7connectOnline["S7 connection_1"] == 0) { pbF1S7.Image = wcfControlMonitorClient.Properties.Resources.linkok; + SControlMonitor.PLCClient = false; } else { pbF1S7.Image = wcfControlMonitorClient.Properties.Resources.linkerror; + SControlMonitor.PLCClient = true; } //if (mi.S7connectOnline["S7 connection_2"] == 0) //{ @@ -1695,34 +1697,41 @@ namespace wcfControlMonitorClient private void Timer2_Tick(object sender, EventArgs e) { - timer2.Enabled = false; - try + + try { + CStaticClass.WcfControl.UpdateAGVStationMassge(); + } + catch (Exception ex) { - { - //string errtext = string.Empty; - //if (CStaticClass.WcfControl.updatestatus(out errtext) == false) - //{ - // if (tsStatus.Text.IndexOf(errtext) < 0) - // { - // tsStatus.Text += errtext; - // } - //} + } + //timer2.Enabled = false; + //try + + //{ + // //string errtext = string.Empty; + // //if (CStaticClass.WcfControl.updatestatus(out errtext) == false) + // //{ + // // if (tsStatus.Text.IndexOf(errtext) < 0) + // // { + // // tsStatus.Text += errtext; + // // } + // //} - } - catch (Exception ex) - { - if (tsStatus.Text.IndexOf(ex.Message) < 0) - { - tsStatus.Text += ex.Message; - } - } - finally - { - timer2.Enabled = true; - } + //} + //catch (Exception ex) + //{ + // if (tsStatus.Text.IndexOf(ex.Message) < 0) + // { + // tsStatus.Text += ex.Message; + // } + //} + //finally + //{ + // timer2.Enabled = true; + //} } /// <summary> /// 定时器:定时发送出入库模式 diff --git a/WcfControlMonitorLib/SControlMonitor.cs b/WcfControlMonitorLib/SControlMonitor.cs index 3534b74..797819d 100644 --- a/WcfControlMonitorLib/SControlMonitor.cs +++ b/WcfControlMonitorLib/SControlMonitor.cs @@ -64,6 +64,7 @@ namespace WcfControlMonitorLib private Object thisLock = new Object(); DataView dvclient = new DataView();//20161229 string sqlstr = string.Empty; + public static bool PLCClient = false; #endregion /// <summary> /// 构造函数 @@ -5285,8 +5286,7 @@ namespace WcfControlMonitorLib {//20120420 errtext = OPCClient.CCommonOPCClient.OpcError; RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", string.Format("SControlMonitor.DealWithDeviceState时,订阅组:{0}发生异常,{1}!", deviceindex, errtext)); - OnRefreshMonitor(rmea); - + OnRefreshMonitor(rmea); return false; } errtext = string.Empty; DataView dv = new DataView(); DataView dvsp = new DataView(); DataView dvbc = new DataView(); DataView dvyanshi = new DataView(); @@ -8807,6 +8807,19 @@ namespace WcfControlMonitorLib } return true; } + + + //设备离线时需要重置数据库AGV站台的值 + public void UpdateAGVStationMassge() { + + if (!SControlMonitor.PLCClient) + { + StringBuilder sql = new StringBuilder(); + sql.Remove(0, sql.Length); + sql.Append("update T_AGVIOStation set F_AGVIOStatus=0"); + dbo.ExecuteSql(sql.ToString()); + } + } } } diff --git a/webapi/WindowsFormsApp1/APIChannel.cs b/webapi/WindowsFormsApp1/APIChannel.cs index 311ca04..9c07466 100644 --- a/webapi/WindowsFormsApp1/APIChannel.cs +++ b/webapi/WindowsFormsApp1/APIChannel.cs @@ -33,6 +33,8 @@ namespace WindowsFormsApp1 static String ERROR = String.Empty; private static NancyHost _server; static string address = CommonClassLib.AppSettings.GetValue("Serveradderss"); + public static bool Lock2 = false; + //private static ServiceReference1.I_Managely5Client I_ManageClient = new ServiceReference1.I_Managely5Client(); public static void Start() { @@ -137,107 +139,109 @@ namespace WindowsFormsApp1 #region WMS调用, 在此处理,取消任务 单条形式 Post["/api/wcs/thirdParty/cancelWmsTask", true] = async (x, ct) => { - dbo.TransBegin(); + try { - var body = this.Request.Body; - int length = (int)body.Length; - byte[] data = new byte[length]; - body.Read(data, 0, length); - string jsonStr = System.Text.Encoding.Default.GetString(data); - CommonClassLib.CCarryConvert.WriteLog("WEBAPI", "收到报文", jsonStr.ToString(), ""); - CCallService.WMS_WCS_PARAM_Priority wms_wcs_cancel = Model.JsonHelper.Deserialize<CCallService.WMS_WCS_PARAM_Priority>(jsonStr); - CCallService.WCS_WMS_PARAM_Priority wcs_wms_cancel = new CCallService.WCS_WMS_PARAM_Priority(); //返回的报文 - string err = string.Empty; - string returnJson = string.Empty; - StringBuilder sql = new StringBuilder(); - DataView dv = new DataView(); - DataView dv1 = new DataView(); - if (wms_wcs_cancel != null) - { - //CCallService.CANCEL_DATA canceldata = new CCallService.CANCEL_DATA(); - //canceldata = wms_wcs_cancel.data; - // CCallService.CANCEL_RES_DATA cancelReturn = new CCallService.CANCEL_RES_DATA(); - wms_wcs_cancel.taskId = wms_wcs_cancel.taskId.Trim('D').Trim('C'); - sql.Clear(); - sql.Append("select * from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); - dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; - if (dv.Count == 1)//存在需要删除的任务 - { - int stepOk = Convert.ToInt32(dv[0]["FIntoStepOK"]);//拆分下发 - int FSTATUS = Convert.ToInt32(dv[0]["FSTATUS"]);//任务未执行 - if (stepOk == 0)//未拆分 + + dbo.TransBegin(); + var body = this.Request.Body; + int length = (int)body.Length; + byte[] data = new byte[length]; + body.Read(data, 0, length); + string jsonStr = System.Text.Encoding.Default.GetString(data); + CommonClassLib.CCarryConvert.WriteLog("WEBAPI", "收到报文", jsonStr.ToString(), ""); + CCallService.WMS_WCS_PARAM_Priority wms_wcs_cancel = Model.JsonHelper.Deserialize<CCallService.WMS_WCS_PARAM_Priority>(jsonStr); + CCallService.WCS_WMS_PARAM_Priority wcs_wms_cancel = new CCallService.WCS_WMS_PARAM_Priority(); //返回的报文 + string err = string.Empty; + string returnJson = string.Empty; + StringBuilder sql = new StringBuilder(); + DataView dv = new DataView(); + DataView dv1 = new DataView(); + if (wms_wcs_cancel != null) + { + //CCallService.CANCEL_DATA canceldata = new CCallService.CANCEL_DATA(); + //canceldata = wms_wcs_cancel.data; + // CCallService.CANCEL_RES_DATA cancelReturn = new CCallService.CANCEL_RES_DATA(); + wms_wcs_cancel.taskId = wms_wcs_cancel.taskId.Trim('D').Trim('C'); + sql.Clear(); + sql.Append("select * from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); + dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; + if (dv.Count == 1)//存在需要删除的任务 { - //暂不考虑数据库执行删除指令失败的情况 - sql.Clear(); - sql.Append("delete from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); - dbo.ExecuteSql(sql.ToString()); - //同时还要删除IOControl表的任务信息 - sql.Clear(); - sql.Append("delete from IO_CONTROL where MANAGE_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); + int stepOk = Convert.ToInt32(dv[0]["FIntoStepOK"]);//拆分下发 + int FSTATUS = Convert.ToInt32(dv[0]["FSTATUS"]);//任务未执行 + if (stepOk == 0)//未拆分 + { + //暂不考虑数据库执行删除指令失败的情况 + sql.Clear(); + sql.Append("delete from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); + dbo.ExecuteSql(sql.ToString()); + //同时还要删除IOControl表的任务信息 + sql.Clear(); + sql.Append("delete from IO_CONTROL where MANAGE_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); dbo.ExecuteSql(sql.ToString()); wcs_wms_cancel.code = 0; wcs_wms_cancel.msg = ""; wcs_wms_cancel.data = ""; - } - else if (stepOk == 1 && FSTATUS == 0) { - sql.Clear(); - sql.Append("delete from T_Monitor_Task where F_ManageTaskIndex = '").Append(wms_wcs_cancel.taskId).Append("'"); - dbo.ExecuteSql(sql.ToString()); - sql.Clear(); - sql.Append("delete from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); - var count= dbo.ExecuteSql(sql.ToString()); - //暂不考虑数据库执行删除指令失败的情况 + } + else if (stepOk == 1 && FSTATUS == 0) { + sql.Clear(); + sql.Append("delete from T_Monitor_Task where F_ManageTaskIndex = '").Append(wms_wcs_cancel.taskId).Append("'"); + dbo.ExecuteSql(sql.ToString()); + sql.Clear(); + sql.Append("delete from t_manage_task where FID = '").Append(wms_wcs_cancel.taskId).Append("'"); + var count = dbo.ExecuteSql(sql.ToString()); + //暂不考虑数据库执行删除指令失败的情况 - //同时还要删除IOControl表的任务信息 - sql.Clear(); - sql.Append("delete from IO_CONTROL where MANAGE_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); - dbo.ExecuteSql(sql.ToString()); + //同时还要删除IOControl表的任务信息 + sql.Clear(); + sql.Append("delete from IO_CONTROL where MANAGE_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); + dbo.ExecuteSql(sql.ToString()); wcs_wms_cancel.code = 0; wcs_wms_cancel.msg = ""; wcs_wms_cancel.data = ""; - + + } + else + { + + wcs_wms_cancel.code = 1; + wcs_wms_cancel.msg = "取消任务失败,任务已执行!"; + wcs_wms_cancel.data = ""; + } } - else + else if (dv.Count == 0) { + wcs_wms_cancel.code = 0; + wcs_wms_cancel.msg = "取消任务成功,WCS中无此任务!" + wms_wcs_cancel.taskId; + wcs_wms_cancel.data = ""; + + } + else + { wcs_wms_cancel.code = 1; - wcs_wms_cancel.msg = "取消任务失败,任务已执行!"; + wcs_wms_cancel.msg = "取消任务失败,WCS中有多条相同任务!"; wcs_wms_cancel.data = ""; } - } - else if (dv.Count == 0) - { - - wcs_wms_cancel.code = 0; - wcs_wms_cancel.msg = "取消任务成功,WCS中无此任务!" + wms_wcs_cancel.taskId; - wcs_wms_cancel.data = ""; - - } - else - { - wcs_wms_cancel.code = 1; - wcs_wms_cancel.msg = "取消任务失败,WCS中有多条相同任务!"; - wcs_wms_cancel.data = ""; - } - if (wcs_wms_cancel.code == 0) {//删除成功 - sql.Clear(); - sql.Append("select * from IO_CONTROL where CONTROL_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); - dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; - if (dv1.Count > 0) { + if (wcs_wms_cancel.code == 0) {//删除成功 sql.Clear(); - sql.Append("delete from IO_CONTROL where CONTROL_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); - dbo.ExceSQL(sql.ToString()); + sql.Append("select * from IO_CONTROL where CONTROL_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); + dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; + if (dv1.Count > 0) { + sql.Clear(); + sql.Append("delete from IO_CONTROL where CONTROL_ID = '").Append(wms_wcs_cancel.taskId).Append("'"); + dbo.ExceSQL(sql.ToString()); + } } } - } - returnJson = Model.JsonHelper.Serializer(wcs_wms_cancel); - CommonClassLib.CCarryConvert.WriteLog("WEBAPI", "返回报文", returnJson, ""); - dbo.TransCommit(); - return returnJson; + returnJson = Model.JsonHelper.Serializer(wcs_wms_cancel); + CommonClassLib.CCarryConvert.WriteLog("WEBAPI", "返回报文", returnJson, ""); + dbo.TransCommit(); + return returnJson; } catch (Exception ex) { @@ -484,14 +488,14 @@ namespace WindowsFormsApp1 } else if (wms_wcs.agvTaskStatus == 22)//开始放货 { - status = 3; + status = 4; } else if (wms_wcs.agvTaskStatus == 23)//放货完成 { - status = 4; + status = 5; } else { - status = 0; + status = 3; } wcs_wms.code = 0; wcs_wms.msg = "";