xuwei 2 лет назад
Родитель
Сommit
5ee59244a9
1 измененных файлов с 64 добавлено и 0 удалено
  1. 64 0
      wwwroot/api/plc/plc_led_data.ashx

+ 64 - 0
wwwroot/api/plc/plc_led_data.ashx

@@ -0,0 +1,64 @@
+<%@ WebHandler Language="C#" Class="plc_test" %>
+
+using System;
+using System.Web;
+using System.Collections.Generic;
+using Curtain.Net.Sockets;
+using DK.XuWei.WebMes;
+
+public class plc_test : IHttpHandler
+{
+    public struct LedData
+    {
+        public string workstation;
+        public string goodscode;
+        public string goodsmodule;
+        public string goodstype;
+    }
+
+    public void ProcessRequest(HttpContext context)
+    {
+        context.Response.ContentType = "text/plain";
+        List<LedData> ledData = new List<LedData>();
+
+
+        if (context.Application["led_data"] is object)
+            ledData = (List<LedData>)context.Application["led_data"];
+
+        //条码转换生产数据
+        if(context.Request["barcode"] is object)
+            ledData.Add(new LedData() {
+                workstation = context.Request["barcode"],
+                goodscode = context.Request["barcode"],
+                goodsmodule = context.Request["barcode"],
+                goodstype = context.Request["barcode"]
+            });
+
+        context.Application["led_data"] = ledData;
+
+        //写入PLC
+        SiemensS7.Open("127.0.0.1", 102);
+        //写业务数据
+        for(int i=0;i<ledData.Count;i++)
+        {
+            SiemensS7.Write<string>("DB2000.2", ledData[i].goodscode);
+        }
+
+        //写标识位
+        //SiemensS7.Write<short>("DB2000.1",1);
+
+        SiemensS7.Close();
+
+        context.Response.Write(new JsonResult(ledData).ToJson());
+
+    }
+
+    public bool IsReusable
+    {
+        get
+        {
+            return false;
+        }
+    }
+
+}