更新20260529
This commit is contained in:
@@ -12,6 +12,7 @@ public sealed class ModbusRtuScaleService : IScaleService
|
||||
private const int ExpectedDataByteCount = 4;
|
||||
private const double MinimumMass = 0;
|
||||
private const double MaximumMass = 100000;
|
||||
private const ushort CdabFloatRegisterStart = 0x200;
|
||||
private static readonly TimeSpan ReadWriteTimeout = TimeSpan.FromMilliseconds(1000);
|
||||
|
||||
private readonly object _syncRoot = new();
|
||||
@@ -42,7 +43,7 @@ public sealed class ModbusRtuScaleService : IScaleService
|
||||
WriteReadRequest(port);
|
||||
var response = ReadResponse(port);
|
||||
|
||||
if (!TryDecodeCurrentMass(response, _options.UnitId, out value))
|
||||
if (!TryDecodeCurrentMass(response, _options.UnitId, GetFloatByteOrder(), out value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -70,6 +71,13 @@ public sealed class ModbusRtuScaleService : IScaleService
|
||||
}
|
||||
}
|
||||
|
||||
private ModbusFloatByteOrder GetFloatByteOrder()
|
||||
{
|
||||
return _options.RegisterAddress >= CdabFloatRegisterStart
|
||||
? ModbusFloatByteOrder.Cdab
|
||||
: ModbusFloatByteOrder.Abcd;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
@@ -194,7 +202,11 @@ public sealed class ModbusRtuScaleService : IScaleService
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryDecodeCurrentMass(byte[] response, byte unitId, out double value)
|
||||
private static bool TryDecodeCurrentMass(
|
||||
byte[] response,
|
||||
byte unitId,
|
||||
ModbusFloatByteOrder byteOrder,
|
||||
out double value)
|
||||
{
|
||||
value = double.NaN;
|
||||
|
||||
@@ -207,15 +219,17 @@ public sealed class ModbusRtuScaleService : IScaleService
|
||||
}
|
||||
|
||||
var result = new ModbusFloatReadResult(response[3], response[4], response[5], response[6]);
|
||||
var candidate = result.Abcd;
|
||||
var candidate = result.GetValue(byteOrder);
|
||||
if (!ModbusFloatSelector.IsInRange(candidate, MinimumMass, MaximumMass))
|
||||
{
|
||||
Debug.WriteLine(
|
||||
$"Scale mass out of range raw [{result.RawHex}], ABCD={result.Abcd:G9}, "
|
||||
$"Scale mass out of range raw [{result.RawHex}], selected={byteOrder}, "
|
||||
+ $"ABCD={result.Abcd:G9}, "
|
||||
+ $"CDAB={result.Cdab:G9}, BADC={result.Badc:G9}, DCBA={result.Dcba:G9}.");
|
||||
Log.Warning(
|
||||
"Scale mass out of range. Raw={RawHex}, ABCD={Abcd}, CDAB={Cdab}, BADC={Badc}, DCBA={Dcba}, Range={MinimumMass}..{MaximumMass}.",
|
||||
"Scale mass out of range. Raw={RawHex}, SelectedByteOrder={SelectedByteOrder}, ABCD={Abcd}, CDAB={Cdab}, BADC={Badc}, DCBA={Dcba}, Range={MinimumMass}..{MaximumMass}.",
|
||||
result.RawHex,
|
||||
byteOrder,
|
||||
result.Abcd,
|
||||
result.Cdab,
|
||||
result.Badc,
|
||||
|
||||
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_02.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 KiB |
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_04.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_04.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 250 KiB |
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_08.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_08.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_09.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_09.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 224 KiB |
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_11.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_11.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_12.png
Normal file
BIN
ConeCalorimeter/tmp/pdfs/mh_awc_pages/page_12.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 330 KiB |
Reference in New Issue
Block a user