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); } } } }
private Task ReceivedCommunicationSetupAck(Memory <byte> buffer) { var data = S7CommSetupAckDataDatagram.TranslateFromMemory(buffer); _s7Context.MaxParallelJobs = data.Parameter.MaxAmQCalling; _s7Context.PduSize = data.Parameter.PduLength; _concurrentJobs = new SemaphoreSlim(_s7Context.MaxParallelJobs); UpdateConnectionState(ConnectionState.Opened); _connectEvent.Set(true); return(Task.CompletedTask); }
private void ReceivedCommunicationSetupAck(Memory <byte> buffer) { var data = S7CommSetupAckDataDatagram.TranslateFromMemory(buffer); var oldSemaCount = _s7Context.MaxAmQCalling; _s7Context.MaxAmQCalling = data.Parameter.MaxAmQCalling; _s7Context.MaxAmQCalled = data.Parameter.MaxAmQCalled; _s7Context.PduSize = data.Parameter.PduLength; UpdateJobsSemaphore(oldSemaCount, _s7Context.MaxAmQCalling); _ = UpdateConnectionState(ConnectionState.Opened); _connectEvent.Set(true); }
private void ReceivedCommunicationSetupAck(Memory <byte> buffer) { var data = S7CommSetupAckDataDatagram.TranslateFromMemory(buffer); _s7Context.MaxAmQCalling = data.Parameter.MaxAmQCalling; _s7Context.MaxAmQCalled = data.Parameter.MaxAmQCalled; _s7Context.PduSize = data.Parameter.PduLength; if (_concurrentJobs != null) { _concurrentJobs.Dispose(); } _concurrentJobs = new SemaphoreSlim(_s7Context.MaxAmQCalling); _ = UpdateConnectionState(ConnectionState.Opened); _connectEvent.Set(true); }
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); } } } }