private void Input_OnReceive(object sender, ChannelReceivedEventArgs e) { MbapHeader header = MbapHeader.Decode(e.Message); if (header == null) { logger?.LogWarning("MBAP Header returned null"); return; //assume keep alive } if (!map.HasItem(header.UnitId)) { byte[] errorMsg = ModbusErrorMessage.Create(e.Message, ErrorCode.GatewayPathsNotAvailable); InputChannel.SendAsync(errorMsg).GetAwaiter(); return; } if (!map.GetItem(header.UnitId).Authorize(e.Message)) { byte[] errorMsg = ModbusErrorMessage.Create(e.Message, ErrorCode.IllegalAddress); InputChannel.SendAsync(errorMsg).GetAwaiter(); return; } byte[] message = e.Message; byte[] msg = null; foreach (var filter in InputFilters) { msg = filter.Execute(message); msg ??= message; } OutputChannel.SendAsync(msg).GetAwaiter(); }
private void Output_OnReceive(object sender, ChannelReceivedEventArgs e) { byte[] message = e.Message; byte[] msg = null; foreach (var filter in OutputFilters) { msg = filter.Execute(message); msg ??= message; } InputChannel.SendAsync(msg); }