This commit is contained in:
parallelbgls
2025-05-21 12:04:12 +08:00
parent 62e6fcbfb1
commit 51ded333d9
4 changed files with 27 additions and 12 deletions

View File

@@ -28,9 +28,9 @@ namespace Modbus.Net
/// <summary>
/// 是否为大端
/// </summary>
protected new bool LittleEndian => false;
public override bool LittleEndian => true;
protected new bool LittleEndianBit => false;
public override bool LittleEndianBit => false;
/// <summary>
/// 覆盖的获取实例的方法
@@ -154,9 +154,9 @@ namespace Modbus.Net
/// <summary>
/// 是否为大端
/// </summary>
protected new bool LittleEndian => true;
public override bool LittleEndian => true;
protected new bool LittleEndianBit => false;
public override bool LittleEndianBit => true;
/// <summary>
/// 覆盖的获取实例的方法

View File

@@ -12,6 +12,16 @@ namespace Modbus.Net
/// </summary>
public abstract class ValueHelper
{
/// <summary>
/// 是否为小端格式
/// </summary>
public abstract bool LittleEndian { get; }
/// <summary>
/// 位是否为小端格式
/// </summary>
public abstract bool LittleEndianBit { get; }
/// <summary>
/// 兼容数据类型对应的字节长度
/// </summary>
@@ -347,12 +357,12 @@ namespace Modbus.Net
/// <summary>
/// 协议中的内容构造是否小端的,默认是小端构造协议。
/// </summary>
public static bool LittleEndian => true;
public override bool LittleEndian => true;
/// <summary>
/// 协议中的比特位内容构造是否小端的,默认是小端构造协议。
/// </summary>
public static bool LittleEndianBit => true;
public override bool LittleEndianBit => true;
/// <summary>
/// 将一个byte数字转换为一个byte元素的数组。
@@ -1228,7 +1238,7 @@ namespace Modbus.Net
/// <summary>
/// 是否为大端
/// </summary>
protected new bool LittleEndian => false;
public override bool LittleEndian => false;
/// <summary>
/// 覆盖的获取实例的方法
@@ -1471,12 +1481,12 @@ namespace Modbus.Net
/// <summary>
/// 是否为小端
/// </summary>
protected new bool LittleEndian => false;
public override bool LittleEndian => false;
/// <summary>
/// 是否为小端位
/// </summary>
protected new bool LittleEndianBit => false;
public override bool LittleEndianBit => false;
/// <summary>
/// 覆盖的实例获取方法

View File

@@ -149,6 +149,10 @@ namespace Modbus.Net
var localMainPos = (int)localPos;
//字节坐标的子地址位置
var localSubPos = (int)((localPos - localMainPos) * 8);
if (ValueHelper.GetInstance(BaseUtility.Endian).LittleEndianBit == true && AddressTranslator.GetAreaByteLength(communicateAddress.Area) > 1 && ValueHelper.ByteLength[address.DataType.FullName] < AddressTranslator.GetAreaByteLength(communicateAddress.Area))
{
localMainPos =(int)(2 * ((int)(localMainPos / AddressTranslator.GetAreaByteLength(communicateAddress.Area)) * AddressTranslator.GetAreaByteLength(communicateAddress.Area)) + (AddressTranslator.GetAreaByteLength(communicateAddress.Area) - 1) - localMainPos);
}
//根据类型选择返回结果的键是通讯标识还是地址
string key;

View File

@@ -3,7 +3,7 @@
"TCP": {
"ConnectionTimeout": "5000",
"FetchSleepTime": "100",
"FullDuplex": "False",
"FullDuplex": "True",
"Modbus": {
"ModbusPort": "502",
"IP": "192.168.1.1"
@@ -16,7 +16,7 @@
"UDP": {
"ConnectionTimeout": "5000",
"FetchSleepTime": "100",
"FullDuplex": "False",
"FullDuplex": "True",
"Modbus": {
"ModbusPort": "502",
"IP": "192.168.1.1"
@@ -46,7 +46,8 @@
"Host": "opc.tcp://localhost/test"
},
"Controller": {
"WaitingListCount": "100"
"WaitingListCount": "100",
"NoResponse": false
}
}
}