From f142e86b68f5480f342442b1a4ae4c6a4fc3d912 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期二, 17 十二月 2024 09:08:12 +0800 Subject: [PATCH] 1 --- WIDESEAWCS_Server/WIDESEAWCS_Communicator/Omron/OmronEtherNetCommunicator.cs | 66 ++++++++++++++++++++++++++++++++- 1 files changed, 64 insertions(+), 2 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Omron/OmronEtherNetCommunicator.cs b/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Omron/OmronEtherNetCommunicator.cs index 3d2a1b4..52a1111 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Omron/OmronEtherNetCommunicator.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Omron/OmronEtherNetCommunicator.cs @@ -4,6 +4,7 @@ using HslCommunication.Profinet.Omron; using HslCommunication.Profinet.Siemens; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; @@ -18,7 +19,7 @@ namespace WIDESEAWCS_Communicator { /// <summary> - /// 瑗块棬瀛怱7閫氳绫� + /// 娆у榫橢therNet/IP(CIP) /// </summary> [Description("娆у榫橢therNet/IP(CIP)")] public class OmronEtherNetCommunicator : BaseCommunicator @@ -200,6 +201,38 @@ case TypeCode.Char: return plc.Write(address, Convert.ToChar(value)); default: + if (value is int[]) + { + return plc.Write(address, value as int[]); + } + else if (value is uint[]) + { + return plc.Write(address, value as uint[]); + } + else if (value is short[]) + { + return plc.Write(address, value as short[]); + } + else if (value is ushort[]) + { + return plc.Write(address, value as ushort[]); + } + else if (value is bool[]) + { + return plc.Write(address, value as bool[]); + } + else if (value is float[]) + { + return plc.Write(address, value as float[]); + } + else if (value is double[]) + { + return plc.Write(address, value as double[]); + } + else if (value is byte[]) + { + return plc.Write(address, value as byte[]); + } throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, type.Name, address), CommunicationErrorType.TypeError); } } @@ -214,29 +247,47 @@ } } - private object Read(string address, TypeCode typeCode) + private object Read(string address, TypeCode typeCode, ushort length = 1) { try { switch (typeCode) { case TypeCode.Int32: + if (length > 1) + return (int)GetContent(plc.ReadInt32(address, length), address); return (int)GetContent(plc.ReadInt32(address), address); case TypeCode.UInt32: + if (length > 1) + return (uint)GetContent(plc.ReadUInt32(address, length), address); return (uint)GetContent(plc.ReadUInt32(address), address); case TypeCode.Int16: + if (length > 1) + return (short)GetContent(plc.ReadInt16(address, length), address); return (short)GetContent(plc.ReadInt16(address), address); case TypeCode.UInt16: + if (length > 1) + return (ushort)GetContent(plc.ReadUInt16(address, length), address); return (ushort)GetContent(plc.ReadUInt16(address), address); case TypeCode.Single: + if (length > 1) + return (float)GetContent(plc.ReadFloat(address, length), address); return (float)GetContent(plc.ReadFloat(address), address); case TypeCode.Boolean: + if (length > 1) + return (bool)GetContent(plc.ReadBool(address, length), address); 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); return (string)GetContent(plc.ReadString(address), address); case TypeCode.Char: + if (length > 1) + return (char)GetContent(plc.Read(address, length), address); return (char)GetContent(plc.ReadByte(address), address); default: throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, typeCode.ToString(), address), CommunicationErrorType.TypeError); @@ -347,6 +398,12 @@ return (T)Read(address, Type.GetTypeCode(type)); } + public override T[] Read<T>(string address, ushort length) + { + Type type = typeof(T); + return (T[])Read(address, Type.GetTypeCode(type), length); + } + public override object ReadAsObj(string address, string dataType) { return Read(address, SiemensDBDataType.GetTypeCode(dataType)); @@ -428,6 +485,11 @@ return GetResult(Write(address, value), address, value); } + public override bool Write<T>(string address, T[] values) + { + return GetResult(Write(address, values), address, values); + } + public override bool WriteCustomer<T>(string address, [NotNull] T value) { StringBuilder stringBuilder = new StringBuilder(); -- Gitblit v1.9.3