/// <summary>
        /// Initializes a new instance of the <see cref="ConcurrentRequestExecutor"/> class with the specified
        /// connection and memory pool.
        /// </summary>
        /// <param name="connection">The <see cref="S7Connection"/> that is used for this executor.</param>
        /// <param name="memoryPool">
        /// The <see cref="MemoryPool{T}" /> that is used for request and response memory allocations.
        /// </param>
        public ConcurrentRequestExecutor(S7Connection connection, MemoryPool <byte>?memoryPool = default)
        {
            if (connection.Parameters == null)
            {
                Sally7CommunicationSetupException.ThrowConnectionParametersNotSet();
            }

            Connection      = connection;
            socket          = connection.TcpClient.Client;
            bufferSize      = connection.Parameters.GetRequiredBufferSize();
            maxRequests     = connection.Parameters.MaximumNumberOfConcurrentRequests;
            this.memoryPool = memoryPool ?? MemoryPool <byte> .Shared;

            jobPool       = new JobPool(connection.Parameters.MaximumNumberOfConcurrentRequests);
            sendSignal    = new Signal();
            receiveSignal = new Signal();

            if (!sendSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitSendingSignal();
            }
            if (!receiveSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitReceivingSignal();
            }

            reader = new SocketTpktReader(socket);

#if !NETSTANDARD2_1_OR_GREATER && !NET5_0_OR_GREATER
            sendAwaitable = new SocketAwaitable(new SocketAsyncEventArgs());
#endif
        }
Beispiel #2
0
        private static Tsap GetDestinationTsap(CpuType cpuType, int?rack, int?slot)
        {
            switch (cpuType)
            {
            case CpuType.S7_200:
                return(new Tsap(0x10, 0x00));

            case CpuType.S7_300:
            case CpuType.S7_400:
            case CpuType.S7_1200:
            case CpuType.S7_1500:
                if (rack == null)
                {
                    Sally7CommunicationSetupException.ThrowDestinationRackIsNull(cpuType, rack);
                }
                if (slot == null)
                {
                    Sally7CommunicationSetupException.ThrowDestinationSlotIsNull(cpuType, slot);
                }

                return(new Tsap(0x03, (byte)((rack.GetValueOrDefault() << 5) | slot.GetValueOrDefault())));

            default:
                Sally7CommunicationSetupException.ThrowCpuTypeNotSupported(cpuType);
                return(default);    // to make the compiler happy
            }
        }
Beispiel #3
0
        private static Tsap GetSourceTsap(CpuType cpuType)
        {
            switch (cpuType)
            {
            case CpuType.S7_200:
                return(new Tsap(0x10, 0x00));

            case CpuType.S7_300:
            case CpuType.S7_400:
            case CpuType.S7_1200:
                return(new Tsap(0x01, 0x00));

            case CpuType.S7_1500:
                return(new Tsap(0x10, 0x02));

            default:
                Sally7CommunicationSetupException.ThrowCpuTypeNotSupported(cpuType);
                return(default);    // to make the compiler happy
            }
        }