diff --git a/Modbus.Net/CrossLampControl.WebApi/Controllers/CrossLampController.cs b/Modbus.Net/CrossLampControl.WebApi/Controllers/CrossLampController.cs index da3e203..da28d9d 100644 --- a/Modbus.Net/CrossLampControl.WebApi/Controllers/CrossLampController.cs +++ b/Modbus.Net/CrossLampControl.WebApi/Controllers/CrossLampController.cs @@ -7,6 +7,7 @@ using System.Web.Http; using System.Web.Http.Routing; using CrossLampControl.WebApi.Models; using ModBus.Net; +using ModBus.Net.Simense; namespace CrossLampControl.WebApi.Controllers { diff --git a/Modbus.Net/ModBus.Net/AddressTranslator.cs b/Modbus.Net/ModBus.Net/AddressTranslator.cs index 83f583b..7187021 100644 --- a/Modbus.Net/ModBus.Net/AddressTranslator.cs +++ b/Modbus.Net/ModBus.Net/AddressTranslator.cs @@ -17,74 +17,6 @@ namespace ModBus.Net public abstract KeyValuePair AddressTranslate(string address, bool isRead); } - /// - /// NA200H数据单元翻译器 - /// - public class AddressTranslatorNA200H : AddressTranslator - { - protected Dictionary TransDictionary; - protected Dictionary ReadFunctionCodeDictionary; - protected Dictionary WriteFunctionCodeDictionary; - - public AddressTranslatorNA200H() - { - TransDictionary = new Dictionary - { - {"Q", 0}, - {"M", 10000}, - {"N", 20000}, - {"I", 0}, - {"S", 10000}, - {"IW", 0}, - {"SW", 5000}, - {"MW", 0}, - {"NW", 10000}, - {"QW", 20000}, - }; - ReadFunctionCodeDictionary = new Dictionary - { - {"Q", (int)ModbusProtocalReadDataFunctionCode.ReadCoilStatus}, - {"M", (int)ModbusProtocalReadDataFunctionCode.ReadCoilStatus}, - {"N", (int)ModbusProtocalReadDataFunctionCode.ReadCoilStatus}, - {"I", (int)ModbusProtocalReadDataFunctionCode.ReadInputStatus}, - {"S", (int)ModbusProtocalReadDataFunctionCode.ReadInputStatus}, - {"IW", (int)ModbusProtocalReadDataFunctionCode.ReadInputRegister}, - {"SW", (int)ModbusProtocalReadDataFunctionCode.ReadInputRegister}, - {"MW", (int)ModbusProtocalReadDataFunctionCode.ReadHoldRegister}, - {"NW", (int)ModbusProtocalReadDataFunctionCode.ReadHoldRegister}, - {"QW", (int)ModbusProtocalReadDataFunctionCode.ReadHoldRegister}, - }; - WriteFunctionCodeDictionary = new Dictionary - { - {"Q", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiCoil}, - {"M", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiCoil}, - {"N", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiCoil}, - {"MW", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiRegister}, - {"NW", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiRegister}, - {"QW", (int)ModbusProtocalWriteDataFunctionCode.WriteMultiRegister}, - }; - } - - public override KeyValuePair AddressTranslate(string address, bool isRead) - { - address = address.ToUpper(); - int i = 0; - int t; - while (!int.TryParse(address[i].ToString(), out t) && i < address.Length) - { - i++; - } - if (i == 0 || i >= address.Length) throw new FormatException(); - string head = address.Substring(0, i); - string tail = address.Substring(i); - return isRead - ? new KeyValuePair(TransDictionary[head] + int.Parse(tail) - 1, - ReadFunctionCodeDictionary[head]) - : new KeyValuePair(TransDictionary[head] + int.Parse(tail) - 1, - WriteFunctionCodeDictionary[head]); - } - } - /// /// 基本的单元转换器 /// @@ -102,54 +34,4 @@ namespace ModBus.Net throw new FormatException(); } } - - public class AddressTranslatorSimense : AddressTranslator - { - protected Dictionary AreaCodeDictionary; - - public AddressTranslatorSimense() - { - AreaCodeDictionary = new Dictionary - { - {"S", 0x04}, - {"SM", 0x05}, - {"AI", 0x06}, - {"AQ", 0x07}, - {"C", 0x1E}, - {"T", 0x1F}, - {"HC", 0x20}, - {"I", 0x81}, - {"Q", 0x82}, - {"M", 0x83}, - {"DB", 0x84}, - {"V", 0x184}, - }; - } - - public override KeyValuePair AddressTranslate(string address, bool isRead) - { - address = address.ToUpper(); - if (address.Substring(0,2) == "DB") - { - var addressSplit = address.Split('.'); - if (addressSplit.Length != 2) throw new FormatException(); - addressSplit[0] = addressSplit[0].Substring(2); - if (addressSplit[1].Substring(0, 2) == "DB") - addressSplit[1] = addressSplit[1].Substring(2); - return new KeyValuePair(int.Parse(addressSplit[1]), int.Parse(addressSplit[0]) * 256 + AreaCodeDictionary["DB"]); - } - int i = 0; - int t; - while (!int.TryParse(address[i].ToString(), out t) && i < address.Length) - { - i++; - } - if (i == 0 || i >= address.Length) throw new FormatException(); - string head = address.Substring(0, i); - string tail = address.Substring(i); - return - new KeyValuePair(int.Parse(tail), - AreaCodeDictionary[head]); - } - } } \ No newline at end of file diff --git a/Modbus.Net/ModBus.Net/ModBus.Net-xamarin.csproj b/Modbus.Net/ModBus.Net/ModBus.Net-xamarin.csproj index 53611ee..23a3ac3 100644 --- a/Modbus.Net/ModBus.Net/ModBus.Net-xamarin.csproj +++ b/Modbus.Net/ModBus.Net/ModBus.Net-xamarin.csproj @@ -1,4 +1,4 @@ - + Debug @@ -44,24 +44,9 @@ - - - - - - - - - - - - - - - @@ -71,9 +56,7 @@ - - - + diff --git a/Modbus.Net/ModBus.Net/ModBus.Net.csproj b/Modbus.Net/ModBus.Net/ModBus.Net.csproj index 1f99c71..e31f761 100644 --- a/Modbus.Net/ModBus.Net/ModBus.Net.csproj +++ b/Modbus.Net/ModBus.Net/ModBus.Net.csproj @@ -56,9 +56,10 @@ - - - + + + + True @@ -68,22 +69,23 @@ - - - + + + - - + + - - - - - - - + + + + + + + + Code @@ -97,6 +99,7 @@ ConfigurationManager.Designer.cs +