public override void AdsReadWriteInd(AmsAddress rAddr, uint invokeId, uint indexGroup, uint indexOffset, uint cbReadLength, uint cbWriteLength, byte[] data)
 {
     if (OnClientReadWriteRequest != null)
     {
         _pendingRequests.Add(
             invokeId,
             Task.Factory.StartNew(() => {
             Protocol.AdsContext context = new Protocol.AdsContext(rAddr.ToString(), Protocol.AdsCommand.ReadWrite, invokeId, indexGroup, indexOffset, cbReadLength, data);
             OnClientReadWriteRequest(context);
             ServiceRequest(context);
         }, _cancellationSource.Token)
             );
     }
 }
示例#2
0
        public override void AdsWriteInd(AmsAddress rAddr, uint invokeId, uint indexGroup, uint indexOffset, uint cbLength, byte[] data)
        {
            // send response as soon as possible
            AdsWriteRes(rAddr, invokeId, AdsErrorCode.NoError);

            try
            {
                var entries = new List <LogEntry>();
                var reader  = new AdsBinaryReader(new AdsStream(data));

                while (reader.BaseStream.Length > reader.BaseStream.Position)
                {
                    LogEntry logEntry;

                    var version = reader.ReadByte();
                    if (version == 1)
                    {
                        logEntry = ReadLogEntryV1(reader);
                    }
                    else
                    {
                        throw new NotImplementedException($"Version {version}");
                    }

                    logEntry.Source   = rAddr.ToString();
                    logEntry.Hostname = _adsHostnameService.GetHostname(rAddr.NetId).ValueOr(string.Empty);

                    entries.Add(logEntry);
                }

                LogsReceived?.Invoke(this, new LogEntryEventArgs(entries));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error parsing log message from plc.");
            }
        }