|
@@ -28,6 +28,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
public static string dbRead = "1.26";
|
|
public static string dbRead = "1.26";
|
|
|
public static string[] dbBarcodeBlock = { "2.2", "2.32", "2.62", "2.92", "2.122", "2.152", "2.182", "2.212", "2.242", "2.272", "2.302", "2.332" };
|
|
public static string[] dbBarcodeBlock = { "2.2", "2.32", "2.62", "2.92", "2.122", "2.152", "2.182", "2.212", "2.242", "2.272", "2.302", "2.332" };
|
|
|
public static string dbBanMa = "2.362";//2.360 => 2.362
|
|
public static string dbBanMa = "2.362";//2.360 => 2.362
|
|
|
|
|
+ public static string dbUsercode = "2.376"; //150.374 => 150.376
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static class API
|
|
public static class API
|
|
@@ -39,7 +40,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
public static string userPassword = "D63AC55256F8048265387A2B0388F1D2";
|
|
public static string userPassword = "D63AC55256F8048265387A2B0388F1D2";
|
|
|
public static string sessionKey = "C2A5AE55-8E9B-45F9-A0AF-6A5A1BF3457C";
|
|
public static string sessionKey = "C2A5AE55-8E9B-45F9-A0AF-6A5A1BF3457C";
|
|
|
public static int procedureID = 107; //3#包装
|
|
public static int procedureID = 107; //3#包装
|
|
|
- public static bool debug = false;
|
|
|
|
|
|
|
+ public static bool debug = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public bool resultFlag = false;
|
|
public bool resultFlag = false;
|
|
@@ -79,7 +80,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbRead));
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbRead));
|
|
|
result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -98,7 +98,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
|
|
|
result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -117,7 +116,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
|
|
|
result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -136,7 +134,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
|
|
int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
|
|
|
result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -160,7 +157,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
|
|
obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
|
|
|
}
|
|
}
|
|
|
result.Add(new JObject(new JProperty("PLC读取(产品条码)", obj)));
|
|
result.Add(new JObject(new JProperty("PLC读取(产品条码)", obj)));
|
|
|
- resultFlag = true;
|
|
|
|
|
return barCodes;
|
|
return barCodes;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -179,7 +175,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
|
|
string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
|
|
|
result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -198,7 +193,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
string read = SiemensS7.Read<string>(PLC.dbMaterialcode, 14).ToString();
|
|
string read = SiemensS7.Read<string>(PLC.dbMaterialcode, 14).ToString();
|
|
|
result.Add(new JObject(new JProperty("PLC读取(物料号)", PLC.dbMaterialcode + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(物料号)", PLC.dbMaterialcode + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -217,7 +211,6 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt32(SiemensS7.Read<short>(PLC.dbResult));
|
|
int read = Convert.ToInt32(SiemensS7.Read<short>(PLC.dbResult));
|
|
|
result.Add(new JObject(new JProperty("PLC读取(结果)", PLC.dbResult + " = " + read.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC读取(结果)", PLC.dbResult + " = " + read.ToString())));
|
|
|
- resultFlag = true;
|
|
|
|
|
return read;
|
|
return read;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -228,6 +221,24 @@ public class autoPacking6151 : IHttpHandler
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //读取USERCODE
|
|
|
|
|
+ public string PlcReadUsercode()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!resultFlag) return "";
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ string read = SiemensS7.Read<string>(PLC.dbUsercode,6).ToString();
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC读取(USECODE)", PLC.dbUsercode + " = " + read.ToString())));
|
|
|
|
|
+ return read;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
|
|
|
|
|
+ resultFlag = false;
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//写入条码
|
|
//写入条码
|
|
|
public int PlcWriteBarcode(string barCode)
|
|
public int PlcWriteBarcode(string barCode)
|
|
|
{
|
|
{
|
|
@@ -324,12 +335,25 @@ public class autoPacking6151 : IHttpHandler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//写入执行结果
|
|
//写入执行结果
|
|
|
|
|
+ // 1 通过 2 条码格式错误 3 产品不可到达 4 MES异常 5 条码不一致 6 绑板完成 7 工号读取错误
|
|
|
public int PlcWriteResult(Int16 flag)
|
|
public int PlcWriteResult(Int16 flag)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
|
|
+ string message = "";
|
|
|
|
|
+ switch(flag)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 1:message = "OK:扫码通过";break;
|
|
|
|
|
+ case 2:message = "ERR:条码格式错误";break;
|
|
|
|
|
+ case 3:message = "ERR:产品不可到达";break;
|
|
|
|
|
+ case 4:message = "ERR:MES异常";break;
|
|
|
|
|
+ case 5:message = "ERR:条码不一致";break;
|
|
|
|
|
+ case 6:message = "ERR:绑板完成";break;
|
|
|
|
|
+ case 7:message = "ERR:工号读取错误";break;
|
|
|
|
|
+ default:message = "ERR:未定义";break;
|
|
|
|
|
+ }
|
|
|
SiemensS7.Write<short>(PLC.dbResult, flag);
|
|
SiemensS7.Write<short>(PLC.dbResult, flag);
|
|
|
- result.Add(new JObject(new JProperty("PLC写入(执行结果)", PLC.dbResult + " = " + flag.ToString())));
|
|
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC写入("+message+")", PLC.dbResult + " = " + flag.ToString())));
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
@@ -392,7 +416,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
resultFlag = false;
|
|
resultFlag = false;
|
|
|
result.Add(new JObject(
|
|
result.Add(new JObject(
|
|
|
- new JProperty("API调用(条码状态)", "操作失败!"),
|
|
|
|
|
|
|
+ new JProperty("API调用(条码状态)", json["d"]["Message"].ToString()),
|
|
|
new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
|
|
new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
|
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
|
new JProperty("参数(barCode)", barCode)
|
|
new JProperty("参数(barCode)", barCode)
|
|
@@ -458,7 +482,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
resultFlag = false;
|
|
resultFlag = false;
|
|
|
result.Add(new JObject(
|
|
result.Add(new JObject(
|
|
|
- new JProperty("API调用(条码验证)", "操作失败!"),
|
|
|
|
|
|
|
+ new JProperty("API调用(条码验证)", json["d"]["Message"].ToString()),
|
|
|
new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
|
|
new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
|
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
|
new JProperty("参数(barCode)", barCode)
|
|
new JProperty("参数(barCode)", barCode)
|
|
@@ -537,7 +561,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
resultFlag = false;
|
|
resultFlag = false;
|
|
|
result.Add(new JObject(
|
|
result.Add(new JObject(
|
|
|
- new JProperty("API调用(装板数量)", "操作失败!"),
|
|
|
|
|
|
|
+ new JProperty("API调用(装板数量)", json["d"]["Message"].ToString()),
|
|
|
new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
|
|
new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
|
|
|
new JProperty("参数(ACTION)", "GetSetting"),
|
|
new JProperty("参数(ACTION)", "GetSetting"),
|
|
|
new JProperty("参数(MODULE)", "FinishedLoadingCar"),
|
|
new JProperty("参数(MODULE)", "FinishedLoadingCar"),
|
|
@@ -617,7 +641,7 @@ public class autoPacking6151 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
resultFlag = false;
|
|
resultFlag = false;
|
|
|
result.Add(new JObject(
|
|
result.Add(new JObject(
|
|
|
- new JProperty("API调用(包装码垛)", "操作失败!"),
|
|
|
|
|
|
|
+ new JProperty("API调用(包装码垛)", json["d"]["Message"].ToString()),
|
|
|
new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
|
|
new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
|
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
new JProperty("参数(procedureID)", API.procedureID),
|
|
|
new JProperty("参数(productionDataEntitys)", productionDataEntitys)
|
|
new JProperty("参数(productionDataEntitys)", productionDataEntitys)
|
|
@@ -686,6 +710,63 @@ public class autoPacking6151 : IHttpHandler
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //读取用户信息
|
|
|
|
|
+ public DataRow GetUserinfo(string userCode)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ using (IDataAccess conn = DataAccess.Create())
|
|
|
|
|
+ {
|
|
|
|
|
+ DataTable dt = conn.ExecuteDatatable(@"
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ u.ACCOUNTCODE,
|
|
|
|
|
+ u.USERID,
|
|
|
|
|
+ u.USERCODE,
|
|
|
|
|
+ u.USERNAME,
|
|
|
|
|
+ u.PASSWORD,
|
|
|
|
|
+ l.SESSIONKEY
|
|
|
|
|
+ FROM
|
|
|
|
|
+ TP_MST_USER u
|
|
|
|
|
+ LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ u.USERCODE = @USERCODE@
|
|
|
|
|
+ ",
|
|
|
|
|
+ new CDAParameter("USERCODE", userCode)
|
|
|
|
|
+ );
|
|
|
|
|
+ if(dt.Rows.Count >0 )
|
|
|
|
|
+ {
|
|
|
|
|
+ API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
|
|
|
|
|
+ API.userId = dt.Rows[0]["USERID"].ToString();
|
|
|
|
|
+ API.userCode = dt.Rows[0]["USERCODE"].ToString();
|
|
|
|
|
+ API.userName = dt.Rows[0]["USERNAME"].ToString();
|
|
|
|
|
+ API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
|
|
|
|
|
+ API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
|
|
|
|
|
+ JObject obj = new JObject();
|
|
|
|
|
+ obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
|
|
|
|
|
+ obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
|
|
|
|
|
+ obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
|
|
|
|
|
+ obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
|
|
|
|
|
+ obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
|
|
|
|
|
+ obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
|
|
|
|
|
+ result.Add(new JObject(new JProperty("MES读取(用户信息)", obj)));
|
|
|
|
|
+ return dt.Rows[0];
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ resultFlag = false;
|
|
|
|
|
+ result.Add(new JObject(new JProperty("MES读取(用户信息)","用户未找到!")));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ resultFlag = false;
|
|
|
|
|
+ result.Add(new JObject(new JProperty("系统异常", e.Message)));
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//主程序入口
|
|
//主程序入口
|
|
|
public void ProcessRequest(HttpContext context)
|
|
public void ProcessRequest(HttpContext context)
|
|
|
{
|
|
{
|
|
@@ -724,13 +805,24 @@ public class autoPacking6151 : IHttpHandler
|
|
|
goodsId = Convert.ToInt16(dr["GOODSID"]);
|
|
goodsId = Convert.ToInt16(dr["GOODSID"]);
|
|
|
logoId = Convert.ToInt16(dr["LOGOID"]);
|
|
logoId = Convert.ToInt16(dr["LOGOID"]);
|
|
|
|
|
|
|
|
- //接口验证条码状态(非必须取消这个接口)
|
|
|
|
|
- //int status = ApiGetStatusBarcode(barCode);
|
|
|
|
|
-
|
|
|
|
|
- //接口验证可到达
|
|
|
|
|
- int check = ApiCheckBarcode(barCode);
|
|
|
|
|
- //写验证结果
|
|
|
|
|
- if (check == -1) PlcWriteResult(3);
|
|
|
|
|
|
|
+ //读取工号
|
|
|
|
|
+ string userCode = PlcReadUsercode();
|
|
|
|
|
+ if (userCode != "")
|
|
|
|
|
+ {
|
|
|
|
|
+ GetUserinfo(userCode);
|
|
|
|
|
+ //接口验证条码状态(非必须取消这个接口)
|
|
|
|
|
+ //int status = ApiGetStatusBarcode(barCode);
|
|
|
|
|
+
|
|
|
|
|
+ //接口验证可到达
|
|
|
|
|
+ int check = ApiCheckBarcode(barCode);
|
|
|
|
|
+ //写验证结果
|
|
|
|
|
+ if (check == -1) PlcWriteResult(3);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //工号错误
|
|
|
|
|
+ PlcWriteResult(7);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -805,13 +897,27 @@ public class autoPacking6151 : IHttpHandler
|
|
|
//绑板处理
|
|
//绑板处理
|
|
|
if(readFlag == 2 || readFlag == 3)
|
|
if(readFlag == 2 || readFlag == 3)
|
|
|
{
|
|
{
|
|
|
- String[] barCodes = PlcReadBarcodes(goodsNum);
|
|
|
|
|
- string banMa = "";
|
|
|
|
|
- if (readFlag == 3) banMa = PlcReadBanma();
|
|
|
|
|
- //绑板处理
|
|
|
|
|
- ApiAddWorkPiece(barCodes, banMa, goodsNum);
|
|
|
|
|
- //写入结果
|
|
|
|
|
- PlcWriteResult(6);
|
|
|
|
|
|
|
+ //读取工号
|
|
|
|
|
+ string userCode = PlcReadUsercode();
|
|
|
|
|
+ if (userCode != "")
|
|
|
|
|
+ {
|
|
|
|
|
+ //读取工号信息
|
|
|
|
|
+ GetUserinfo(userCode);
|
|
|
|
|
+ //读取条码
|
|
|
|
|
+ String[] barCodes = PlcReadBarcodes(goodsNum);
|
|
|
|
|
+ string banMa = "";
|
|
|
|
|
+ if (readFlag == 3) banMa = PlcReadBanma();
|
|
|
|
|
+ //绑板处理
|
|
|
|
|
+ ApiAddWorkPiece(barCodes, banMa, goodsNum);
|
|
|
|
|
+ //绑板完成
|
|
|
|
|
+ PlcWriteResult(6);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //工号错误
|
|
|
|
|
+ PlcWriteResult(7);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//强制绑板完成
|
|
//强制绑板完成
|