|
|
@@ -22,6 +22,7 @@ public class gaixiJiaoJie2206 : IHttpHandler {
|
|
|
public static string dbGoodsType = "100.2";//产品型号:连体:1;智能:2
|
|
|
public static string dbBarcode = "100.6"; //产品条码
|
|
|
public static string dbUsercode = "100.18";
|
|
|
+ public static string dbInfo = "100.26";//接收条码信息(int)接收不成功=0,接收成功=1
|
|
|
}
|
|
|
|
|
|
public static class API
|
|
|
@@ -85,27 +86,47 @@ public class gaixiJiaoJie2206 : IHttpHandler {
|
|
|
if (addWorkPiece == 1)
|
|
|
{
|
|
|
int goodsType = GetGoodinfo(barCode);
|
|
|
- //写PLC
|
|
|
- bool goodstypeflag = s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
- bool barcodeflag = s7.Write<string>(PLC.dbBarcode, barCode);
|
|
|
- bool resultflag = s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
|
|
|
- result.Add(new JObject(new JProperty("PLC写入返回布尔值 ",resultflag.ToString()+";"+goodstypeflag.ToString()+";"+barcodeflag.ToString())));;
|
|
|
- for (int i = 0; i < 3; i++)
|
|
|
+ ////写PLC
|
|
|
+ //bool goodstypeflag = s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
+ //bool barcodeflag = s7.Write<string>(PLC.dbBarcode, barCode);
|
|
|
+ //bool resultflag = s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
+
|
|
|
+ //result.Add(new JObject(new JProperty("PLC写入返回布尔值 ",resultflag.ToString()+";"+goodstypeflag.ToString()+";"+barcodeflag.ToString())));;
|
|
|
+ //for (int i = 0; i < 3; i++)
|
|
|
+ //{
|
|
|
+ // //if (Convert.ToInt16(s7.Read<short>(PLC.dbResult)) != Convert.ToInt16(1) ||
|
|
|
+ // // Convert.ToInt16(s7.Read<short>(PLC.dbGoodsType)) != Convert.ToInt16(goodsType) ||
|
|
|
+ // // s7.Read<string>(PLC.dbBarcode, 11).ToString() != barCode)
|
|
|
+ // if (!resultflag || !goodstypeflag || !barcodeflag)
|
|
|
+ // {
|
|
|
+ // //写PLC
|
|
|
+ // s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
+ // s7.Write<string>(PLC.dbBarcode, barCode);
|
|
|
+ // s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ bool goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
+ bool barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
|
|
|
+ bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
+
|
|
|
+ int repeat = 5;
|
|
|
+ int i = 1;
|
|
|
+ result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
|
|
|
+
|
|
|
+ while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
|
|
|
{
|
|
|
- //if (Convert.ToInt16(s7.Read<short>(PLC.dbResult)) != Convert.ToInt16(1) ||
|
|
|
- // Convert.ToInt16(s7.Read<short>(PLC.dbGoodsType)) != Convert.ToInt16(goodsType) ||
|
|
|
- // s7.Read<string>(PLC.dbBarcode, 11).ToString() != barCode)
|
|
|
- if (!resultflag || !goodstypeflag || !barcodeflag)
|
|
|
- {
|
|
|
- //写PLC
|
|
|
- s7.Write<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
- s7.Write<string>(PLC.dbBarcode, barCode);
|
|
|
- s7.Write<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
- }
|
|
|
+ result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):")));
|
|
|
+ goodstypeflag = PlcWriteRepeat<short>(PLC.dbGoodsType, Convert.ToInt16(goodsType));
|
|
|
+ barcodeflag = PlcWriteRepeat<string>(PLC.dbBarcode, barCode);
|
|
|
+ resultflag = PlcWriteRepeat<short>(PLC.dbResult, Convert.ToInt16(1));
|
|
|
+
|
|
|
+ result.Add(new JObject(new JProperty("PLC读取接收条码数据:",PLC.dbInfo + " = " + s7.Read<short>(PLC.dbInfo) + ";")));
|
|
|
+ i++;
|
|
|
}
|
|
|
|
|
|
- result.Add(new JObject(new JProperty("PLC写入(信息:OK)",PLC.dbResult + " = " +s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsType+ " = " + s7.Read<short>(PLC.dbGoodsType) + ";"+ PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode,11))));
|
|
|
+ result.Add(new JObject(new JProperty("PLC读出(核对)",PLC.dbResult + " = " +s7.Read<short>(PLC.dbResult) + ";" + PLC.dbGoodsType+ " = " + s7.Read<short>(PLC.dbGoodsType) + ";"+ PLC.dbBarcode + " = " + s7.Read<string>(PLC.dbBarcode,11))));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -128,6 +149,22 @@ public class gaixiJiaoJie2206 : IHttpHandler {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public bool PlcWriteRepeat<T>(string db,object value,int repeat = 5)
|
|
|
+ {
|
|
|
+ bool isSuccess = false;
|
|
|
+ isSuccess = s7.Write<T>(db, (T)(value));
|
|
|
+ result.Add(new JObject(new JProperty("PLC写入数据:", db + "=" + value.ToString())));
|
|
|
+ //int i = 0;
|
|
|
+ //while ( Convert.ToInt16(s7.Read<short>(PLC.dbInfo)) != Convert.ToInt16(1) && i<repeat )
|
|
|
+ //{
|
|
|
+ // isSuccess = s7.Write<T>(db, (T)(value));
|
|
|
+ // result.Add(new JObject(new JProperty("PLC写入数据(重写第" + i.ToString() + "次):", db + "=" + value.ToString())));
|
|
|
+ // i++;
|
|
|
+ //}
|
|
|
+ return isSuccess;
|
|
|
+ }
|
|
|
+
|
|
|
//读取USERCODE
|
|
|
public string PlcReadUsercode()
|
|
|
{
|