From c6377a07e3eb0973156bb4fce581032713e1ded7 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期日, 13 四月 2025 09:48:34 +0800 Subject: [PATCH] 增加循环写入PLC值方法;增加155出库口;增加152、153入口 --- Admin.NET/WCS.Application/PLC/PLCUtil.cs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 45 insertions(+), 1 deletions(-) diff --git a/Admin.NET/WCS.Application/PLC/PLCUtil.cs b/Admin.NET/WCS.Application/PLC/PLCUtil.cs index 99558a9..af3b820 100644 --- a/Admin.NET/WCS.Application/PLC/PLCUtil.cs +++ b/Admin.NET/WCS.Application/PLC/PLCUtil.cs @@ -1,6 +1,7 @@ 锘縰sing DocumentFormat.OpenXml.Bibliography; using DocumentFormat.OpenXml.Drawing; using Elastic.Clients.Elasticsearch; +using Furion.Logging; using IoTClient; using IoTClient.Clients.Modbus; using IoTClient.Clients.PLC; @@ -221,10 +222,53 @@ } } /// <summary> + /// 寰幆鍐欏叆PLC鍊硷紙骞惰鍙栧�煎垽鏂拰鍐欏叆鐨勫�兼槸鍚︿竴鑷达紝鍐欏叆鎺у埗瀛椾笉鑳界敤姝ゆ柟娉曪級 + /// </summary> + public IoTClient.Result SetPlcDBValueRepeat(PLCDataTypeEnum PosType, string DbNumber, string Pos, string Value) + { + IoTClient.Result _result = new IoTClient.Result(); + + int setCount = 0;//鍐欏叆娆℃暟 + while (setCount < 5) + { + string address; + if (DbNumber.StartsWith("DB")) + address = DbNumber + "." + Pos; + else + address = DbNumber + Pos; + _result = this.SetPlcDBValue(PosType, address, Value);//鍐欏叆鍊� + + //绱鍐欏叆娆℃暟 + setCount++; + + if (_result.IsSucceed) + { + //璇诲彇鍐欏叆鐨勫�� + var (res, val) = GetPlcDBValue(PosType, DbNumber, Pos); + if (val.ToString() == Value) + { + //璇诲彇鐨勫�煎拰鍐欏叆鐨勫�间竴鑷达紝鐩存帴璺冲嚭寰幆 + break; + } + } + } + //鍐欏叆鏃ュ織 + Log.Information($"66666666鍐欏叆PLC锛孌bNumber锛歿DbNumber}锛孭os:{Pos},Value:{Value},setCount:{setCount}"); + + return _result; + } + /// <summary> /// 鍐欏叆PLC鍊� /// </summary> + /// <param name="PosType"></param> + /// <param name="DbNumber"></param> + /// <param name="Pos"></param> + /// <param name="Value"></param> + /// <returns></returns> public IoTClient.Result SetPlcDBValue(PLCDataTypeEnum PosType, string DbNumber, string Pos, string Value) { + Log.Information($"66666666鍐欏叆PLC锛孌bNumber锛歿DbNumber}锛孭os:{Pos},Value:{Value}"); + string address; if (DbNumber.StartsWith("DB")) address = DbNumber + "." + Pos; @@ -280,7 +324,7 @@ } } /// <summary> - /// 鍐欏叆PLC鍊� + /// 鎵归噺鍐欏叆PLC鍊� /// </summary> public IoTClient.Result SetPlcBatchDBValue(Dictionary<string, KeyValuePair<string, PLCDataTypeEnum>> listaddress) { -- Gitblit v1.8.0