wanshenmean
6 天以前 37acb8358f5602a9013ee29c04a45e33483c2329
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/DeviceBase/DeviceCommand.cs
@@ -23,6 +23,7 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.LogHelper;
namespace WIDESEAWCS_QuartzJob.DeviceBase
{
@@ -160,17 +161,23 @@
                    case TypeCode.String:
                        ushort dataLength = CheckStringAttribute(propertyInfo);
                        //if (dataLength - 2 != Content[index])
                        //{
                        //    throw new Exception($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                        //}
                        if (dataLength - 2 != Content[index])
                        {
                            //throw new Exception($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                            //QuartzLogger.Debug($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                        //if (Content[index + 1] > Content.Length - index - 2)
                        //{
                        //    throw new Exception($"读取PLC字符串实际长度【{Content[index + 1]}】超出当前byte数组长度,索引:【{index}】,字符串起始索引:【{index + 2}】,数组长度:【{Content.Length}】,解析长度:【{Content.Length - index - 2}】");
                        //}
                            propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index, dataLength).Trim().Replace("\0", "").Replace("\\u000","").Trim());
                            index += dataLength;
                            break;
                        }
                        if (Content[index + 1] > Content.Length - index - 2)
                        {
                            throw new Exception($"读取PLC字符串实际长度【{Content[index + 1]}】超出当前byte数组长度,索引:【{index}】,字符串起始索引:【{index + 2}】,数组长度:【{Content.Length}】,解析长度:【{Content.Length - index - 2}】");
                        }
                        propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index + 2, Content[index + 1] > 0 ? Content[index + 1] : dataLength - 2));
                        //propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index, dataLength - 2));
                        index += dataLength;
                        break;
                    default: