Exemple #1
0
        private async Task ReceivedCommunicationSetupJob(Memory <byte> buffer)
        {
            var data = S7CommSetupDatagram.TranslateFromMemory(buffer);

            using (var dg = S7CommSetupAckDataDatagram
                            .TranslateToMemory(
                       S7CommSetupAckDataDatagram
                       .BuildFrom(_s7Context, data), out var memoryLength))
            {
                using (var sendData = _transport.Build(dg.Memory.Slice(0, memoryLength), out var sendLength))
                {
                    var result = await _transport.Client.SendAsync(sendData.Memory.Slice(0, sendLength)).ConfigureAwait(false);

                    if (result == SocketError.Success)
                    {
                        //UpdateConnectionState(ConnectionState.PendingOpenPlc);
                        _s7Context.MaxAmQCalling = data.Parameter.MaxAmQCalling;
                        _s7Context.MaxAmQCalled  = data.Parameter.MaxAmQCalling;
                        _s7Context.PduSize       = data.Parameter.PduLength;

                        if (_concurrentJobs != null)
                        {
                            _concurrentJobs.Dispose();
                        }
                        _concurrentJobs = new SemaphoreSlim(_s7Context.MaxAmQCalling);

                        await UpdateConnectionState(ConnectionState.Opened).ConfigureAwait(false);
                    }
                }
            }
        }
Exemple #2
0
        private async Task HandleCommSetupAsync(S7CommSetupDatagram data)
        {
            using (var dg = S7CommSetupAckDataDatagram
                            .TranslateToMemory(
                       S7CommSetupAckDataDatagram
                       .BuildFrom(_s7Context, data, data.Header.ProtocolDataUnitReference), out var memoryLength))
            {
                using (var sendData = _transport.Build(dg.Memory.Slice(0, memoryLength), out var sendLength))
                {
                    var result = await _transport.Connection.SendAsync(sendData.Memory.Slice(0, sendLength)).ConfigureAwait(false);

                    if (result == SocketError.Success)
                    {
                        var oldSemaCount = _s7Context.MaxAmQCalling;
                        _s7Context.MaxAmQCalling = data.Parameter.MaxAmQCalling;
                        _s7Context.MaxAmQCalled  = data.Parameter.MaxAmQCalled;
                        _s7Context.PduSize       = data.Parameter.PduLength;
                        UpdateJobsSemaphore(oldSemaCount, _s7Context.MaxAmQCalling);

                        await UpdateConnectionState(ConnectionState.Opened).ConfigureAwait(false);
                    }
                }
            }
        }