public void AddChannels(List<Channel> channels) { foreach (Channel c in channels.Where(x => x.Enabled > 0)) { Dictionary<String, String> ConnectionOptions = StringToDictionary.Convert(c.ConnectionString); // TODO: Try/catch around this to continue after hitting a bad channel switch (c.Type.ToLower()) { case "tcpclient": if (ConnectionOptions.Keys.Contains("address") && ConnectionOptions.Keys.Contains("port")) { UInt16 port = Convert.ToUInt16(ConnectionOptions["port"]); if (port == 0) throw new FormatException(); // TODO timespan option IChannel ch = DNP3Manager.AddTCPClient(c.Name, LogLevel.Info, TimeSpan.FromSeconds(5), ConnectionOptions["address"], port); ChannelWrapper wr = new ChannelWrapper(c, ch); wr.OnStateChanged += this.ChannelStateChanged; wr.Channel.AddStateListener(new Action<ChannelState>(wr.StateChanged)); Channels.Add(wr); } break; case "serial": if (ConnectionOptions.Keys.Contains("port") && ConnectionOptions.Keys.Contains("baud")) { UInt16 baud = Convert.ToUInt16(ConnectionOptions["baud"]); if (baud == 0) throw new FormatException(); // TODO: more serial settings SerialSettings ss = new SerialSettings(ConnectionOptions["port"], baud, 8, 1, Parity.NONE, FlowControl.NONE); // TODO: timespan option IChannel ch = DNP3Manager.AddSerial(c.Name, LogLevel.Info, TimeSpan.FromSeconds(5), ss); ChannelWrapper wr = new ChannelWrapper(c, ch); wr.OnStateChanged += this.ChannelStateChanged; wr.Channel.AddStateListener(new Action<ChannelState>(wr.StateChanged)); Channels.Add(wr); } break; } } }
private void refresh_channels(ChannelWrapper updated) { this.BeginInvoke(new Action(refresh_channels2)); }