private void ModbusMessageReceived(string resource, string contentType, byte[] message)
 {
     try
     {
         MbapHeader header = MbapHeader.Decode(message);
         string     key    = GetCacheKey(header);
         if (cache.Contains(key))
         {
             cache.Remove(key);
             OnReceive?.Invoke(this, new ChannelReceivedEventArgs(channel.Id, message));
             logger?.LogDebug("Output channel received message.");
             diag?.PublishOutput(header).GetAwaiter();
         }
         else
         {
             logger?.LogWarning("Vrtu channel cannot match received message.");
         }
     }
     catch (Exception ex)
     {
         logger?.LogError(ex, "Fault receiving message on vrtu channel.");
     }
 }
Exemple #2
0
        public async Task SendAsync(byte[] message)
        {
            if (client == null || !client.IsConnected)
            {
                logger?.LogWarning("Module channel client is unavailable to send.");
                return;
            }

            try
            {
                MbapHeader header   = MbapHeader.Decode(message);
                string     pisystem = UriGenerator.GetRtuPiSystem(hostname, virtualRtuId, deviceId, header.UnitId, false);
                await client.PublishAsync(QualityOfServiceLevelType.AtMostOnce, pisystem, "application/json", message);

                await diag?.PublishOutput(header);

                logger?.LogDebug("Published message on module channel");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, "Fault sending on module channel.");
            }
        }