Procházet zdrojové kódy

3#刮蹬,调用PLC接口

Administrator před 5 roky
rodič
revize
85c6977d44

+ 63 - 0
DK.Service/CMNModuleService/PLCWorkLogic..cs

@@ -378,5 +378,68 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
 			}
 		}
 		#endregion
+
+		/// <summary>
+		/// 写PLC,通过工位类型
+		/// </summary>
+		/// <param name="conn"></param>
+		/// <param name="workStationType"></param>
+		/// <param name="plcPara"></param>
+		/// <returns></returns>
+		public static ServiceResultEntity PlcWriteByWorkStationType(int workStationType, Hashtable plcPara)
+		{
+			using (IDataAccess conn = DataAccess.Create())
+			{
+				//读取工位配置信息
+				DataTable dataTable = conn.ExecuteDatatable(@"
+					SELECT
+						* 
+					FROM
+						TP_MST_WORKSTATION t 
+					WHERE
+						t.WORKSTATIONTYPEID = @WORKSTATIONTYPE@
+					",
+					new CDAParameter("WORKSTATIONTYPE", workStationType)
+				 );
+
+				if (dataTable == null || dataTable.Rows.Count == 0)
+				{
+					return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "无当前工位信息" };
+				}
+
+				string ip = dataTable.Rows[0]["PLCIP"] + "";
+				int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
+				JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
+
+				//写入PLC
+				using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
+				{
+					//自动按配置写
+					plc.Connect(ip, port);
+					for (int i = 0; i < plcObj.Count; i++)
+					{
+						if (plcObj[i]["type"].ToString().ToLower() == "string")
+							plc.Write<string>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), plcPara[plcObj[i]["name"].ToString()].ToString());
+						else if (plcObj[i]["type"].ToString().ToLower() == "int")
+							plc.Write<short>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToInt16(plcPara[plcObj[i]["name"].ToString()]));
+						else if (plcObj[i]["type"].ToString().ToLower() == "bool")
+							plc.Write<bool>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToBoolean(plcPara[plcObj[i]["name"].ToString()]));
+					}
+
+				}
+
+				//写入操作成功日志
+				string plcParaStr = "";
+				foreach (string key in plcPara.Keys) plcParaStr += " " + key + ":" + plcPara[key].ToString() + " ";
+				Curtain.Log.Logger.Debug("PLC写入成功!" + plcParaStr);
+
+				//PLC操作成功
+				return new ServiceResultEntity()
+				{
+					Status = Constant.ServiceResultStatus.Success,
+					Message = "" //一定不可以有值,为空时才是提交成功
+				};
+			}
+		}
 	}
 }

+ 11 - 2
DK.Service/PMModuleLogic/PMModuleLogicDAL.cs

@@ -10,6 +10,7 @@
  *******************************************************************************/
 
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using System.IO;
@@ -502,7 +503,7 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
                 #endregion
 
                 // 如果是3#包装,更新三车间包装标识
-                if (procedure.ProcedureID == 107)
+                if (string.IsNullOrEmpty(dr["out_errMsg"] +"") && procedure.ProcedureID == 107)
                 {
                     string sql = string.Empty;
                     int r = 0;
@@ -518,11 +519,19 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
                 }
 
                 // 如果是3#上水,调用PLC接口 2020-09-03 fubin
-                if (procedure.ProcedureID == 94)
+                if (string.IsNullOrEmpty(dr["out_errMsg"] + "") && procedure.ProcedureID == 94)
                 {
                     errMsg = PLCModuleLogic.DoPLCWorkByUser_HEGII_S3(sUserInfo, barcodeTable.Rows[0]["Barcode"].ToString(), 94).Message;
                 }
 
+                // 如果是3#刮蹬,调用PLC接口 2020-09-07 fubin
+                if (string.IsNullOrEmpty(dr["out_errMsg"] + "") && procedure.ProcedureID == 99)
+                {
+                    Hashtable plcPara = new Hashtable();
+                    plcPara.Add("finishflag", true);
+                    errMsg = PLCModuleLogic.PlcWriteByWorkStationType(3201, plcPara).Message;
+                }
+
                 // 没有错误 提交事务
                 if (string.IsNullOrEmpty(errMsg))
                 {