| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <%@ WebHandler Language="C#" Class="autoPacking6151_db" %>
- using System;
- using System.Web;
- using DK.XuWei.WebMes;
- /// <summary>
- /// PLC数据块监控和初始化使用
- /// xuwei add 2023-12-31
- /// </summary>
- public class autoPacking6151_db : IHttpHandler
- {
- public static class PLC
- {
- public static string plcIp = "192.168.1.20";
- public static int plcPort = 102;
- public static string dbBarcode = "1.2"; //1.0 => 1.2
- public static string dbGoodsId = "1.14";
- public static string dbGoodsNum = "1.16";
- public static string dbResult = "1.18";
- public static string dbLogoId = "1.22";//替换产品等级
- public static string dbMaterialcode = "1.30";
- 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 dbBanMa = "2.362";//2.360 => 2.362
- }
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- if (context.Request["init"] is object)
- {
- PlcInit(context);
- }
- else
- {
- PlcRead(context);
- }
- }
- public void PlcInit(HttpContext context)
- {
- SiemensS7.Open(PLC.plcIp, PLC.plcPort);
- SiemensS7.Write<short>(PLC.dbRead, (Int16)1).ToString();
- SiemensS7.Write<string>(PLC.dbBarcode, "00000000000").ToString();
- SiemensS7.Write<string>(PLC.dbMaterialcode, "00000000000000").ToString();
- SiemensS7.Write<short>(PLC.dbGoodsId, (Int16)0).ToString();
- SiemensS7.Write<short>(PLC.dbLogoId, (Int16)0).ToString();
- SiemensS7.Write<short>(PLC.dbGoodsNum, (Int16)0).ToString();
- SiemensS7.Write<short>(PLC.dbResult, (Int16)0).ToString();
- for (int i = 0; i < PLC.dbBarcodeBlock.Length; i++)
- {
- SiemensS7.Write<string>(PLC.dbBarcodeBlock[i], "00000000000").ToString();
- }
- SiemensS7.Write<string>(PLC.dbBanMa, "00000000").ToString();
- SiemensS7.Close();
- context.Response.Write("INIT OK!");
- }
- public void PlcRead(HttpContext context)
- {
- SiemensS7.Open(PLC.plcIp, PLC.plcPort);
- context.Response.Write(PLC.plcIp + ":" + PLC.plcPort + "\n\n");
- if(context.Request["read"] is object)
- {
- Int16 readFlag = Convert.ToInt16(context.Request["read"].ToString());
- SiemensS7.Write<short>(PLC.dbRead, readFlag);
- }
- string read = SiemensS7.Read<short>(PLC.dbRead).ToString();
- context.Response.Write("读取标识:[" + PLC.dbRead + "]:" + read + "\n");
- string bcode = SiemensS7.Read<string>(PLC.dbBarcode, 11).ToString();
- context.Response.Write("条码:[" + PLC.dbBarcode + "]:" + bcode + "\n");
- string materialcode = SiemensS7.Read<string>(PLC.dbMaterialcode,14).ToString();
- context.Response.Write("物料码:[" + PLC.dbMaterialcode + "]:" + materialcode + "\n");
- string goodsid = SiemensS7.Read<short>(PLC.dbGoodsId).ToString();
- context.Response.Write("产品:[" + PLC.dbGoodsId + "]:" + goodsid + "\n");
- string logoid = SiemensS7.Read<short>(PLC.dbLogoId).ToString();
- context.Response.Write("商标:[" + PLC.dbLogoId + "]:" + logoid + "\n");
- string goodsnum = SiemensS7.Read<short>(PLC.dbGoodsNum).ToString();
- context.Response.Write("板数:[" + PLC.dbGoodsNum + "]:" + goodsnum + "\n");
- string result = SiemensS7.Read<short>(PLC.dbResult).ToString();
- context.Response.Write("结果:[" + PLC.dbResult + "]:" + result + "\n\n");
- for (int i = 0; i < PLC.dbBarcodeBlock.Length; i++)
- {
- string barcode = SiemensS7.Read<string>(PLC.dbBarcodeBlock[i], 11).ToString();
- context.Response.Write("条码" + (i + 1).ToString() + ":[" + PLC.dbBarcodeBlock[i] + "]:" + barcode + "\n");
- }
- string banma = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
- SiemensS7.Close();
- context.Response.Write("板码:[" + PLC.dbBanMa + "]:" + banma + "\n");
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
|