Ejemplo n.º 1
0
        private void ReceivedReadJobAck(Memory <byte> buffer)
        {
            var data = S7ReadJobAckDatagram.TranslateFromMemory(buffer);

            if (_readHandler.TryGetValue(data.Header.Header.ProtocolDataUnitReference, out var cbh))
            {
                if (data.Header.Error.ErrorClass != 0)
                {
                    _logger?.LogError("Error while reading data for reference {0}. ErrorClass: {1}  ErrorCode:{2}", data.Header.Header.ProtocolDataUnitReference, data.Header.Error.ErrorClass, data.Header.Error.ErrorCode);
                    cbh.Exception = new Dacs7Exception(data.Header.Error.ErrorClass, data.Header.Error.ErrorCode);
                }
                if (data.Data == null)
                {
                    _logger?.LogWarning("No data from read ack received for reference {0}", data.Header.Header.ProtocolDataUnitReference);
                }

                if (cbh.Event != null)
                {
                    cbh.Event.Set(data.Data);
                }
                else
                {
                    _logger?.LogWarning("No event for read handler found for received read ack reference {0}", data.Header.Header.ProtocolDataUnitReference);
                }
            }
            else
            {
                _logger?.LogWarning("No read handler found for received read ack reference {0}", data.Header.Header.ProtocolDataUnitReference);
            }
        }
Ejemplo n.º 2
0
        private Task ReceivedReadJobAck(Memory <byte> buffer)
        {
            var data = S7ReadJobAckDatagram.TranslateFromMemory(buffer);

            if (_readHandler.TryGetValue(data.Header.Header.ProtocolDataUnitReference, out var cbh))
            {
                cbh.Event.Set(data.Data);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        private async Task SendReadJobAck(List <ReadResultItem> readItems, ushort id)
        {
            using (var dgmem = S7ReadJobAckDatagram.TranslateToMemory(S7ReadJobAckDatagram.Build(_s7Context, id, readItems), out var commemLength))
            {
                using (var sendData = _transport.Build(dgmem.Memory.Slice(0, commemLength), out var sendLength))
                {
                    var result = await _transport.Connection.SendAsync(sendData.Memory.Slice(0, sendLength)).ConfigureAwait(false);

                    if (result == SocketError.Success)
                    {
                        // OK
                    }
                }
            }
        }