From ca479803a22cbc0c5ff2abd1410aebdf56f7dd2d Mon Sep 17 00:00:00 2001 From: "parallelbgls@outlook.com" Date: Sat, 10 Oct 2015 11:35:04 +0800 Subject: [PATCH] 2015-10-10 update 1 add two lost file --- .../Modbus/AddressFormaterModbus.cs | 16 ++++++ .../Simense/AddressTranslatorSimense.cs | 56 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Modbus.Net/ModBus.Net/Modbus/AddressFormaterModbus.cs create mode 100644 Modbus.Net/ModBus.Net/Simense/AddressTranslatorSimense.cs diff --git a/Modbus.Net/ModBus.Net/Modbus/AddressFormaterModbus.cs b/Modbus.Net/ModBus.Net/Modbus/AddressFormaterModbus.cs new file mode 100644 index 0000000..6485ed6 --- /dev/null +++ b/Modbus.Net/ModBus.Net/Modbus/AddressFormaterModbus.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ModBus.Net.Modbus +{ + public class AddressFormaterNA200H : AddressFormater + { + public override string FormatAddress(string area, int address) + { + return area + address; + } + } +} diff --git a/Modbus.Net/ModBus.Net/Simense/AddressTranslatorSimense.cs b/Modbus.Net/ModBus.Net/Simense/AddressTranslatorSimense.cs new file mode 100644 index 0000000..c0bb7e0 --- /dev/null +++ b/Modbus.Net/ModBus.Net/Simense/AddressTranslatorSimense.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace ModBus.Net.Simense +{ + 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