|
|
@@ -17,8 +17,6 @@ public class gaixi6381 : IHttpHandler
|
|
|
|
|
|
public static class PLC
|
|
|
{
|
|
|
- public static string plcIp = "172.18.37.141";
|
|
|
- public static int plcPort = 102;
|
|
|
public static string dbResult = "100.0"; //产品型号(int)产品的标识码(盖板标识码)
|
|
|
public static string dbGoodsType = "100.2";//产品型号:连体:1;智能:2
|
|
|
public static string dbBarcode = "100.8"; //产品条码
|
|
|
@@ -35,32 +33,9 @@ public class gaixi6381 : IHttpHandler
|
|
|
// public static int procedureID = 2; //改洗
|
|
|
//}
|
|
|
|
|
|
+ public static S7 s7=new S7("172.18.37.141");
|
|
|
public JArray result = new JArray();
|
|
|
- public S7 s7 = new S7();
|
|
|
|
|
|
- //打开PLC
|
|
|
- public int PlcOpen()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- s7.Open(PLC.plcIp, PLC.plcPort);
|
|
|
- result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
|
|
|
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
|
|
|
- }
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- //关闭PLC
|
|
|
- public int PlcClose()
|
|
|
- {
|
|
|
- s7.Close();
|
|
|
- result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
|
|
|
- return 1;
|
|
|
- }
|
|
|
|
|
|
//主程序入口
|
|
|
public void ProcessRequest(HttpContext context)
|
|
|
@@ -69,8 +44,6 @@ public class gaixi6381 : IHttpHandler
|
|
|
if (context.Request["barcode"] is object)
|
|
|
{
|
|
|
string barCode = context.Request["barcode"].ToString();
|
|
|
- if (PlcOpen() == 1)
|
|
|
- {
|
|
|
DataTable goodsType = GetGoodinfo(barCode);
|
|
|
/*
|
|
|
//写PLC
|
|
|
@@ -103,8 +76,6 @@ public class gaixi6381 : IHttpHandler
|
|
|
bool resultflag = PlcWriteRepeat<short>(PLC.dbResult, goodsType.Rows[0]["SEATCOVERCODE"].ToString());
|
|
|
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))));
|
|
|
//========================================
|
|
|
- PlcClose();
|
|
|
- }
|
|
|
context.Response.Write(new JsonResult(JsonStatus.success) { rows = result }.ToJson());
|
|
|
}
|
|
|
else
|