|
@@ -27,6 +27,7 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
public static string dbStatus = "1000.14"; //状态标识 1时读取下一条信息传递
|
|
public static string dbStatus = "1000.14"; //状态标识 1时读取下一条信息传递
|
|
|
public static string dbGoodsCodes = "1000.18"; //产品型号 strig
|
|
public static string dbGoodsCodes = "1000.18"; //产品型号 strig
|
|
|
|
|
|
|
|
|
|
+ public static string packlineName = "实际2线";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public bool resultFlag = false;
|
|
public bool resultFlag = false;
|
|
@@ -72,10 +73,18 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
if (PlcOpen() == 1)
|
|
if (PlcOpen() == 1)
|
|
|
{
|
|
{
|
|
|
|
|
+ /*readFlag 1、2、0
|
|
|
|
|
+ 1:代表上一条数据 PLC 已保存完成,需要传新工单(mes处理)
|
|
|
|
|
+ a:先更新当前工单为完成
|
|
|
|
|
+ b:查询下一个新工单
|
|
|
|
|
+ c:写入PLC,标识位更新成2,等包装线处理
|
|
|
|
|
+ 2:等包装线处理,开始处理时,标识位被包装线改成0(包装线 处理)
|
|
|
|
|
+ 0:包装线开始处理工单,处理完成后,标识位被包装线改成1,保证线等待下一工单(包装线 处理)
|
|
|
|
|
+ */
|
|
|
int readFlag = PlcReadReadFlag();
|
|
int readFlag = PlcReadReadFlag();
|
|
|
|
|
|
|
|
//标识等于1时,代表上一条数据 PLC 已保存完成
|
|
//标识等于1时,代表上一条数据 PLC 已保存完成
|
|
|
- if(readFlag == 1)
|
|
|
|
|
|
|
+ if (readFlag == 1)
|
|
|
{
|
|
{
|
|
|
//读取包装工单 ID
|
|
//读取包装工单 ID
|
|
|
int formID = PlcReadFormID();
|
|
int formID = PlcReadFormID();
|
|
@@ -83,102 +92,62 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
//MES 更新该条工单的同步状态;
|
|
//MES 更新该条工单的同步状态;
|
|
|
int updateFlag = UpdateForm(formID);
|
|
int updateFlag = UpdateForm(formID);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //时根据包装线及执行顺序给 PLC 传输下一条的工单信息,更新标识位为 0,
|
|
|
|
|
- if (updateFlag > 0)
|
|
|
|
|
- {
|
|
|
|
|
- DataRow dr = GetForms(0);
|
|
|
|
|
- //传输数据
|
|
|
|
|
- if (dr != null)
|
|
|
|
|
- {
|
|
|
|
|
- PlcWriteRepeat<int>(PLC.dbFormID, Convert.ToInt32(dr["FORMID"].ToString()));//工单ID
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbStackNum, Convert.ToInt16(dr["STACKNUM"].ToString()));//码垛数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(dr["GOODSTYPE"].ToString())); //产品类型 1:智能 2:连体
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateType, Convert.ToInt16(dr["PLATETYPE"].ToString()));//托盘类型 1:铁托 2:胶托
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateNum, Convert.ToInt16(dr["PLATENUM"].ToString())); //产品数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(dr["GOODSCODE"].ToString()));//产品型号 1000.12
|
|
|
|
|
- PlcWriteRepeat<string>(PLC.dbGoodsCodes, dr["GOODSCODES"].ToString());//产品型号 1000.18
|
|
|
|
|
- }
|
|
|
|
|
- result.Add(new JObject(new JProperty("PLC读出(核对)",
|
|
|
|
|
- "FormID["+ PLC.dbFormID + "] =" + s7.Read<int>(PLC.dbFormID) +
|
|
|
|
|
- ";StackNum[" + PLC.dbStackNum + "] = " + s7.Read<short>(PLC.dbStackNum) +
|
|
|
|
|
- ";GoodsType[" + PLC.dbGoodsType + "] = " + s7.Read<short>(PLC.dbGoodsType) +
|
|
|
|
|
- ";PlateType[" + PLC.dbPlateType + "] = " + s7.Read<short>(PLC.dbPlateType) +
|
|
|
|
|
- ";PlateNum[" + PLC.dbPlateNum + "] = " + s7.Read<short>(PLC.dbPlateNum) +
|
|
|
|
|
- ";GoodsCode[" + PLC.dbGoodsCode + "] = " + s7.Read<short>(PLC.dbGoodsCode) +
|
|
|
|
|
- ";GoodsCodes[" + PLC.dbGoodsCodes + "] = " + s7.Read<string>(PLC.dbGoodsCodes, 14)
|
|
|
|
|
- )));
|
|
|
|
|
- //========================================
|
|
|
|
|
- context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
|
|
|
|
|
|
|
+ DataRow dr = GetForms(0);
|
|
|
|
|
+ //传输数据
|
|
|
|
|
+ if (dr != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ PlcWriteRepeat<int>(PLC.dbFormID, Convert.ToInt32(dr["FORMID"].ToString()));//工单ID
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbStackNum, Convert.ToInt16(dr["STACKNUM"].ToString()));//码垛数量
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(dr["GOODSTYPE"].ToString())); //产品类型 1:智能 2:连体
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbPlateType, Convert.ToInt16(dr["PLATETYPE"].ToString()));//托盘类型 1:铁托 2:胶托
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbPlateNum, Convert.ToInt16(dr["PLATENUM"].ToString())); //产品数量
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(dr["GOODSCODE"].ToString()));//产品型号 1000.12
|
|
|
|
|
+ PlcWriteRepeat<string>(PLC.dbGoodsCodes, dr["GOODSCODES"].ToString());//产品型号 1000.18
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- DataRow dr = GetForms(formID);
|
|
|
|
|
- //传输数据
|
|
|
|
|
- if (dr != null)
|
|
|
|
|
- {
|
|
|
|
|
- PlcWriteRepeat<int>(PLC.dbFormID, Convert.ToInt32(dr["FORMID"].ToString()));//工单ID
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbStackNum, Convert.ToInt16(dr["STACKNUM"].ToString()));//码垛数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(dr["GOODSTYPE"].ToString())); //产品类型 1:智能 2:连体
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateType, Convert.ToInt16(dr["PLATETYPE"].ToString()));//托盘类型 1:铁托 2:胶托
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateNum, Convert.ToInt16(dr["PLATENUM"].ToString())); //产品数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(dr["GOODSCODE"].ToString()));//产品型号 1000.12
|
|
|
|
|
- PlcWriteRepeat<string>(PLC.dbGoodsCodes, dr["GOODSCODES"].ToString());//产品型号 1000.18
|
|
|
|
|
- }
|
|
|
|
|
- result.Add(new JObject(new JProperty("PLC读出(核对)",
|
|
|
|
|
- "FormID["+ PLC.dbFormID + "] =" + s7.Read<int>(PLC.dbFormID) +
|
|
|
|
|
- ";StackNum[" + PLC.dbStackNum + "] = " + s7.Read<short>(PLC.dbStackNum) +
|
|
|
|
|
- ";GoodsType[" + PLC.dbGoodsType + "] = " + s7.Read<short>(PLC.dbGoodsType) +
|
|
|
|
|
- ";PlateType[" + PLC.dbPlateType + "] = " + s7.Read<short>(PLC.dbPlateType) +
|
|
|
|
|
- ";PlateNum[" + PLC.dbPlateNum + "] = " + s7.Read<short>(PLC.dbPlateNum) +
|
|
|
|
|
- ";GoodsCode[" + PLC.dbGoodsCode + "] = " + s7.Read<short>(PLC.dbGoodsCode) +
|
|
|
|
|
- ";GoodsCodes[" + PLC.dbGoodsCodes + "] = " + s7.Read<string>(PLC.dbGoodsCodes, 14)
|
|
|
|
|
- )));
|
|
|
|
|
- //========================================
|
|
|
|
|
- context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ PlcWriteRepeat<short>(PLC.dbStatus, (short)2);//mes处理完成,推送新单标识
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC写入(新)",
|
|
|
|
|
+ "dbStatus[" + PLC.dbStatus + "]=2" +
|
|
|
|
|
+ ";FormID[" + PLC.dbFormID + "]=" + dr["FORMID"] +
|
|
|
|
|
+ ";StackNum[" + PLC.dbStackNum + "]=" + dr["STACKNUM"] +
|
|
|
|
|
+ ";GoodsType[" + PLC.dbGoodsType + "]=" + dr["GOODSTYPE"] +
|
|
|
|
|
+ ";PlateType[" + PLC.dbPlateType + "]=" + dr["PLATETYPE"] +
|
|
|
|
|
+ ";PlateNum[" + PLC.dbPlateNum + "]=" + dr["PLATENUM"] +
|
|
|
|
|
+ ";GoodsCode[" + PLC.dbGoodsCode + "]=" + dr["GOODSCODE"] +
|
|
|
|
|
+ ";GoodsCodes[" + PLC.dbGoodsCodes + "]=" + dr["GOODSCODES"]
|
|
|
|
|
+ )));
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- DataRow dr = GetForms(0);
|
|
|
|
|
- //传输数据
|
|
|
|
|
- if (dr != null)
|
|
|
|
|
- {
|
|
|
|
|
- PlcWriteRepeat<int>(PLC.dbFormID, Convert.ToInt32(dr["FORMID"].ToString()));//工单ID
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbStackNum, Convert.ToInt16(dr["STACKNUM"].ToString()));//码垛数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(dr["GOODSTYPE"].ToString())); //产品类型 1:智能 2:连体
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateType, Convert.ToInt16(dr["PLATETYPE"].ToString()));//托盘类型 1:铁托 2:胶托
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbPlateNum, Convert.ToInt16(dr["PLATENUM"].ToString())); //产品数量
|
|
|
|
|
- PlcWriteRepeat<short>(PLC.dbGoodsCode, Convert.ToInt16(dr["GOODSCODE"].ToString()));//产品型号 1000.12
|
|
|
|
|
- PlcWriteRepeat<string>(PLC.dbGoodsCodes, dr["GOODSCODES"].ToString());//产品型号 1000.18
|
|
|
|
|
- }
|
|
|
|
|
- result.Add(new JObject(new JProperty("PLC读出(核对)",
|
|
|
|
|
- "FormID["+ PLC.dbFormID + "] =" + s7.Read<int>(PLC.dbFormID) +
|
|
|
|
|
- ";StackNum[" + PLC.dbStackNum + "] = " + s7.Read<short>(PLC.dbStackNum) +
|
|
|
|
|
- ";GoodsType[" + PLC.dbGoodsType + "] = " + s7.Read<short>(PLC.dbGoodsType) +
|
|
|
|
|
- ";PlateType[" + PLC.dbPlateType + "] = " + s7.Read<short>(PLC.dbPlateType) +
|
|
|
|
|
- ";PlateNum[" + PLC.dbPlateNum + "] = " + s7.Read<short>(PLC.dbPlateNum) +
|
|
|
|
|
- ";GoodsCode[" + PLC.dbGoodsCode + "] = " + s7.Read<short>(PLC.dbGoodsCode) +
|
|
|
|
|
- ";GoodsCodes[" + PLC.dbGoodsCodes + "] = " + s7.Read<string>(PLC.dbGoodsCodes, 14)
|
|
|
|
|
- )));
|
|
|
|
|
- //========================================
|
|
|
|
|
- context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
|
|
|
|
|
- //包装工单 ID错误
|
|
|
|
|
- //PlcWriteResult(2);
|
|
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC写入(无)", PLC.dbStatus)));
|
|
|
}
|
|
}
|
|
|
|
|
+ result.Add(new JObject(new JProperty("PLC读出(核对)",
|
|
|
|
|
+ "dbStatus[" + PLC.dbStatus + "]=" + s7.Read<short>(PLC.dbStatus) +
|
|
|
|
|
+ ";FormID[" + PLC.dbFormID + "]=" + s7.Read<int>(PLC.dbFormID) +
|
|
|
|
|
+ ";StackNum[" + PLC.dbStackNum + "]=" + s7.Read<short>(PLC.dbStackNum) +
|
|
|
|
|
+ ";GoodsType[" + PLC.dbGoodsType + "]=" + s7.Read<short>(PLC.dbGoodsType) +
|
|
|
|
|
+ ";PlateType[" + PLC.dbPlateType + "]=" + s7.Read<short>(PLC.dbPlateType) +
|
|
|
|
|
+ ";PlateNum[" + PLC.dbPlateNum + "]=" + s7.Read<short>(PLC.dbPlateNum) +
|
|
|
|
|
+ ";GoodsCode[" + PLC.dbGoodsCode + "]=" + s7.Read<short>(PLC.dbGoodsCode) +
|
|
|
|
|
+ ";GoodsCodes[" + PLC.dbGoodsCodes + "]=" + s7.Read<string>(PLC.dbGoodsCodes, 14)
|
|
|
|
|
+ )));
|
|
|
|
|
+ //========================================
|
|
|
|
|
+ //context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 标识位不是1,不做任何处理
|
|
|
PlcClose();
|
|
PlcClose();
|
|
|
}
|
|
}
|
|
|
- context.Response.Write(System.Environment.NewLine + (new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson()));
|
|
|
|
|
|
|
+ context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
//读取PLC标识
|
|
//读取PLC标识
|
|
|
public int PlcReadReadFlag()
|
|
public int PlcReadReadFlag()
|
|
|
{
|
|
{
|
|
|
- if (!resultFlag) return -1;
|
|
|
|
|
|
|
+ if (!resultFlag)
|
|
|
|
|
+ return -1;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
int read = Convert.ToInt16(s7.Read<short>(PLC.dbStatus));
|
|
int read = Convert.ToInt16(s7.Read<short>(PLC.dbStatus));
|
|
@@ -196,7 +165,8 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
//读取包装工单ID
|
|
//读取包装工单ID
|
|
|
public int PlcReadFormID()
|
|
public int PlcReadFormID()
|
|
|
{
|
|
{
|
|
|
- if (!resultFlag) return 0;
|
|
|
|
|
|
|
+ if (!resultFlag)
|
|
|
|
|
+ return 0;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
int formID = Convert.ToInt32(s7.Read<int>(PLC.dbFormID));
|
|
int formID = Convert.ToInt32(s7.Read<int>(PLC.dbFormID));
|
|
@@ -242,20 +212,25 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
{
|
|
{
|
|
|
using (IDataAccess conn = DataAccess.Create())
|
|
using (IDataAccess conn = DataAccess.Create())
|
|
|
{
|
|
{
|
|
|
- int results = conn.ExecuteNonQuery(@"
|
|
|
|
|
- update TP_MST_PACKINGFORM set sycnflag = 1 WHERE packingline = 2 and packingformid = @PACKINGFORMID@ and sycnflag = 0
|
|
|
|
|
- ",
|
|
|
|
|
|
|
+ // int results = conn.ExecuteNonQuery(@"
|
|
|
|
|
+ // update TP_MST_PACKINGFORM set sycnflag = 1 WHERE packingline = 2 and packingformid = @PACKINGFORMID@ and sycnflag = 0
|
|
|
|
|
+ //",
|
|
|
|
|
+ // new CDAParameter("PACKINGFORMID", packingformid)
|
|
|
|
|
+ // );
|
|
|
|
|
+
|
|
|
|
|
+ int results = conn.ExecuteNonQuery("update TP_MST_PACKINGFORM set sycnflag = 1, REMARKS = REMARKS || '" + PLC.packlineName + "' WHERE packingformid = @PACKINGFORMID@ and sycnflag <> 1",
|
|
|
new CDAParameter("PACKINGFORMID", packingformid)
|
|
new CDAParameter("PACKINGFORMID", packingformid)
|
|
|
);
|
|
);
|
|
|
- if(results > 0 )
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (results > 0)
|
|
|
{
|
|
{
|
|
|
- result.Add(new JObject(new JProperty("MES更新(同步状态:OK)", "")));
|
|
|
|
|
|
|
+ result.Add(new JObject(new JProperty("MES更新(同步状态:OK)", packingformid.ToString())));
|
|
|
return results;
|
|
return results;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
//resultFlag = false;
|
|
//resultFlag = false;
|
|
|
- result.Add(new JObject(new JProperty("MES更新(同步状态:ERR)","未更新或已更新!")));
|
|
|
|
|
|
|
+ result.Add(new JObject(new JProperty("MES更新(同步状态:ERR)", "未更新或已更新!")));
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -297,7 +272,7 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
left join tp_mst_datadictionary d on pf.platetype = d.dictionaryid and d.dictionarytype = 'TPC031'
|
|
left join tp_mst_datadictionary d on pf.platetype = d.dictionaryid and d.dictionarytype = 'TPC031'
|
|
|
left join tp_mst_datadictionary d1 on pf.stacknum = d1.dictionaryid and d1.dictionarytype = 'TPC032'
|
|
left join tp_mst_datadictionary d1 on pf.stacknum = d1.dictionaryid and d1.dictionarytype = 'TPC032'
|
|
|
left join V_GOODS_MATERIALCODE gg ON gg.GOODSID = pf.GOODSID AND gg.MATERIALCODE = pf.MATERIALCODE
|
|
left join V_GOODS_MATERIALCODE gg ON gg.GOODSID = pf.GOODSID AND gg.MATERIALCODE = pf.MATERIALCODE
|
|
|
- WHERE pf.packingformid = "+formid+@"
|
|
|
|
|
|
|
+ WHERE pf.packingformid = " + formid + @"
|
|
|
ORDER BY PF.CREATETIME ,PF.ORDERNO
|
|
ORDER BY PF.CREATETIME ,PF.ORDERNO
|
|
|
";
|
|
";
|
|
|
|
|
|
|
@@ -339,7 +314,7 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
}
|
|
}
|
|
|
DataTable dt = conn.ExecuteDatatable(sql);
|
|
DataTable dt = conn.ExecuteDatatable(sql);
|
|
|
|
|
|
|
|
- if(dt.Rows.Count > 0 )
|
|
|
|
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
{
|
|
{
|
|
|
JObject obj = new JObject();
|
|
JObject obj = new JObject();
|
|
|
obj.Add(new JProperty("FORMID", dt.Rows[0]["FORMID"].ToString()));
|
|
obj.Add(new JProperty("FORMID", dt.Rows[0]["FORMID"].ToString()));
|
|
@@ -355,7 +330,7 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
//resultFlag = false;
|
|
//resultFlag = false;
|
|
|
- result.Add(new JObject(new JProperty("MES读取(工单信息:ERR)","工单未找到!")));
|
|
|
|
|
|
|
+ result.Add(new JObject(new JProperty("MES读取(工单信息:ERR)", "工单未找到!")));
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -368,14 +343,14 @@ public class autoPackingForm6157 : IHttpHandler
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public bool PlcWriteRepeat<T>(string db,object value,int repeat = 5)
|
|
|
|
|
|
|
+ public bool PlcWriteRepeat<T>(string db, object value, int repeat = 5)
|
|
|
{
|
|
{
|
|
|
bool isSuccess = false;
|
|
bool isSuccess = false;
|
|
|
isSuccess = s7.Write<T>(db, (T)(value));
|
|
isSuccess = s7.Write<T>(db, (T)(value));
|
|
|
result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
|
|
result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
|
|
|
|
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
|
- while ( !isSuccess && i<repeat )
|
|
|
|
|
|
|
+ while (!isSuccess && i < repeat)
|
|
|
{
|
|
{
|
|
|
s7.IS_OPEN = false;
|
|
s7.IS_OPEN = false;
|
|
|
isSuccess = s7.Write<T>(db, (T)(value));
|
|
isSuccess = s7.Write<T>(db, (T)(value));
|