|
|
@@ -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 = "" //一定不可以有值,为空时才是提交成功
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|