From c9a1df9c19a64844d05d120ff171f523d77e7823 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 22:15:36 +0800
Subject: [PATCH] Merge branch 'xiaoyang' into dev

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs |  123 ++++++++++++++++++++++++++++++----------
 1 files changed, 91 insertions(+), 32 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs
index 142601b..c2dfc11 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs
@@ -1,4 +1,5 @@
 锘�#region << 鐗� 鏈� 娉� 閲� >>
+
 /*----------------------------------------------------------------
  * 鍛藉悕绌洪棿锛歐IDESEAWCS_Communicator
  * 鍒涘缓鑰咃細鑳$搴�
@@ -11,8 +12,9 @@
  * 淇敼鏃堕棿锛�
  * 鐗堟湰锛歏1.0.1
  * 淇敼璇存槑锛�
- * 
+ *
  *----------------------------------------------------------------*/
+
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using HslCommunication;
@@ -20,19 +22,12 @@
 using HslCommunication.LogNet;
 using HslCommunication.Profinet.Siemens;
 using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections;
-using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
-using System.Linq;
 using System.Net;
 using System.Net.NetworkInformation;
 using System.Reflection;
 using System.Text;
-using System.Threading.Tasks;
-using System.Xml.Linq;
 
 namespace WIDESEAWCS_Communicator
 {
@@ -43,6 +38,7 @@
     public class SiemensS7 : BaseCommunicator
     {
         #region Private Member
+
         /// <summary>
         /// HSLCommunication鐨勮タ闂ㄥ瓙鐨凷7鍗忚鐨勯�氳绫�
         /// </summary>
@@ -59,7 +55,7 @@
         private int _port;
 
         /// <summary>
-        /// 褰撳墠閫氳鍣ㄦ槸鍚﹀凡杩炴帴鍒癙LC銆�  
+        /// 褰撳墠閫氳鍣ㄦ槸鍚﹀凡杩炴帴鍒癙LC銆�
         /// </summary>
         private bool _connected;
 
@@ -71,11 +67,13 @@
         private ILogNet _logNet;
 
         private bool _isPing = true;
+
         #endregion Private Member
 
         #region Public Member
-        /// <summary>  
-        /// 鑾峰彇褰撳墠閫氳鍣ㄦ槸鍚﹀凡杩炴帴鍒癙LC銆�  
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠閫氳鍣ㄦ槸鍚﹀凡杩炴帴鍒癙LC銆�
         /// </summary>
         public override bool IsConnected => _connected;
 
@@ -92,10 +90,12 @@
         /// <summary>
         /// 鏄惁鍦ㄥ啓鍏ユ暟鎹悗璇诲彇鏁版嵁纭銆�
         /// </summary>
-        public override bool IsReadAfterWrite { get; set; } = false;
+        public override bool IsReadAfterWrite { get; set; } = true;
+
         #endregion Public Member
 
         #region Constructor Function
+
         /// <summary>
         /// 鏋勯�犲嚱鏁�
         /// </summary>
@@ -118,9 +118,11 @@
             _port = port;//閫氳繃鏋勯�犲嚱鏁拌祴鍊艰繛鎺ヤ娇鐢ㄧ殑绔彛鍙�
             _name = name;
         }
+
         #endregion
 
         #region Private Method
+
         /// <summary>
         /// 浠嶰perateResult瀵硅薄涓幏鍙栬鍙栫殑鏁版嵁銆�
         /// </summary>
@@ -150,7 +152,7 @@
         }
 
         /// <summary>
-        /// 
+        ///
         /// </summary>
         /// <typeparam name="T"></typeparam>
         /// <param name="operateResult"></param>
