From 710ab2e026ed86af697d8d3e21a9f1b14a5f0dd3 Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:34:41 +0200 Subject: [PATCH 1/8] Provide a buffer to MemoryStream NetStandard 1.3 doesn't expose .GetBuffer(), this removes the need for having it. The support for messages that span TPKT's is quite nasty, but probably S7 PLC's will never even use a message spanning multiple TPKT's. --- S7.Net/COTP.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/S7.Net/COTP.cs b/S7.Net/COTP.cs index 0781709..dea9f06 100644 --- a/S7.Net/COTP.cs +++ b/S7.Net/COTP.cs @@ -98,15 +98,20 @@ namespace S7.Net var segment = TPDU.Read(stream); if (segment == null) return null; - var output = new MemoryStream(segment.Data.Length); + var buffer = new byte[segment.Data.Length]; + var output = new MemoryStream(buffer); output.Write(segment.Data, 0, segment.Data.Length); while (!segment.LastDataUnit) { segment = TPDU.Read(stream); - output.Write(segment.Data, (int)output.Position, segment.Data.Length); + Array.Resize(ref buffer, buffer.Length + segment.Data.Length); + var lastPosition = output.Position; + output = new MemoryStream(buffer); + output.Write(segment.Data, (int) lastPosition, segment.Data.Length); } - return output.GetBuffer().Take((int)output.Position).ToArray(); + + return buffer.Take((int)output.Position).ToArray(); } /// @@ -120,15 +125,19 @@ namespace S7.Net var segment = await TPDU.ReadAsync(stream); if (segment == null) return null; - var output = new MemoryStream(segment.Data.Length); + var buffer = new byte[segment.Data.Length]; + var output = new MemoryStream(buffer); output.Write(segment.Data, 0, segment.Data.Length); while (!segment.LastDataUnit) { segment = await TPDU.ReadAsync(stream); - output.Write(segment.Data, (int)output.Position, segment.Data.Length); + Array.Resize(ref buffer, buffer.Length + segment.Data.Length); + var lastPosition = output.Position; + output = new MemoryStream(buffer); + output.Write(segment.Data, (int) lastPosition, segment.Data.Length); } - return output.GetBuffer().Take((int)output.Position).ToArray(); + return buffer.Take((int)output.Position).ToArray(); } } } From e516675a70e0e7366c0448585ed53821606a3bb1 Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:36:49 +0200 Subject: [PATCH 2/8] Replace InvalidEnumArgumentException usage InvalidEnumArgumentException is not supported in NetStandard 1.3. --- S7.Net/PLC.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs index 2bba5e4..e8ddc1c 100644 --- a/S7.Net/PLC.cs +++ b/S7.Net/PLC.cs @@ -2,7 +2,6 @@ using S7.Net.Types; using System; using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Net.Sockets; using System.Threading.Tasks; @@ -103,7 +102,7 @@ namespace S7.Net public Plc(CpuType cpu, string ip, Int16 rack, Int16 slot) { if (!Enum.IsDefined(typeof(CpuType), cpu)) - throw new InvalidEnumArgumentException(nameof(cpu), (int) cpu, typeof(CpuType)); + throw new ArgumentException($"The value of argument '{nameof(cpu)}' ({cpu}) is invalid for Enum type '{typeof(CpuType).Name}'.", nameof(cpu)); if (string.IsNullOrEmpty(ip)) throw new ArgumentException("IP address must valid.", nameof(ip)); From 7821b6b6f6fe76a8cc521e2fedd621a9c6312b9d Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:40:22 +0200 Subject: [PATCH 3/8] Add NetStandard 1.3 support Supersedes UWP support since UWP 10.0 supports up to NetStandard 1.4. --- S7.Net/Compat/TcpClientMixins.cs | 19 +++++++++++++++++++ S7.Net/PLCExceptions.cs | 17 ++++++++++++----- S7.Net/S7.Net.csproj | 8 +++++--- S7.Net/Types/Class.cs | 4 ++-- S7.Net/Types/Struct.cs | 25 ++++++++++++++++++++++--- 5 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 S7.Net/Compat/TcpClientMixins.cs diff --git a/S7.Net/Compat/TcpClientMixins.cs b/S7.Net/Compat/TcpClientMixins.cs new file mode 100644 index 0000000..0b449e1 --- /dev/null +++ b/S7.Net/Compat/TcpClientMixins.cs @@ -0,0 +1,19 @@ +using System.Net.Sockets; + +namespace S7.Net +{ + public static class TcpClientMixins + { + #if NETSTANDARD1_3 + public static void Close(this TcpClient tcpClient) + { + tcpClient.Dispose(); + } + + public static void Connect(this TcpClient tcpClient, string host, int port) + { + tcpClient.ConnectAsync(host, port).GetAwaiter().GetResult(); + } + #endif + } +} diff --git a/S7.Net/PLCExceptions.cs b/S7.Net/PLCExceptions.cs index e3b97eb..c06823b 100644 --- a/S7.Net/PLCExceptions.cs +++ b/S7.Net/PLCExceptions.cs @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; +#if NET_FULL +using System.Runtime.Serialization; +#endif + namespace S7.Net { @@ -21,9 +20,11 @@ namespace S7.Net { } + #if NET_FULL protected WrongNumberOfBytesException(SerializationInfo info, StreamingContext context) : base(info, context) { } + #endif } internal class InvalidAddressException : Exception @@ -40,9 +41,11 @@ namespace S7.Net { } + #if NET_FULL protected InvalidAddressException(SerializationInfo info, StreamingContext context) : base(info, context) { } + #endif } internal class InvalidVariableTypeException : Exception @@ -59,9 +62,11 @@ namespace S7.Net { } + #if NET_FULL protected InvalidVariableTypeException(SerializationInfo info, StreamingContext context) : base(info, context) { } + #endif } internal class TPKTInvalidException : Exception @@ -78,8 +83,10 @@ namespace S7.Net { } + #if NET_FULL protected TPKTInvalidException(SerializationInfo info, StreamingContext context) : base(info, context) { } + #endif } } diff --git a/S7.Net/S7.Net.csproj b/S7.Net/S7.Net.csproj index 1bcf18e..1fd6fe5 100644 --- a/S7.Net/S7.Net.csproj +++ b/S7.Net/S7.Net.csproj @@ -1,11 +1,13 @@ - - + - net452;netstandard2.0 + net452;netstandard2.0;netstandard1.3 true Properties\S7.Net.snk S7.Net.UnitTest + + NET_FULL + \ No newline at end of file diff --git a/S7.Net/Types/Class.cs b/S7.Net/Types/Class.cs index 26f4742..40b73ed 100644 --- a/S7.Net/Types/Class.cs +++ b/S7.Net/Types/Class.cs @@ -13,8 +13,8 @@ namespace S7.Net.Types private static IEnumerable GetAccessableProperties(Type classType) { return classType -#if NETFX_CORE - .GetProperties().Where(p => p.GetSetMethod() != null); +#if NETSTANDARD1_3 + .GetTypeInfo().DeclaredProperties.Where(p => p.SetMethod != null); #else .GetProperties( BindingFlags.SetProperty | diff --git a/S7.Net/Types/Struct.cs b/S7.Net/Types/Struct.cs index 9ee05c2..c58eba6 100644 --- a/S7.Net/Types/Struct.cs +++ b/S7.Net/Types/Struct.cs @@ -19,7 +19,13 @@ namespace S7.Net.Types { double numBytes = 0.0; - System.Reflection.FieldInfo[] infos = structType.GetFields(); + var infos = structType + #if NETSTANDARD1_3 + .GetTypeInfo().DeclaredFields; + #else + .GetFields(); + #endif + foreach (System.Reflection.FieldInfo info in infos) { switch (info.FieldType.Name) @@ -80,7 +86,14 @@ namespace S7.Net.Types double numBytes = 0.0; object structValue = Activator.CreateInstance(structType); - System.Reflection.FieldInfo[] infos = structValue.GetType().GetFields(); + + var infos = structValue.GetType() + #if NETSTANDARD1_3 + .GetTypeInfo().DeclaredFields; + #else + .GetFields(); + #endif + foreach (System.Reflection.FieldInfo info in infos) { switch (info.FieldType.Name) @@ -182,7 +195,13 @@ namespace S7.Net.Types int bitPos = 0; double numBytes = 0.0; - System.Reflection.FieldInfo[] infos = type.GetFields(); + var infos = type + #if NETSTANDARD1_3 + .GetTypeInfo().DeclaredFields; + #else + .GetFields(); + #endif + foreach (System.Reflection.FieldInfo info in infos) { bytes2 = null; From 2df9d0b0bfffb3c3648e03bd6a8b54e66b8444cb Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:41:41 +0200 Subject: [PATCH 4/8] Remove obsolete UWP / S7.Net.Core files --- S7.Net.Core/Properties/AssemblyInfo.cs | 29 -- S7.Net.Core/Properties/S7.Net.Core.rd.xml | 33 -- S7.Net.Core/S7.Net.Core.csproj | 176 -------- S7.Net.Core/S7.Net.Core.nuget.props | 21 - S7.Net.Core/S7.Net.Core.nuget.targets | 12 - S7.Net.Core/SocketClient.cs | 481 ---------------------- S7.Net.Core/project.json | 16 - S7.UniversalWindowsApp.sln | 45 -- 8 files changed, 813 deletions(-) delete mode 100644 S7.Net.Core/Properties/AssemblyInfo.cs delete mode 100644 S7.Net.Core/Properties/S7.Net.Core.rd.xml delete mode 100644 S7.Net.Core/S7.Net.Core.csproj delete mode 100644 S7.Net.Core/S7.Net.Core.nuget.props delete mode 100644 S7.Net.Core/S7.Net.Core.nuget.targets delete mode 100644 S7.Net.Core/SocketClient.cs delete mode 100644 S7.Net.Core/project.json delete mode 100644 S7.UniversalWindowsApp.sln diff --git a/S7.Net.Core/Properties/AssemblyInfo.cs b/S7.Net.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index bc10b55..0000000 --- a/S7.Net.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("S7.Net.Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("S7.Net.Core")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: ComVisible(false)] \ No newline at end of file diff --git a/S7.Net.Core/Properties/S7.Net.Core.rd.xml b/S7.Net.Core/Properties/S7.Net.Core.rd.xml deleted file mode 100644 index 6cda541..0000000 --- a/S7.Net.Core/Properties/S7.Net.Core.rd.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/S7.Net.Core/S7.Net.Core.csproj b/S7.Net.Core/S7.Net.Core.csproj deleted file mode 100644 index 2d16f96..0000000 --- a/S7.Net.Core/S7.Net.Core.csproj +++ /dev/null @@ -1,176 +0,0 @@ - - - - - Debug - AnyCPU - {CBFF80E8-3D3D-4656-A27C-A65EA5774536} - Library - Properties - S7.Net.Core - S7.Net.Core - en-US - UAP - 10.0.10586.0 - 10.0.10240.0 - 14 - 512 - {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - ARM - true - full - false - bin\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - ARM - pdbonly - true - bin\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - x86 - true - bin\x86\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - x86 - false - prompt - - - x86 - bin\x86\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - x86 - false - prompt - - - ARM - true - bin\ARM\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - ARM - false - prompt - - - ARM - bin\ARM\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - ARM - false - prompt - - - x64 - true - bin\x64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - x64 - false - prompt - - - x64 - bin\x64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - x64 - false - prompt - - - - - - - - Conversion.cs - - - Enums.cs - - - PLC.cs - - - Types\Boolean.cs - - - Types\Byte.cs - - - Types\ByteArray.cs - - - Types\Class.cs - - - Types\Counter.cs - - - Types\DataItem.cs - - - Types\DInt.cs - - - Types\Double.cs - - - Types\DWord.cs - - - Types\Int.cs - - - Types\String.cs - - - Types\Struct.cs - - - Types\Timer.cs - - - Types\Word.cs - - - - - - - 14.0 - - - - \ No newline at end of file diff --git a/S7.Net.Core/S7.Net.Core.nuget.props b/S7.Net.Core/S7.Net.Core.nuget.props deleted file mode 100644 index a6d1cba..0000000 --- a/S7.Net.Core/S7.Net.Core.nuget.props +++ /dev/null @@ -1,21 +0,0 @@ - - - - True - NuGet - C:\Users\shade\Documents\GitHub\s7netplus\S7.Net.Core\project.lock.json - $(UserProfile)\.nuget\packages\ - C:\Users\shade\.nuget\packages\ - ProjectJson - 4.3.1 - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - - - - \ No newline at end of file diff --git a/S7.Net.Core/S7.Net.Core.nuget.targets b/S7.Net.Core/S7.Net.Core.nuget.targets deleted file mode 100644 index e169bc8..0000000 --- a/S7.Net.Core/S7.Net.Core.nuget.targets +++ /dev/null @@ -1,12 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - - - - \ No newline at end of file diff --git a/S7.Net.Core/SocketClient.cs b/S7.Net.Core/SocketClient.cs deleted file mode 100644 index a207f85..0000000 --- a/S7.Net.Core/SocketClient.cs +++ /dev/null @@ -1,481 +0,0 @@ -using System; -using System.Net.Sockets; -using System.Threading; -using System.Net; - -namespace S7.Net -{ - /// - /// This class encapsulate System.Net.Sockets.Socket class of .Net core, so we can use the same methods of the standard Socket class inside the S7.Net sources. - /// - internal class Socket - { - - public bool Connected - { - get - { - if (_socket == null) - return false; - - return _socket.Connected; - } - } - - public SocketError LastSocketError { get; private set; } - - public Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) - { - _socket = new System.Net.Sockets.Socket(addressFamily, socketType, protocolType); - } - - public void Connect(IPEndPoint server) - { - if (Connected) - return; - - LastSocketError = SocketError.NotConnected; - - var socketEventArg = new SocketAsyncEventArgs(); - - socketEventArg.RemoteEndPoint = server; - - var completedEvent = new EventHandler(delegate (object s, SocketAsyncEventArgs e) - { - LastSocketError = e.SocketError; - _clientDone.Set(); - }); - - socketEventArg.Completed += completedEvent; - - _clientDone.Reset(); - - LastSocketError = SocketError.TimedOut; - - _socket.ConnectAsync(socketEventArg); - - _clientDone.WaitOne(TIMEOUT_MILLISECONDS); - - socketEventArg.Completed -= completedEvent; - } - - public int Send(byte[] buffer, int size, SocketFlags socketFlag) - { - var response = 0; - - if (_socket != null) - { - var socketEventArg = new SocketAsyncEventArgs(); - - socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint; - socketEventArg.UserToken = null; - - var completedEvent = new EventHandler(delegate (object s, SocketAsyncEventArgs e) - { - LastSocketError = e.SocketError; - - if (e.SocketError == SocketError.Success) - response = e.BytesTransferred; - - _clientDone.Set(); - }); - - socketEventArg.Completed += completedEvent; - - socketEventArg.SetBuffer(buffer, 0, size); - - _clientDone.Reset(); - - LastSocketError = SocketError.TimedOut; - - _socket.SendAsync(socketEventArg); - - _clientDone.WaitOne(_sendTimeout); - - socketEventArg.Completed -= completedEvent; - } - else - { - LastSocketError = SocketError.NotInitialized; - } - - return response; - } - - public int Receive(byte[] buffer, int size, SocketFlags socketFlag) - { - var response = 0; - - if (_socket != null) - { - var socketEventArg = new SocketAsyncEventArgs(); - - socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint; - socketEventArg.SetBuffer(buffer, 0, size); - - var completedEvent = new EventHandler(delegate (object s, SocketAsyncEventArgs e) - { - LastSocketError = e.SocketError; - - if (e.SocketError == SocketError.Success) - response = e.BytesTransferred; - - _clientDone.Set(); - }); - - socketEventArg.Completed += completedEvent; - - _clientDone.Reset(); - - LastSocketError = SocketError.TimedOut; - - _socket.ReceiveAsync(socketEventArg); - - _clientDone.WaitOne(_receiveTimeout); - - socketEventArg.Completed -= completedEvent; - } - else - { - LastSocketError = SocketError.NotInitialized; - } - - return response; - } - - public void Shutdown(SocketShutdown how) - { - _socket.Shutdown(how); - } - - public void Close() - { - if (_socket != null) - { - _socket.Dispose(); - _socket = null; - } - } - - // - // Summary: - // Sets the specified System.Net.Sockets.Socket option to the specified integer - // value. - // - // Parameters: - // optionLevel: - // One of the System.Net.Sockets.SocketOptionLevel values. - // - // optionName: - // One of the System.Net.Sockets.SocketOptionName values. - // - // optionValue: - // A value of the option. - // - // Exceptions: - // T:System.Net.Sockets.SocketException: - // An error occurred when attempting to access the socket. See the Remarks section - // for more information. - // - // T:System.ObjectDisposedException: - // The System.Net.Sockets.Socket has been closed. - public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue) - { - switch (optionName) - { - case SocketOptionName.ReceiveTimeout: - _receiveTimeout = optionValue; - break; - - case SocketOptionName.SendTimeout: - _sendTimeout = optionValue; - break; - - default: - throw new NotImplementedException("SetSocketOption option not implemented"); - } - } - - private System.Net.Sockets.Socket _socket = null; - private int _receiveTimeout = TIMEOUT_MILLISECONDS; - private int _sendTimeout = TIMEOUT_MILLISECONDS; - - private readonly static ManualResetEvent _clientDone = - new ManualResetEvent(false); - - private const int TIMEOUT_MILLISECONDS = 1000; - - } - - // - // Summary: - // Specifies socket send and receive behaviors. - [Flags] - public enum SocketFlags - { - // - // Summary: - // Use no flags for this call. - None = 0, - //// - //// Summary: - //// Process out-of-band data. - //OutOfBand = 1, - //// - //// Summary: - //// Peek at the incoming message. - //Peek = 2, - //// - //// Summary: - //// Send without using routing tables. - //DontRoute = 4, - //// - //// Summary: - //// Provides a standard value for the number of WSABUF structures that are used to - //// send and receive data. - //MaxIOVectorLength = 16, - //// - //// Summary: - //// The message was too large to fit into the specified buffer and was truncated. - //Truncated = 256, - //// - //// Summary: - //// Indicates that the control data did not fit into an internal 64-KB buffer and - //// was truncated. - //ControlDataTruncated = 512, - //// - //// Summary: - //// Indicates a broadcast packet. - //Broadcast = 1024, - //// - //// Summary: - //// Indicates a multicast packet. - //Multicast = 2048, - //// - //// Summary: - //// Partial send or receive for message. - //Partial = 32768 - } - - // - // Summary: - // Defines socket option levels for the System.Net.Sockets.Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,System.Int32) - // and System.Net.Sockets.Socket.GetSocketOption(System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName) - // methods. - public enum SocketOptionLevel - { - // - // Summary: - // System.Net.Sockets.Socket options apply only to IP sockets. - IP = 0, - // - // Summary: - // System.Net.Sockets.Socket options apply only to TCP sockets. - Tcp = 6, - // - // Summary: - // System.Net.Sockets.Socket options apply only to UDP sockets. - Udp = 17, - // - // Summary: - // System.Net.Sockets.Socket options apply only to IPv6 sockets. - IPv6 = 41, - // - // Summary: - // System.Net.Sockets.Socket options apply to all sockets. - Socket = 65535 - } - - // - // Summary: - // Defines configuration option names. - public enum SocketOptionName - { - // - // Summary: - // Close the socket gracefully without lingering. - DontLinger = -129, - // - // Summary: - // Enables a socket to be bound for exclusive access. - ExclusiveAddressUse = -5, - // - // Summary: - // Record debugging information. - Debug = 1, - // - // Summary: - // Specifies the IP options to be inserted into outgoing datagrams. - IPOptions = 1, - // - // Summary: - // Disables the Nagle algorithm for send coalescing. - NoDelay = 1, - // - // Summary: - // Send UDP datagrams with checksum set to zero. - NoChecksum = 1, - // - // Summary: - // The socket is listening. - AcceptConnection = 2, - // - // Summary: - // Indicates that the application provides the IP header for outgoing datagrams. - HeaderIncluded = 2, - // - // Summary: - // Use urgent data as defined in RFC-1222. This option can be set only once; after - // it is set, it cannot be turned off. - BsdUrgent = 2, - // - // Summary: - // Use expedited data as defined in RFC-1222. This option can be set only once; - // after it is set, it cannot be turned off. - Expedited = 2, - // - // Summary: - // Change the IP header type of the service field. - TypeOfService = 3, - // - // Summary: - // Allows the socket to be bound to an address that is already in use. - ReuseAddress = 4, - // - // Summary: - // Set the IP header Time-to-Live field. - IpTimeToLive = 4, - // - // Summary: - // Use keep-alives. - KeepAlive = 8, - // - // Summary: - // Set the interface for outgoing multicast packets. - MulticastInterface = 9, - // - // Summary: - // An IP multicast Time to Live. - MulticastTimeToLive = 10, - // - // Summary: - // An IP multicast loopback. - MulticastLoopback = 11, - // - // Summary: - // Add an IP group membership. - AddMembership = 12, - // - // Summary: - // Drop an IP group membership. - DropMembership = 13, - // - // Summary: - // Do not fragment IP datagrams. - DontFragment = 14, - // - // Summary: - // Join a source group. - AddSourceMembership = 15, - // - // Summary: - // Do not route; send the packet directly to the interface addresses. - DontRoute = 16, - // - // Summary: - // Drop a source group. - DropSourceMembership = 16, - // - // Summary: - // Block data from a source. - BlockSource = 17, - // - // Summary: - // Unblock a previously blocked source. - UnblockSource = 18, - // - // Summary: - // Return information about received packets. - PacketInformation = 19, - // - // Summary: - // Set or get the UDP checksum coverage. - ChecksumCoverage = 20, - // - // Summary: - // Specifies the maximum number of router hops for an Internet Protocol version - // 6 (IPv6) packet. This is similar to Time to Live (TTL) for Internet Protocol - // version 4. - HopLimit = 21, - // - // Summary: - // Permit sending broadcast messages on the socket. - Broadcast = 32, - // - // Summary: - // Bypass hardware when possible. - UseLoopback = 64, - // - // Summary: - // Linger on close if unsent data is present. - Linger = 128, - // - // Summary: - // Receives out-of-band data in the normal data stream. - OutOfBandInline = 256, - // - // Summary: - // Specifies the total per-socket buffer space reserved for sends. This is unrelated - // to the maximum message size or the size of a TCP window. - SendBuffer = 4097, - // - // Summary: - // Specifies the total per-socket buffer space reserved for receives. This is unrelated - // to the maximum message size or the size of a TCP window. - ReceiveBuffer = 4098, - // - // Summary: - // Specifies the low water mark for Overload:System.Net.Sockets.Socket.Send operations. - SendLowWater = 4099, - // - // Summary: - // Specifies the low water mark for Overload:System.Net.Sockets.Socket.Receive operations. - ReceiveLowWater = 4100, - // - // Summary: - // Send a time-out. This option applies only to synchronous methods; it has no effect - // on asynchronous methods such as the System.Net.Sockets.Socket.BeginSend(System.Byte[],System.Int32,System.Int32,System.Net.Sockets.SocketFlags,System.AsyncCallback,System.Object) - // method. - SendTimeout = 4101, - // - // Summary: - // Receive a time-out. This option applies only to synchronous methods; it has no - // effect on asynchronous methods such as the System.Net.Sockets.Socket.BeginSend(System.Byte[],System.Int32,System.Int32,System.Net.Sockets.SocketFlags,System.AsyncCallback,System.Object) - // method. - ReceiveTimeout = 4102, - // - // Summary: - // Get the error status and clear. - Error = 4103, - // - // Summary: - // Get the socket type. - Type = 4104, - // - // Summary: - // Updates an accepted socket's properties by using those of an existing socket. - // This is equivalent to using the Winsock2 SO_UPDATE_ACCEPT_CONTEXT socket option - // and is supported only on connection-oriented sockets. - UpdateAcceptContext = 28683, - // - // Summary: - // Updates a connected socket's properties by using those of an existing socket. - // This is equivalent to using the Winsock2 SO_UPDATE_CONNECT_CONTEXT socket option - // and is supported only on connection-oriented sockets. - UpdateConnectContext = 28688, - // - // Summary: - // Not supported; will throw a System.Net.Sockets.SocketException if used. - MaxConnections = int.MaxValue - } -} \ No newline at end of file diff --git a/S7.Net.Core/project.json b/S7.Net.Core/project.json deleted file mode 100644 index d269c23..0000000 --- a/S7.Net.Core/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.UniversalWindowsPlatform": "5.4.0" - }, - "frameworks": { - "uap10.0.10240": {} - }, - "runtimes": { - "win10-arm": {}, - "win10-arm-aot": {}, - "win10-x86": {}, - "win10-x86-aot": {}, - "win10-x64": {}, - "win10-x64-aot": {} - } -} \ No newline at end of file diff --git a/S7.UniversalWindowsApp.sln b/S7.UniversalWindowsApp.sln deleted file mode 100644 index 7bdd6d0..0000000 --- a/S7.UniversalWindowsApp.sln +++ /dev/null @@ -1,45 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7A8252C3-E6AE-435A-809D-4413C06E0711}" - ProjectSection(SolutionItems) = preProject - README.md = README.md - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S7.Net.Core", "S7.Net.Core\S7.Net.Core.csproj", "{CBFF80E8-3D3D-4656-A27C-A65EA5774536}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|ARM.ActiveCfg = Debug|ARM - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|ARM.Build.0 = Debug|ARM - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|x64.ActiveCfg = Debug|x64 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|x64.Build.0 = Debug|x64 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|x86.ActiveCfg = Debug|x86 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Debug|x86.Build.0 = Debug|x86 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|Any CPU.Build.0 = Release|Any CPU - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|ARM.ActiveCfg = Release|ARM - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|ARM.Build.0 = Release|ARM - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|x64.ActiveCfg = Release|x64 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|x64.Build.0 = Release|x64 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|x86.ActiveCfg = Release|x86 - {CBFF80E8-3D3D-4656-A27C-A65EA5774536}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal From a1f4e44c48b922412d7286ae23eb3e4bb74ce20a Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:43:13 +0200 Subject: [PATCH 5/8] R#: Cleanup usings --- S7.Net/COTP.cs | 1 - S7.Net/PLC.cs | 5 ----- S7.Net/PLCHelpers.cs | 4 ---- S7.Net/PlcAsynchronous.cs | 2 -- S7.Net/PlcSynchronous.cs | 3 --- S7.Net/TPKT.cs | 1 - S7.Net/Types/Bit.cs | 3 +-- S7.Net/Types/Boolean.cs | 4 +--- S7.Net/Types/Struct.cs | 2 -- 9 files changed, 2 insertions(+), 23 deletions(-) diff --git a/S7.Net/COTP.cs b/S7.Net/COTP.cs index dea9f06..364363f 100644 --- a/S7.Net/COTP.cs +++ b/S7.Net/COTP.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Net.Sockets; using System.Threading.Tasks; using System.Linq; diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs index e8ddc1c..80cefba 100644 --- a/S7.Net/PLC.cs +++ b/S7.Net/PLC.cs @@ -1,10 +1,5 @@ -using S7.Net.Types; using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; using System.Net.Sockets; -using System.Threading.Tasks; namespace S7.Net diff --git a/S7.Net/PLCHelpers.cs b/S7.Net/PLCHelpers.cs index 4bf5753..14e536b 100644 --- a/S7.Net/PLCHelpers.cs +++ b/S7.Net/PLCHelpers.cs @@ -1,11 +1,7 @@ using S7.Net.Types; using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; -using System.Net.Sockets; -using System.Threading.Tasks; namespace S7.Net { diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs index 0cd32b0..c829963 100644 --- a/S7.Net/PlcAsynchronous.cs +++ b/S7.Net/PlcAsynchronous.cs @@ -1,8 +1,6 @@ using S7.Net.Types; using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Net.Sockets; using System.Threading.Tasks; diff --git a/S7.Net/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs index ec092ed..8f1b5bc 100644 --- a/S7.Net/PlcSynchronous.cs +++ b/S7.Net/PlcSynchronous.cs @@ -1,11 +1,8 @@ using S7.Net.Types; using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Net.Sockets; -using System.Threading.Tasks; using S7.Net.Protocol; //Implement synchronous methods here diff --git a/S7.Net/TPKT.cs b/S7.Net/TPKT.cs index 2b71cec..a3af212 100644 --- a/S7.Net/TPKT.cs +++ b/S7.Net/TPKT.cs @@ -1,5 +1,4 @@ using System; -using System.Net.Sockets; using System.IO; using System.Threading.Tasks; diff --git a/S7.Net/Types/Bit.cs b/S7.Net/Types/Bit.cs index cd36118..5f00476 100644 --- a/S7.Net/Types/Bit.cs +++ b/S7.Net/Types/Bit.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; namespace S7.Net.Types { diff --git a/S7.Net/Types/Boolean.cs b/S7.Net/Types/Boolean.cs index 4c93895..b83369d 100644 --- a/S7.Net/Types/Boolean.cs +++ b/S7.Net/Types/Boolean.cs @@ -1,6 +1,4 @@ -using System; - -namespace S7.Net.Types +namespace S7.Net.Types { /// /// Contains the methods to read, set and reset bits inside bytes diff --git a/S7.Net/Types/Struct.cs b/S7.Net/Types/Struct.cs index c58eba6..2d6dde5 100644 --- a/S7.Net/Types/Struct.cs +++ b/S7.Net/Types/Struct.cs @@ -1,6 +1,4 @@ using System; -using System.Linq; -using System.Globalization; using System.Reflection; namespace S7.Net.Types From 98228924eada3569e551deea8b1cc4a111e51872 Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Sat, 30 Jun 2018 21:48:12 +0200 Subject: [PATCH 6/8] Simplify info declaration in Struct field loops --- S7.Net/Types/Struct.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/S7.Net/Types/Struct.cs b/S7.Net/Types/Struct.cs index 2d6dde5..cd88e92 100644 --- a/S7.Net/Types/Struct.cs +++ b/S7.Net/Types/Struct.cs @@ -24,7 +24,7 @@ namespace S7.Net.Types .GetFields(); #endif - foreach (System.Reflection.FieldInfo info in infos) + foreach (var info in infos) { switch (info.FieldType.Name) { @@ -92,7 +92,7 @@ namespace S7.Net.Types .GetFields(); #endif - foreach (System.Reflection.FieldInfo info in infos) + foreach (var info in infos) { switch (info.FieldType.Name) { @@ -200,7 +200,7 @@ namespace S7.Net.Types .GetFields(); #endif - foreach (System.Reflection.FieldInfo info in infos) + foreach (var info in infos) { bytes2 = null; switch (info.FieldType.Name) From fc62bb79d49d1373a39c34c173effded4de873e5 Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Mon, 2 Jul 2018 20:27:29 +0200 Subject: [PATCH 7/8] Update supported frameworks and compile section --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dacc228..a6e990a 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,13 @@ S7.Net Plus has a [User Manual](https://github.com/killnine/s7netplus/blob/maste + Compatible S7 PLC (S7-200, S7-300, S7-400, S7-1200, S7-1500) -## Target framework -+ .NET Framework 3.5 or higher -+ Universal Windows Application (.Net Core) - see S7.UniversalWindowsApp.sln +## Supported frameworks ++ .NET Framework 4.5.2 and higher ++ .NET Standard 1.3 (.NET Core 1.0, UWP 10.0, Xamarin, ...) ++ .NET Standard 2.0 (.NET Core 2.0, .NET Framework 4.6.1) ## Compile -You need at least Visual Studio 2015 (you can download the Community Edition for free). +You need at least Visual Studio 2017 (you can download the Community Edition for free). ## Nuget From 28a122526569967b19c56f66a356d7b9df2ddaf9 Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Mon, 2 Jul 2018 22:59:16 +0200 Subject: [PATCH 8/8] Change S7.Net project type in S7.sln --- S7.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/S7.sln b/S7.sln index 5a1565d..85c156a 100644 --- a/S7.sln +++ b/S7.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27703.2026 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "S7.Net", "S7.Net\S7.Net.csproj", "{BFD484F9-3F04-42A2-BF2A-60A189A25DCF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S7.Net", "S7.Net\S7.Net.csproj", "{BFD484F9-3F04-42A2-BF2A-60A189A25DCF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7A8252C3-E6AE-435A-809D-4413C06E0711}" ProjectSection(SolutionItems) = preProject