Add GetBit (SubAddress and typeof(bool)) Support

This commit is contained in:
罗圣
2016-08-29 17:15:29 +08:00
parent c5e7f36e59
commit e1cb42a499
9 changed files with 106 additions and 66 deletions

View File

@@ -12,6 +12,11 @@ namespace Modbus.Net.Modbus
{
return area + " " + address;
}
public override string FormatAddress(string area, int address, int subAddress)
{
return area + " " + address + "." + subAddress;
}
}
public class AddressFormaterModbus : AddressFormater
@@ -20,5 +25,10 @@ namespace Modbus.Net.Modbus
{
return area + " " + address;
}
public override string FormatAddress(string area, int address, int subAddress)
{
return area + " " + address + "." + subAddress;
}
}
}

View File

@@ -60,16 +60,29 @@ namespace Modbus.Net.Modbus
string[] splitString = address.Split(' ');
string head = splitString[0];
string tail = splitString[1];
string sub;
if (tail.Contains('.'))
{
string[] splitString2 = tail.Split('.');
sub = splitString2[1];
tail = splitString2[0];
}
else
{
sub = "0";
}
return isRead
? new AddressDef()
{
Area = ReadFunctionCodeDictionary[head].Code,
Address = TransDictionary[head] + int.Parse(tail) - 1,
SubAddress = int.Parse(sub),
}
: new AddressDef()
{
Area = WriteFunctionCodeDictionary[head].Code,
Address = TransDictionary[head] + int.Parse(tail) - 1,
SubAddress = int.Parse(sub),
};
}
@@ -109,16 +122,29 @@ namespace Modbus.Net.Modbus
string[] splitString = address.Split(' ');
string head = splitString[0];
string tail = splitString[1];
string sub;
if (tail.Contains('.'))
{
string[] splitString2 = tail.Split('.');
sub = splitString2[1];
tail = splitString2[0];
}
else
{
sub = "0";
}
return isRead
? new AddressDef()
{
Area = ReadFunctionCodeDictionary[head].Code,
Address = int.Parse(tail) - 1,
SubAddress = int.Parse(sub),
}
: new AddressDef()
{
Area = WriteFunctionCodeDictionary[head].Code,
Address = int.Parse(tail) - 1,
SubAddress = int.Parse(sub),
};
}