@@ -221,27 +223,36 @@
             try
             {
                 Type type = value.GetType();
-
                 switch (Type.GetTypeCode(type))
                 {
                     case TypeCode.Int32:
                         return plc.Write(address, Convert.ToInt32(value));
+
                     case TypeCode.UInt32:
                         return plc.Write(address, Convert.ToUInt32(value));
+
                     case TypeCode.Int16:
                         return plc.Write(address, Convert.ToInt16(value));
+
                     case TypeCode.UInt16:
                         return plc.Write(address, Convert.ToUInt16(value));
+
                     case TypeCode.Single:
                         return plc.Write(address, Convert.ToSingle(value));
+
                     case TypeCode.Boolean:
                         return plc.Write(address, Convert.ToBoolean(value));
+
                     case TypeCode.Byte:
                         return plc.Write(address, Convert.ToByte(value));
+
                     case TypeCode.String:
                         return plc.Write(address, Convert.ToString(value));
+
                     case TypeCode.Char:
                         return plc.Write(address, Convert.ToChar(value));
+                    //case TypeCode.arr:
+                    //    return plc.Write(address, Convert.ToChar(value));
                     default:
                         if (value is int[])
                         {
@@ -300,44 +311,53 @@
                             return (int[])GetContent(plc.ReadInt32(address, length), address);
                         else
                             return (int)GetContent(plc.ReadInt32(address), address);
+
                     case TypeCode.UInt32:
                         if (length > 1)
                             return (uint[])GetContent(plc.ReadUInt32(address, length), address);
                         else
                             return (uint)GetContent(plc.ReadUInt32(address), address);
+
                     case TypeCode.Int16:
                         if (length > 1)
                             return (short[])GetContent(plc.ReadInt16(address, length), address);
                         else
                             return (short)GetContent(plc.ReadInt16(address), address);
+
                     case TypeCode.UInt16:
                         if (length > 1)
                             return (ushort[])GetContent(plc.ReadUInt16(address, length), address);
                         else
                             return (ushort)GetContent(plc.ReadUInt16(address), address);
+
                     case TypeCode.Single:
                         if (length > 1)
                             return (float[])GetContent(plc.ReadFloat(address, length), address);
                         else
                             return (float)GetContent(plc.ReadFloat(address), address);
+
                     case TypeCode.Boolean:
                         if (length > 1)
                             return (bool[])GetContent(plc.ReadBool(address, length), address);
                         else
                             return (bool)GetContent(plc.ReadBool(address), address);
+
                     case TypeCode.Byte:
                         if (length > 1)
                             return (byte)GetContent(plc.Read(address, length), address);
                         return (byte)GetContent(plc.ReadByte(address), address);
+
                     case TypeCode.String:
                         if (length > 1)
                             return (string)GetContent(plc.ReadString(address, length), address);
                         else
                             return (string)GetContent(plc.ReadString(address), address);
+
                     case TypeCode.Char:
                         if (length > 1)
                             return Encoding.Default.GetString((byte[])GetContent(plc.Read(address, length), address)).ToArray();
                         return (char)GetContent(plc.ReadByte(address), address);
+
                     default:
                         throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, typeCode.ToString(), address), CommunicationErrorType.TypeError);
                 }
@@ -374,14 +394,15 @@
                     }
                 }
             });
-
         }
+
         #endregion
 
         #region Public Method
-        /// <summary>  
+
+        /// <summary>
         /// 杩炴帴鍒癙LC銆�
-        /// </summary>  
+        /// </summary>
         /// <returns>濡傛灉杩炴帴鎴愬姛鍒欒繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse銆�</returns>
         /// <exception cref="CommunicationException">鑷畾涔夐�氳寮傚父绫�</exception>
         public override bool Connect()
@@ -414,10 +435,10 @@
             }
         }
 
-        /// <summary>  
-        /// 鏂紑涓庡伐涓氳澶囩殑杩炴帴銆�  
-        /// </summary>  
-        /// <returns>濡傛灉鎴愬姛鏂紑杩炴帴鍒欒繑鍥瀟rue锛屽鏋滃凡缁忔槸鏂紑鐘舵�佸垯杩斿洖false銆�</returns>  
+        /// <summary>
+        /// 鏂紑涓庡伐涓氳澶囩殑杩炴帴銆�
+        /// </summary>
+        /// <returns>濡傛灉鎴愬姛鏂紑杩炴帴鍒欒繑鍥瀟rue锛屽鏋滃凡缁忔槸鏂紑鐘舵�佸垯杩斿洖false銆�</returns>
         public override bool Disconnect()
         {
             try
@@ -440,12 +461,13 @@
         }
 
         #region Read
-        /// <summary>  
-        /// 浠嶱LC璇诲彇鏁版嵁銆�  
-        /// </summary>  
-        /// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>  
-        /// <param name="length">瑕佽鍙栫殑鏁版嵁闀垮害銆�</param>  
-        /// <returns>璇诲彇鍒扮殑鏁版嵁锛屽鏋滆鍙栧け璐ュ垯鍙兘杩斿洖null銆佺┖鏁扮粍鎴栨姏鍑鸿嚜瀹氫箟閫氳寮傚父銆�</returns>  
+
+        /// <summary>
+        /// 浠嶱LC璇诲彇鏁版嵁銆�
+        /// </summary>
+        /// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>
+        /// <param name="length">瑕佽鍙栫殑鏁版嵁闀垮害銆�</param>
+        /// <returns>璇诲彇鍒扮殑鏁版嵁锛屽鏋滆鍙栧け璐ュ垯鍙兘杩斿洖null銆佺┖鏁扮粍鎴栨姏鍑鸿嚜瀹氫箟閫氳寮傚父銆�</returns>
         /// <exception cref="CommunicationException">鑷畾涔夐�氳寮傚父绫�</exception>
         public override byte[] Read(string address, int length)
         {
@@ -467,7 +489,7 @@
         }
 
         /// <summary>
