From 1ee85d89926ad1b97bbad0d6850d0ac782c86d23 Mon Sep 17 00:00:00 2001 From: "parallelbgls@outlook.com" Date: Wed, 29 Apr 2015 15:43:34 +0800 Subject: [PATCH] 2015-04-29 update 2 change a interface in SimenseUtility --- Modbus.Net/ModBus.Net/BaseUtility.cs | 2 +- Modbus.Net/ModBus.Net/SimenseMachine.cs | 8 +-- Modbus.Net/ModBus.Net/SimenseUtility.cs | 76 ++++++++++++------------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/Modbus.Net/ModBus.Net/BaseUtility.cs b/Modbus.Net/ModBus.Net/BaseUtility.cs index 8c24bde..f303607 100644 --- a/Modbus.Net/ModBus.Net/BaseUtility.cs +++ b/Modbus.Net/ModBus.Net/BaseUtility.cs @@ -13,7 +13,7 @@ namespace ModBus.Net /// 协议收发主体 /// protected BaseProtocal Wrapper; - protected virtual string ConnectionString { get; set; } + protected string ConnectionString { get; set; } public bool IsConnected { diff --git a/Modbus.Net/ModBus.Net/SimenseMachine.cs b/Modbus.Net/ModBus.Net/SimenseMachine.cs index ad9df97..67d9772 100644 --- a/Modbus.Net/ModBus.Net/SimenseMachine.cs +++ b/Modbus.Net/ModBus.Net/SimenseMachine.cs @@ -8,17 +8,17 @@ namespace ModBus.Net { public class SimenseMachine : BaseMachine { - public SimenseMachine(SimenseType connectionType, string connectionString, + public SimenseMachine(SimenseType connectionType, string connectionString, SimenseMachineModel model, IEnumerable getAddresses, bool keepConnect) : base(getAddresses, keepConnect) { - BaseUtility = new SimenseUtility(connectionType, connectionString); + BaseUtility = new SimenseUtility(connectionType, connectionString, model); AddressFormater = new AddressFormaterSimense(); AddressCombiner = new AddressCombinerContinus(); } - public SimenseMachine(SimenseType connectionType, string connectionString, + public SimenseMachine(SimenseType connectionType, string connectionString, SimenseMachineModel model, IEnumerable getAddresses) - : this(connectionType, connectionString, getAddresses, false) + : this(connectionType, connectionString, model, getAddresses, false) { } } diff --git a/Modbus.Net/ModBus.Net/SimenseUtility.cs b/Modbus.Net/ModBus.Net/SimenseUtility.cs index 411c31c..daab74e 100644 --- a/Modbus.Net/ModBus.Net/SimenseUtility.cs +++ b/Modbus.Net/ModBus.Net/SimenseUtility.cs @@ -9,48 +9,22 @@ public enum SimenseType Ppi = 0, Mpi = 1, Tcp = 2 -} +}; + +public enum SimenseMachineModel +{ + S7_200 = 0, + S7_200_Smart = 1, + S7_300 = 2, + S7_400 = 3, + S7_1200 = 4, + S7_1500 = 5 +}; namespace ModBus.Net { public class SimenseUtility : BaseUtility { - private string _connectionString; - - protected override string ConnectionString - { - get { return _connectionString; } - set - { - string[] splitStrings = value.Split(','); - switch (splitStrings[1]) - { - case "200": - { - _tdpuSize = 0x09; - _taspSrc = 0x1001; - _tsapDst = 0x1000; - _maxCalling = 0x0001; - _maxCalled = 0x0001; - _maxPdu = 0x03c0; - break; - } - case "300": - case "400": - { - _tdpuSize = 0x1a; - _taspSrc = 0x4b54; - _tsapDst = 0x0302; - _maxCalling = 0x0001; - _maxCalled = 0x0001; - _maxPdu = 0x00f0; - break; - } - } - _connectionString = splitStrings[0]; - } - } - private byte _tdpuSize; private ushort _taspSrc; private ushort _tsapDst; @@ -88,11 +62,35 @@ namespace ModBus.Net } } - public SimenseUtility(SimenseType connectionType, string connectionString) + public SimenseUtility(SimenseType connectionType, string connectionString, SimenseMachineModel model) { ConnectionString = connectionString; + switch (model) + { + case SimenseMachineModel.S7_200: + { + _tdpuSize = 0x09; + _taspSrc = 0x1001; + _tsapDst = 0x1000; + _maxCalling = 0x0001; + _maxCalled = 0x0001; + _maxPdu = 0x03c0; + break; + } + case SimenseMachineModel.S7_300: + case SimenseMachineModel.S7_400: + { + _tdpuSize = 0x1a; + _taspSrc = 0x4b54; + _tsapDst = 0x0302; + _maxCalling = 0x0001; + _maxCalled = 0x0001; + _maxPdu = 0x00f0; + break; + } + } ConnectionType = connectionType; - AddressTranslator = new AddressTranslatorSimense(); + AddressTranslator = new AddressTranslatorSimense(); } public override void SetConnectionType(int connectionType)