From 96fd7a1ee919603f0ca70976c0cf095203f8a532 Mon Sep 17 00:00:00 2001 From: Dai Mr <1822802785@qq.com> Date: Fri, 8 Nov 2024 09:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/StringExtensions.cs | 12 ++++ .../Abstracts/BaseProtocolPlugin.cs | 55 +++++++++++++------ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/JiShe.CollectBus.Common/Extensions/StringExtensions.cs b/JiShe.CollectBus.Common/Extensions/StringExtensions.cs index 3653956..fee56f9 100644 --- a/JiShe.CollectBus.Common/Extensions/StringExtensions.cs +++ b/JiShe.CollectBus.Common/Extensions/StringExtensions.cs @@ -1196,6 +1196,18 @@ namespace JiShe.CollectBus.Common.Extensions return string.Join(" ", strArr); } + /// + /// 判断数据是否有误 + /// + /// + /// + public static bool IsEE(this string str) + { + if (str == "EE") + return true; + return false; + } + private static string AddHex33(this string strGet) { string result; diff --git a/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs index 2f7f619..92b2c33 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs @@ -21,6 +21,8 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts public const int tPLen = 6; + public const string errorData = "EE"; + public abstract Task GetAsync(); @@ -291,7 +293,6 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts //当前B相视在功率:Error: 数据不符合BCD码格式 kVA EE EE EE //当前C相视在功率:Error: 数据不符合BCD码格式 kVA EE EE EE //++++++++++++++++++++++++++++++++++++ - /// /// 当前三相及总有/无功功率、功率因数、三相电压、电流、零序电流、视在功率 /// @@ -386,6 +387,10 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// private decimal AnalysisA05(string singleDigitNumberAndDeciles, string hundredDigitNumbersAndTenDigitNumber) { + if (singleDigitNumberAndDeciles.IsEE() && hundredDigitNumbersAndTenDigitNumber.IsEE()) + { + return 0; + } var bin1 = hundredDigitNumbersAndTenDigitNumber.HexToBin().PadLeft(8, '0'); var hundredDigitNumbers = bin1.Substring(1, 3).BinToDec();//百位 var tenDigitNumber = bin1.Substring(4).BinToDec();//十位 @@ -406,6 +411,10 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// private decimal AnalysisA07(string singleDigitNumberAndDeciles,string hundredDigitNumbersAndTenDigitNumber) { + if (singleDigitNumberAndDeciles.IsEE() && hundredDigitNumbersAndTenDigitNumber.IsEE()) + { + return 0; + } var bin1 = hundredDigitNumbersAndTenDigitNumber.HexToBin().PadLeft(8, '0'); var hundredDigitNumbers = bin1.Substring(1, 3).BinToDec();//百位 var tenDigitNumber = bin1.Substring(4).BinToDec();//十位 @@ -427,6 +436,11 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// private decimal AnalysisA09(string thousandthPercentileAndTenThousandPositions, string decilesAndPercentile, string tenAndSingleDigit) { + if (thousandthPercentileAndTenThousandPositions.IsEE() && decilesAndPercentile.IsEE() && tenAndSingleDigit.IsEE()) + { + return 0; + } + var bin3 = tenAndSingleDigit.HexToBin().PadLeft(8, '0'); var tenDigitNumber = bin3.Substring(1, 3).BinToDec();//十位 var singleDigitNumber = bin3.Substring(4).BinToDec();//个位 @@ -448,19 +462,18 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// /// 数据格式12 TODO:待优化 /// - /// 十位 个位 - /// 千位 百位 - /// 十万位 万位 - /// 千万位 百万位 - /// 十亿位 亿位 - /// 千亿位 百亿位 + /// 十位 个位 + /// 千位 百位 + /// 十万位 万位 + /// 千万位 百万位 + /// 十亿位 亿位 + /// 千亿位 百亿位 /// - private string AnalysisA12(string tenDigitNumberAndSingleDigitNumber, string hundredsOfPositionAndThousandOfPosition, string hundredThousandOfPositionAndTenThousandOfPosition, - string millionsOfPositionAndMillionOfPosition, string billionOfPositionAndHundredMillionOfPosition, string hundredBillionsOfPositionAndBillionsOfPosition) - { - - var value = $"{hundredBillionsOfPositionAndBillionsOfPosition}{billionOfPositionAndHundredMillionOfPosition}{millionsOfPositionAndMillionOfPosition}" + - $"{hundredThousandOfPositionAndTenThousandOfPosition}{hundredsOfPositionAndThousandOfPosition}{tenDigitNumberAndSingleDigitNumber}"; + private string AnalysisA12(string tenDigitAndSingleDigitNumber, string thousandAndHundredsOfPosition, string hundredThousandAndTenThousandOfPosition, + string millionsAndMillionOfPosition, string hundredMillionAndBillionOfPosition, string hundredBillionsAndBillionsOfPosition) + { + var value = $"{hundredBillionsAndBillionsOfPosition}{hundredMillionAndBillionOfPosition}{millionsAndMillionOfPosition}" + + $"{hundredThousandAndTenThousandOfPosition}{thousandAndHundredsOfPosition}{tenDigitAndSingleDigitNumber}"; return value; } @@ -471,14 +484,17 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts /// 千分,万分 /// 十分、百分 /// 十位、个位 - /// 千位、百位 - /// 十万位、万位 + /// 千位、百位 + /// 十万位、万位 /// private decimal AnalysisA14(string tenThousandPositionsAndThousandthPercentile, string decilesAndPercentile, - string tenDigitNumberAndSingleDigitNumber, string thousandOfPositionAndHundredsOfPosition, string hundredThousandOfPositionAndTenThousandOfPosition) + string tenDigitNumberAndSingleDigitNumber, string thousandAndHundredsOfPosition, string hundredThousandAndTenThousandOfPosition) { - - var value = decimal.Parse($"{hundredThousandOfPositionAndTenThousandOfPosition}{thousandOfPositionAndHundredsOfPosition}" + + if (tenThousandPositionsAndThousandthPercentile.IsEE() && decilesAndPercentile.IsEE() && tenDigitNumberAndSingleDigitNumber.IsEE() + && thousandAndHundredsOfPosition.IsEE() && hundredThousandAndTenThousandOfPosition.IsEE()) + return 0; + + var value = decimal.Parse($"{hundredThousandAndTenThousandOfPosition}{thousandAndHundredsOfPosition}" + $"{tenDigitNumberAndSingleDigitNumber}.{decilesAndPercentile}{tenThousandPositionsAndThousandthPercentile}"); return value; @@ -561,6 +577,9 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts private decimal AnalysisA25(string percentileAndThousandthPercentile,string singleDigitNumberAndDeciles, string hundredDigitNumbersAndTenDigitNumber) { + if (percentileAndThousandthPercentile.IsEE() && singleDigitNumberAndDeciles.IsEE() && hundredDigitNumbersAndTenDigitNumber.IsEE()) + return 0; + var bin1 = hundredDigitNumbersAndTenDigitNumber.HexToBin().PadLeft(8, '0'); var hundredDigitNumbers = bin1.Substring(1, 3).BinToDec();//百位 var tenDigitNumber = bin1.Substring(4).BinToDec();//十位