-        /// 
+        ///
         /// </summary>
         /// <typeparam name="T"></typeparam>
         /// <param name="address"></param>
@@ -493,9 +515,11 @@
             else
                 return Read(address, SiemensDBDataType.GetTypeCode(dataType));
         }
+
         #endregion
 
         #region Write
+
         /// <summary>
         /// 鍚慞LC鍐欏叆鏁版嵁銆�
         /// </summary>
@@ -526,7 +550,7 @@
         }
 
         /// <summary>
-        /// 
+        ///
         /// </summary>
         /// <typeparam name="T"></typeparam>
         /// <param name="address"></param>
@@ -537,7 +561,6 @@
         {
             return GetResult(Write(address, value), address, value);
         }
-
 
         public override bool Write<T>(string address, T[] values)
         {
@@ -571,6 +594,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_DW:
                     {
                         uint writeVal;
@@ -585,6 +609,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_Int:
                     {
                         short writeVal;
@@ -599,6 +624,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_W:
                     {
                         ushort writeVal;
@@ -613,6 +639,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_Float:
                     {
                         float writeVal;
@@ -627,6 +654,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_Bool:
                     {
                         bool writeVal;
@@ -641,6 +669,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_Byte:
                     {
                         byte writeVal;
@@ -655,6 +684,7 @@
                         obj = GetResult(Write(address, writeVal), address, writeVal);
                     }
                     break;
+
                 case SiemensDBDataType.DataType_String:
                     {
                         string writeVal;
@@ -670,17 +700,36 @@
                     }
 
                     break;
+
                 case SiemensDBDataType.DataType_Char:
 
                     break;
+
+                case SiemensDBDataType.DataType_ByteArray:
+                    {
+                        byte[] writeVal;
+                        try
+                        {
+                            writeVal = Encoding.UTF8.GetBytes(value.ToString());
+                        }
+                        catch (Exception ex)
+                        {
+                            throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex);
+                        }
+                        obj = GetResult(Write(address, writeVal), address, writeVal);
+                    }
+                    break;
+
                 default:
                     throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, dataType, address), CommunicationErrorType.TypeError);
             }
             return obj;
         }
+
         #endregion
 
         #region ReadCustomer
+
         /// <summary>
         /// 璇诲彇鑷畾涔夌殑鏁版嵁绫诲瀷锛岄渶瑕佺户鎵胯嚜IDataTransfer鎺ュ彛锛岃繑鍥炰竴涓柊鐨勭被鍨嬬殑瀹炰緥瀵硅薄銆�
         /// </summary>
@@ -699,9 +748,11 @@
                 throw new CommunicationException(ex.Message, CommunicationErrorType.ReadException, innerException: ex);
             }
         }
+
         #endregion
 
         #region WriteCustomer
+
         /// <summary>
         /// 鍐欏叆鑷畾涔夌被鍨嬬殑鏁版嵁锛岃绫诲瀷蹇呴』缁ф壙鑷狪DataTransfer鎺ュ彛銆�
         /// </summary>
@@ -768,6 +819,7 @@
                 LogNet.WriteInfo(Name, stringBuilder.ToString());
             }
         }
+
         #endregion
 
         /// <summary>
@@ -812,29 +864,36 @@
                 case TypeCode.Int16:
                     OperateResult<TimeSpan> operateResultShort = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout);
                     return operateResultShort;
+
                 case TypeCode.Int32:
                     OperateResult<TimeSpan> operateResultInt = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout);
                     return operateResultInt;
+
                 case TypeCode.UInt16:
                     OperateResult<TimeSpan> operateResultUShort = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout);
                     return operateResultUShort;
+
                 case TypeCode.UInt32:
                     OperateResult<TimeSpan> operateResultUInt = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout);
                     return operateResultUInt;
+
                 default:
                     throw new NotSupportedException();
             }
         }
+
         #endregion
 
         #region Destruction Function
+
         /// <summary>
-        /// 鏋愭瀯鍑芥暟锛岀‘淇濆湪涓嶅啀闇�瑕佹椂鍏抽棴杩炴帴  
+        /// 鏋愭瀯鍑芥暟锛岀‘淇濆湪涓嶅啀闇�瑕佹椂鍏抽棴杩炴帴
         /// </summary>
         ~SiemensS7()
         {
             Dispose();
         }
+
         #endregion
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3