From 885092869d8a27a0b77d6e55d3dd3f00f29e8002 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期四, 04 十二月 2025 15:45:48 +0800
Subject: [PATCH] 1
---
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs | 78 +++++++++++++++++++++++++++++++++-----
1 files changed, 67 insertions(+), 11 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs"
index 7f60bfc..6af06f5 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs"
@@ -70,6 +70,12 @@
private ILogNet _logNet;
private bool _isPing = true;
+
+ /// <summary>
+ /// 鏄惁鍦ㄥ啓鍏ユ暟鎹悗璇诲彇鏁版嵁纭銆�
+ /// </summary>
+ public override bool IsReadAfterWrite { get; set; } = true;
+
#endregion Private Member
#region Public Member
@@ -181,7 +187,8 @@
catch (Exception ex)
{
LogNet.WriteException(Name, ex.Message, ex);
- throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex);
+ //throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex);
+ return false;
}
finally
{
@@ -238,30 +245,48 @@
}
}
- private object Read(string address, TypeCode typeCode)
+ private object Read(string address, TypeCode typeCode, ushort length = 1)
{
try
{
switch (typeCode)
{
case TypeCode.Int32:
- return (int)GetContent(plc.ReadInt32(address), address);
+ if (length > 1)
+ return (int[])GetContent(plc.ReadInt32(address, length), address);
+ else
+ return (int)GetContent(plc.ReadInt32(address), address);
case TypeCode.UInt32:
- return (uint)GetContent(plc.ReadUInt32(address), address);
+ if (length > 1)
+ return (uint[])GetContent(plc.ReadUInt32(address, length), address);
+ else
+ return (uint)GetContent(plc.ReadUInt32(address), address);
case TypeCode.Int16:
- return (short)GetContent(plc.ReadInt16(address), address);
+ if (length > 1)
+ return (short[])GetContent(plc.ReadInt16(address, length), address);
+ else
+ return (short)GetContent(plc.ReadInt16(address), address);
case TypeCode.UInt16:
- return (ushort)GetContent(plc.ReadUInt16(address), address);
+ if (length > 1)
+ return (ushort[])GetContent(plc.ReadUInt16(address, length), address);
+ else
+ return (ushort)GetContent(plc.ReadUInt16(address), address);
case TypeCode.Single:
- return (float)GetContent(plc.ReadFloat(address), address);
+ if (length > 1)
+ return (float[])GetContent(plc.ReadFloat(address, length), address);
+ else
+ return (float)GetContent(plc.ReadFloat(address), address);
case TypeCode.Boolean:
- return (bool)GetContent(plc.ReadBool(address), address);
+ if (length > 1)
+ return (bool[])GetContent(plc.ReadBool(address, length), address);
+ else
+ return (bool)GetContent(plc.ReadBool(address), address);
case TypeCode.Byte:
- return (byte)GetContent(plc.ReadByte(address), address);
+ return (byte[])GetContent(plc.Read(address, length), address);
case TypeCode.String:
- return (string)GetContent(plc.ReadString(address), address);
+ return (string)GetContent(plc.ReadString(address, length), address);
case TypeCode.Char:
- return (char)GetContent(plc.ReadByte(address), address);
+ return (char[])GetContent(plc.Read(address, length), address);
default:
throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, typeCode.ToString(), address), CommunicationErrorType.TypeError);
}
@@ -390,6 +415,19 @@
}
/// <summary>
+ /// 浠嶱LC璇诲彇鏁版嵁銆�
+ /// </summary>
+ /// <typeparam name="T">璇诲彇鏁版嵁鐨勭被鍨嬫硾鍨嬨��</typeparam>
+ /// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>
+ /// <param name="length">璇诲彇鐨勯暱搴︺��</param>
+ /// <returns>璇诲彇鍒扮殑鏁版嵁锛屽鏋滆鍙栧け璐ュ垯鍙兘杩斿洖null鎴栨姏鍑哄紓甯搞��</returns>
+ public override T[] Read<T>(string address, ushort length)
+ {
+ Type type = typeof(T);
+ return (T[])Read(address, Type.GetTypeCode(type), length);
+ }
+
+ /// <summary>
/// 浠嶱LC璇诲彇鏁版嵁杩斿洖object銆�
/// </summary>
/// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>
@@ -446,6 +484,24 @@
}
/// <summary>
+ /// 鍚慞LC鍐欏叆鏁版嵁銆�
+ /// </summary>
+ /// <typeparam name="T">鍐欏叆鏁版嵁鐨勭被鍨嬫硾鍨嬨��</typeparam>
+ /// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>
+ /// <param name="values">瑕佸啓鍏ョ殑鏁版嵁銆�</param>
+ /// <returns>濡傛灉鍐欏叆鎴愬姛鍒欒繑鍥瀟rue锛屽惁鍒欐姏鍑哄紓甯搞��</returns>
+ public override bool Write<T>(string address, T[] values)
+ {
+ return GetResult(Write(address, values), address, values);
+ }
+
+ public override bool WriteNoRead<T>(string address, T value)
+ {
+ OperateResult operate= Write(address, value);
+ return operate.IsSuccess;
+ }
+
+ /// <summary>
/// 鍚慞LC鍐欏叆鏁版嵁銆�
/// </summary>
/// <param name="address">婧愬湴鍧�锛屽叿浣撴牸寮忓彇鍐充簬浣跨敤鐨勫伐涓氬崗璁��</param>
--
Gitblit v1.9.3