|
|
@@ -52,24 +52,22 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
//按当前登录用户在工位表中的当前工号查找工位类型
|
|
|
- //workStationType = getWorkStationType(conn, sUserInfo.UserCode);
|
|
|
- //DataTable dataTable = GetWorkStationInfo(conn, sUserInfo.UserCode);
|
|
|
- //if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
- //{
|
|
|
- // return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
- //}
|
|
|
-
|
|
|
- //if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
- //{
|
|
|
- // string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
- // if (plc_flag != "1")
|
|
|
- // {
|
|
|
- // return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
- // }
|
|
|
- //}
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
+ workStationType = getWorkStationType(conn, sUserInfo.UserCode);
|
|
|
+ DataTable dataTable = GetWorkStationInfo(conn, sUserInfo.UserCode);
|
|
|
+ if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
workStationType = 3211;
|
|
|
|
|
|
//成检交接3211
|
|
|
@@ -323,32 +321,32 @@ t.plc_flag
|
|
|
new CDAParameter("WORKSTATIONTYPE", workStationType),
|
|
|
new CDAParameter("USERCODE", userCode)
|
|
|
);
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
- //if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
- //{
|
|
|
- // return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
- //}
|
|
|
-
|
|
|
- //if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
- //{
|
|
|
- // string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
- // if (plc_flag != "1")
|
|
|
- // {
|
|
|
- // return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
- // }
|
|
|
- //}
|
|
|
- //string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
- //if (string.IsNullOrWhiteSpace(ip))
|
|
|
- //{
|
|
|
- // return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
- //}
|
|
|
- //int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
|
|
|
- // JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
+
|
|
|
+ if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
+ if (string.IsNullOrWhiteSpace(ip))
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ 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>())
|
|
|
{
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
+
|
|
|
//测试静态数据 测试成功
|
|
|
//plc.Connect(ip, port);
|
|
|
//plc.Write<string>("D", "102.2", "2020070101");
|
|
|
@@ -360,15 +358,14 @@ t.plc_flag
|
|
|
//plc.Write<short>("D", "102.14", Convert.ToInt16(plcPara["goodsmodel"]));
|
|
|
|
|
|
//自动按配置写
|
|
|
- //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()]));
|
|
|
- //}
|
|
|
- //冯林勇 modify 2022-08-19 注释掉写入PCL数据
|
|
|
+ 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()]));
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
#if DEBUG
|
|
|
@@ -478,7 +475,7 @@ t.plc_flag
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 写PLC2
|
|
|
+ /// 写PLC2 xuwei modify 2022-09-10 优化代码
|
|
|
/// </summary>
|
|
|
/// <param name="workStationType"></param>
|
|
|
/// <param name="plcPara"></param>
|
|
|
@@ -490,30 +487,33 @@ t.plc_flag
|
|
|
{
|
|
|
List<CDAParameter> paras = new List<CDAParameter>();
|
|
|
|
|
|
-#region 读取工位配置信息
|
|
|
- string sql =
|
|
|
- "SELECT --t.*\n" + @"
|
|
|
-t.workstationtypeid,
|
|
|
-t.workstationname,
|
|
|
-t.procedureid,
|
|
|
-t.groutinglineid,
|
|
|
-t.usercode,
|
|
|
-t.pccode,
|
|
|
-t.plcip,
|
|
|
-t.plcport,
|
|
|
-t.plcobject,
|
|
|
-t.valueflag,
|
|
|
-t.plcobjectread,
|
|
|
-t.plc_flag" +
|
|
|
- " FROM tp_mst_workstation t\n" +
|
|
|
- " WHERE t.workstationtypeid = @workstationtype@";
|
|
|
-
|
|
|
- paras.Add(new CDAParameter("workstationtype", workStationType));
|
|
|
+ #region 读取工位配置信息
|
|
|
+ string sql = @"
|
|
|
+ SELECT
|
|
|
+ T.WORKSTATIONTYPEID,
|
|
|
+ T.WORKSTATIONNAME,
|
|
|
+ T.PROCEDUREID,
|
|
|
+ T.GROUTINGLINEID,
|
|
|
+ T.USERCODE,
|
|
|
+ T.PCCODE,
|
|
|
+ T.PLCIP,
|
|
|
+ T.PLCPORT,
|
|
|
+ T.PLCOBJECT,
|
|
|
+ T.VALUEFLAG,
|
|
|
+ T.PLCOBJECTREAD,
|
|
|
+ T.PLC_FLAG
|
|
|
+ FROM
|
|
|
+ TP_MST_WORKSTATION T
|
|
|
+ WHERE
|
|
|
+ T.PLC_FLAG = 1
|
|
|
+ AND T.WORKSTATIONTYPEID = @WORKSTATIONTYPE@
|
|
|
+ ";
|
|
|
+ paras.Add(new CDAParameter("WORKSTATIONTYPE", workStationType));
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userCode))
|
|
|
{
|
|
|
- sql += " AND t.usercode = @usercode@";
|
|
|
- paras.Add(new CDAParameter("usercode", userCode));
|
|
|
+ sql += " AND T.USERCODE = @USERCODE@";
|
|
|
+ paras.Add(new CDAParameter("USERCODE", userCode));
|
|
|
}
|
|
|
|
|
|
DataTable dataTable = conn.ExecuteDatatable(sql, paras.ToArray());
|
|
|
@@ -529,15 +529,6 @@ t.plc_flag" +
|
|
|
};
|
|
|
//xuwei end
|
|
|
}
|
|
|
-
|
|
|
- if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
- {
|
|
|
- string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
- if (plc_flag != "1")
|
|
|
- {
|
|
|
- return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
- }
|
|
|
- }
|
|
|
#endregion
|
|
|
|
|
|
string ip = dataTable.Rows[0]["PLCIP"] + "";
|