From 470f736079226683395fda432c19572ddcd33137 Mon Sep 17 00:00:00 2001 From: Federico Barresi Date: Fri, 5 Jun 2020 17:19:30 +0200 Subject: [PATCH] added enums and methods overloads for S7Wordlength and S7Area fix #11 --- Sharp7/S7.cs | 1 + Sharp7/S7Area.cs | 12 ++++++++++++ Sharp7/S7Client.cs | 20 ++++++++++++++++++++ Sharp7/S7Consts.cs | 32 ++++++++++++++++---------------- Sharp7/S7MultiVar.cs | 1 + Sharp7/S7WordLength.cs | 16 ++++++++++++++++ 6 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 Sharp7/S7Area.cs create mode 100644 Sharp7/S7WordLength.cs diff --git a/Sharp7/S7.cs b/Sharp7/S7.cs index 0f30989..dce8a82 100644 --- a/Sharp7/S7.cs +++ b/Sharp7/S7.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +#pragma warning disable 618 namespace Sharp7 { diff --git a/Sharp7/S7Area.cs b/Sharp7/S7Area.cs new file mode 100644 index 0000000..c27b93d --- /dev/null +++ b/Sharp7/S7Area.cs @@ -0,0 +1,12 @@ +namespace Sharp7 +{ + public enum S7Area + { + PE = 0x81, + PA = 0x82, + MK = 0x83, + DB = 0x84, + CT = 0x1C, + TM = 0x1D, + } +} \ No newline at end of file diff --git a/Sharp7/S7Client.cs b/Sharp7/S7Client.cs index 16e1deb..9215011 100644 --- a/Sharp7/S7Client.cs +++ b/Sharp7/S7Client.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Runtime.InteropServices; +#pragma warning disable 618 namespace Sharp7 { @@ -819,6 +820,15 @@ namespace Sharp7 #region [Data I/O main functions] + public int ReadArea(S7Area Area, int DBNumber, int Start, int Amount, S7WordLength WordLen, byte[] Buffer) + { + return ReadArea((int)Area, DBNumber, Start, Amount, (int)WordLen, Buffer); + } + + public int ReadArea(S7Area Area, int DBNumber, int Start, int Amount, S7WordLength WordLen, byte[] Buffer, ref int BytesRead) + { + return ReadArea((int)Area, DBNumber, Start, Amount, (int)WordLen, Buffer, ref BytesRead); + } public int ReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, byte[] Buffer) { int BytesRead = 0; @@ -934,6 +944,16 @@ namespace Sharp7 return _LastError; } + public int WriteArea(S7Area Area, int DBNumber, int Start, int Amount, S7WordLength WordLen, byte[] Buffer) + { + int BytesWritten = 0; + return WriteArea((int) Area, DBNumber, Start, Amount, (int) WordLen, Buffer, ref BytesWritten); + } + + public int WriteArea(S7Area Area, int DBNumber, int Start, int Amount, S7WordLength WordLen, byte[] Buffer, ref int BytesWritten) + { + return WriteArea((int) Area, DBNumber, Start, Amount, (int) WordLen, Buffer, ref BytesWritten); + } public int WriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, byte[] Buffer) { int BytesWritten = 0; diff --git a/Sharp7/S7Consts.cs b/Sharp7/S7Consts.cs index 6116bc2..0a4a5b5 100644 --- a/Sharp7/S7Consts.cs +++ b/Sharp7/S7Consts.cs @@ -81,23 +81,23 @@ namespace Sharp7 public const Int32 p_u32_RecoveryTime = 14; // Not applicable here public const Int32 p_u32_KeepAliveTime = 15; // Not applicable here // Area ID - public const byte S7AreaPE = 0x81; - public const byte S7AreaPA = 0x82; - public const byte S7AreaMK = 0x83; - public const byte S7AreaDB = 0x84; - public const byte S7AreaCT = 0x1C; - public const byte S7AreaTM = 0x1D; + [Obsolete("Use enum S7Area.PE instead")]public const byte S7AreaPE = 0x81; + [Obsolete("Use enum S7Area.PA instead")]public const byte S7AreaPA = 0x82; + [Obsolete("Use enum S7Area.MK instead")]public const byte S7AreaMK = 0x83; + [Obsolete("Use enum S7Area.DB instead")]public const byte S7AreaDB = 0x84; + [Obsolete("Use enum S7Area.CT instead")]public const byte S7AreaCT = 0x1C; + [Obsolete("Use enum S7Area.TM instead")]public const byte S7AreaTM = 0x1D; // Word Length - public const int S7WLBit = 0x01; - public const int S7WLByte = 0x02; - public const int S7WLChar = 0x03; - public const int S7WLWord = 0x04; - public const int S7WLInt = 0x05; - public const int S7WLDWord = 0x06; - public const int S7WLDInt = 0x07; - public const int S7WLReal = 0x08; - public const int S7WLCounter = 0x1C; - public const int S7WLTimer = 0x1D; + [Obsolete("Use enum S7WordLength.Bit instead")]public const int S7WLBit = 0x01; + [Obsolete("Use enum S7WordLength.Byte instead")]public const int S7WLByte = 0x02; + [Obsolete("Use enum S7WordLength.Char instead")]public const int S7WLChar = 0x03; + [Obsolete("Use enum S7WordLength.Word instead")]public const int S7WLWord = 0x04; + [Obsolete("Use enum S7WordLength.Int instead")]public const int S7WLInt = 0x05; + [Obsolete("Use enum S7WordLength.DWord instead")]public const int S7WLDWord = 0x06; + [Obsolete("Use enum S7WordLength.DInt instead")]public const int S7WLDInt = 0x07; + [Obsolete("Use enum S7WordLength.Real instead")]public const int S7WLReal = 0x08; + [Obsolete("Use enum S7WordLength.Counter instead")]public const int S7WLCounter = 0x1C; + [Obsolete("Use enum S7WordLength.Timer instead")]public const int S7WLTimer = 0x1D; // PLC Status public const int S7CpuStatusUnknown = 0x00; public const int S7CpuStatusRun = 0x08; diff --git a/Sharp7/S7MultiVar.cs b/Sharp7/S7MultiVar.cs index d0c804d..717ee61 100644 --- a/Sharp7/S7MultiVar.cs +++ b/Sharp7/S7MultiVar.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Runtime.InteropServices; +#pragma warning disable 618 namespace Sharp7 { diff --git a/Sharp7/S7WordLength.cs b/Sharp7/S7WordLength.cs new file mode 100644 index 0000000..ed9b6da --- /dev/null +++ b/Sharp7/S7WordLength.cs @@ -0,0 +1,16 @@ +namespace Sharp7 +{ + public enum S7WordLength + { + Bit = 0x01, + Byte = 0x02, + Char = 0x03, + Word = 0x04, + Int = 0x05, + DWord = 0x06, + DInt = 0x07, + Real = 0x08, + Counter = 0x1C, + Timer = 0x1D, + } +} \ No newline at end of file