public ModuleService(ModuleConfig config, ModuleTcpChannel channel, Logger logger = null) { this.config = config; output = channel; this.logger = logger; mapper = new MbapMapper(Guid.NewGuid().ToString()); adapter = new ModuleTwinAdapter(); adapter.OnConfigurationReceived += Adapter_OnConfigurationReceived; }
public SlaveChannel(Slave slave, ILogger logger = null) { this.slave = slave; this.logger = logger; SlaveId = slave.UnitId; mapper = new MbapMapper(Guid.NewGuid().ToString()); delayPolicy = new ExponentialDelayPolicy(30000, 2, true); retryPolicy = new BasicRetryPolicy(delayPolicy, 5); CreateChannelAsync().GetAwaiter(); }
public TcpManager(ModuleConfig config, ILogger logger = null) { this.config = config; this.config.OnChanged += Config_OnChanged; this.logger = logger; slaves = new Dictionary <string, Slave>(); connections = new Dictionary <byte, Tuple <TcpConnection, byte?> >(); mapper = new MbapMapper("rtumapper"); RunAsync().GetAwaiter(); }
public ScadaClientAdapter(VrtuConfig config, IChannel channel, ILogger logger) { Id = Guid.NewGuid().ToString(); this.config = config; this.channel = channel; this.logger = logger; subscribed = new HashSet <byte>(); mapper = new MbapMapper("vrtu"); OpenWebSocketAsync().GetAwaiter(); }
public async Task RunAsync() { #if DEBUG listener = new TcpListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 502)); #else listener = new TcpListener(new IPEndPoint(GetIPAddress(Dns.GetHostName()), 502)); #endif listener.ExclusiveAddressUse = false; listener.Start(); logger?.LogInformation("SCADA client listener started."); while (true) { try { TcpClient tcpClient = await listener.AcceptTcpClientAsync(); tcpClient.LingerState = new LingerOption(true, 0); tcpClient.NoDelay = true; tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); CancellationTokenSource cts = new CancellationTokenSource(); logger?.LogDebug("SCADA client connection acquired."); IChannel inputChannel = ChannelFactory.Create(false, tcpClient, 1024, 1024 * 100, cts.Token); logger?.LogDebug("SCADA client created TCP input channel"); IChannel outputChannel = new VirtualRtuChannel(config, logger); logger?.LogDebug("SCADA client created VRTU output channel"); MbapMapper mapper = new MbapMapper(Guid.NewGuid().ToString()); PipelineBuilder builder = new PipelineBuilder(logger); Pipeline pipeline = builder.AddConfig(config) .AddInputChannel(inputChannel) .AddOutputChannel(outputChannel) .AddInputFilter(new InputMapFilter(mapper)) .AddOutputFilter(new OutputMapFilter(mapper)) .Build(); logger?.LogDebug("SCADA client pipeline built."); pipeline.OnPipelineError += Pipeline_OnPipelineError; pipelines.Add(pipeline.Id, pipeline); pipeline.Execute(); logger?.LogDebug("SCADA client pipeline executed."); } catch (Exception ex) { logger?.LogError(ex, "Fault creating pipeline."); } } }
public RtuController(ModuleConfig config, ModuleTcpChannel channel, ILogger logger = null) { if (channel == null) { this.channel = ModuleTcpChannel.CreateSingleton(config, logger); if (!this.channel.IsConnected) { this.channel.OpenAsync().GetAwaiter(); } } else { this.channel = channel; } this.logger = logger; mapper = new MbapMapper(Guid.NewGuid().ToString()); }
public OutputMapFilter(MbapMapper mapper) { this.mapper = mapper; }