static void Main(string[] args) { IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(); mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional var channel = mgr.AddTCPClient("client", LogLevel.INFO, 5000, "127.0.0.1", 20000); //optionally, add a listener for the channel state channel.AddStateListener(state => Console.WriteLine("Client state: " + state)); var config = new MasterStackConfig(); config.link.useConfirms = true; //setup your stack configuration here. var master = channel.AddMaster("master", LogLevel.INFO, PrintingDataObserver.Instance, config); //optionally, add a listener for the stack state master.AddStateListener(state => Console.WriteLine("Master state: " + state)); Console.WriteLine("Enter an index to send a command"); while (true) { System.UInt32 index = System.UInt32.Parse(Console.ReadLine()); var future = master.GetCommandProcessor().SelectAndOperate(new ControlRelayOutputBlock(ControlCode.CC_PULSE, 1, 100, 100), index); CommandStatus result = future.Await(); Console.WriteLine("Result: " + result); } }
private void MasterSettingsForm_FormClosed(object sender, FormClosedEventArgs e) { if (DialogResult == DialogResult.OK && OnAddMaster != null) { MasterStackConfig config = new MasterStackConfig(); config.link = this.linkLayerSettingsControl1.Config; OnAddMaster(this.textBoxName.Text, FilterLevel.LEV_INTERPRET, config); } }
public override void Run() { var masterStack = new MasterStackConfig(); masterStack.link.localAddr = 1; masterStack.link.remoteAddr = 10; master = GetMaster(masterStack); var integrityPoll = master.AddClassScan(ClassField.AllEventClasses, TimeSpan.FromMilliseconds(500), TaskConfig.Default); master.Enable(); }
void dialog_OnAddMaster(String name, FilterLevel level, MasterStackConfig config, TreeNode portNode) { if (this.OnAddMaster != null) { if (portNode.Nodes.ContainsKey(name)) { MessageBox.Show("Port already contains a stack called: " + name); } else { this.OnAddMaster(name, portNode.Text, level, config); TreeNode master = portNode.Nodes.Add(name, name); EventHandler removeStackAction = (obj, e) => this.RemoveStackClick(portNode, master); master.ContextMenuStrip = this.WireNewMasterMenuStrip(removeStackAction); } } }
public static void InitDeviceConnection(CIMData.SCADAInfo scadaDev) { IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1); //mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional UInt16 sport = Convert.ToUInt16(scadaDev.Dnp.Port); scadaDev.Channel = mgr.AddTCPClient(scadaDev.Name, LogLevels.ALL, ChannelRetry.Default, scadaDev.Dnp.IPAddress, sport); //optionally, add a listener for the channel state scadaDev.Channel.AddStateListener(state => Console.WriteLine("channel state: " + state + " for dev: " + scadaDev.Name + " addr: " + scadaDev.Dnp.IPAddress)); var config = new MasterStackConfig(); //setup your stack configuration here. UInt16 laddr = Convert.ToUInt16(scadaDev.Dnp.LocalAddress); UInt16 raddr = Convert.ToUInt16(scadaDev.Dnp.RemoteAddress); config.link.localAddr = laddr; config.link.remoteAddr = raddr; var key = new byte[16]; for (int i = 0; i < key.Length; ++i) { key[i] = 0xFF; } HandleSOEData hse = new HandleSOEData(scadaDev); scadaDev.Master = scadaDev.Channel.AddMaster("master", hse.getInstance(), DefaultMasterApplication.Instance, config); // you a can optionally add various kinds of polls var integrityPoll = scadaDev.Master.AddClassScan(ClassField.AllClasses, TimeSpan.FromMinutes(1), TaskConfig.Default); scadaDev.Master.Enable(); scadaDev.Connected = true; }
static void Main(string[] args) { var sm = new StackManager(); sm.AddLogHandler(new PrintingLogAdapter()); //this is optional sm.AddTCPv4Client("client", FilterLevel.LEV_INFO, 5000, "127.0.0.1", 20000); var config = new MasterStackConfig(); config.link.useConfirms = true; //setup your stack configuration here. var commandAcceptor = sm.AddMaster("client", "master", FilterLevel.LEV_INFO, new PrintingDataObserver(), config); Console.WriteLine("Enter an index to send a command"); while (true) { System.UInt32 index = System.UInt32.Parse(Console.ReadLine()); DateTime start = DateTime.Now; var future = commandAcceptor.AcceptCommand(new BinaryOutput(ControlCode.CC_PULSE, 1, 100, 100), index); CommandStatus result = future.Await(); DateTime end = DateTime.Now; TimeSpan duration = end - start; Console.WriteLine("Result: " + result + " and took " + duration.Ticks + " Ticks"); } }
static int Main(string[] args) { IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, PrintingLogAdapter.Instance); var channel = mgr.AddTCPClient("client", LogLevels.ALL, ChannelRetry.Default, "127.0.0.1", 20000); //optionally, add a listener for the channel state channel.AddStateListener(state => Console.WriteLine("channel state: " + state)); var config = new MasterStackConfig(); //setup your stack configuration here. config.link.localAddr = 1; config.link.remoteAddr = 10; var key = new byte[16]; for (int i = 0; i < key.Length; ++i) { key[i] = 0xFF; } var master = channel.AddMaster("master", PrintingSOEHandler.Instance, DefaultMasterApplication.Instance, config); // you a can optionally add various kinds of polls var integrityPoll = master.AddClassScan(ClassField.AllClasses, TimeSpan.FromMinutes(1), TaskConfig.Default); var rangePoll = master.AddRangeScan(30, 2, 5, 7, TimeSpan.FromSeconds(20), TaskConfig.Default); var classPoll = master.AddClassScan(ClassField.AllEventClasses, TimeSpan.FromSeconds(5), TaskConfig.Default); /* you can also do very custom scans * var headers = new Header[] { Header.Range8(1, 2, 7, 8), Header.Count8(2, 3, 7) }; * var weirdPoll = master.AddScan(headers, TimeSpan.FromSeconds(20)); */ master.Enable(); // enable communications Console.WriteLine("Enter a command"); while (true) { switch (Console.ReadLine()) { case "a": // perform an ad-hoc scan of all analogs master.ScanAllObjects(30, 0, TaskConfig.Default); break; case "c": var task = master.SelectAndOperate(GetCommandHeaders(), TaskConfig.Default); task.ContinueWith((result) => Console.WriteLine("Result: " + result.Result)); break; case "o": var crob = new ControlRelayOutputBlock(ControlCode.PULSE_ON, 1, 100, 100); var single = master.SelectAndOperate(crob, 1, TaskConfig.Default); single.ContinueWith((result) => Console.WriteLine("Result: " + result.Result)); break; case "l": // add interpretation to the current logging level var filters = channel.GetLogFilters(); channel.SetLogFilters(filters.Add(LogFilters.TRANSPORT_TX | LogFilters.TRANSPORT_RX)); break; case "i": integrityPoll.Demand(); break; case "r": rangePoll.Demand(); break; case "e": classPoll.Demand(); break; case "x": return(0); default: break; } } }
protected virtual IMaster GetMaster(MasterStackConfig config) { return(channel.AddMaster("master", dataHandler, DefaultMasterApplication.Instance, config)); }
public static void InitDeviceConnection(CIMData.SCADAInfo scadaDev) { try { Console.WriteLine("init dev 0"); IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1); //mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional UInt16 sport = Convert.ToUInt16(scadaDev.Dnp.Port); Console.WriteLine("init dev 1"); scadaDev.Channel = mgr.AddTCPClient(scadaDev.Name, LogLevels.ALL, ChannelRetry.Default, scadaDev.Dnp.IPAddress, sport); Console.WriteLine("init dev 2"); //optionally, add a listener for the channel state scadaDev.Channel.AddStateListener(state => Console.WriteLine("channel state: " + state + " for dev: " + scadaDev.Name + " addr: " + scadaDev.Dnp.IPAddress)); Console.WriteLine("init dev 3"); var config = new MasterStackConfig(); Console.WriteLine("init dev 4"); //setup your stack configuration here. UInt16 laddr = Convert.ToUInt16(scadaDev.Dnp.LocalAddress); UInt16 raddr = Convert.ToUInt16(scadaDev.Dnp.RemoteAddress); config.link.localAddr = laddr; config.link.remoteAddr = raddr; var key = new byte[16]; for (int i = 0; i < key.Length; ++i) { key[i] = 0xFF; } HandleSOEData hse = new HandleSOEData(scadaDev); scadaDev.Master = scadaDev.Channel.AddMaster("master", hse.getInstance(), DefaultMasterApplication.Instance, config); double intscan; if ((!Double.TryParse(scadaDev.Dnp.IntegrityScanRate, out intscan)) || (intscan <= 0)) { intscan = 60000; Console.WriteLine("Invalid integrity scan - defaulting to 1 minute"); } var integrityPoll = scadaDev.Master.AddClassScan(ClassField.AllClasses, TimeSpan.FromMilliseconds(intscan), TaskConfig.Default); scadaDev.Master.Enable(); } catch (Exception e) { Console.WriteLine("error on initialization :{0} " + e); } scadaDev.Connected = true; }
private void stackBrowser1_OnAddMaster(string name, string port, FilterLevel level, MasterStackConfig config) { var observer = new EventedDataObserver(this); var control = this.stackDisplayControl.AddMaster(name, observer.MeasurementSource); control.CommandAcceptor = sm.AddMaster(port, name, level, observer, config); }
static int Main(string[] args) { var application = new MasterApplicatonSA(); IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(); Console.WriteLine(String.Format("Crypto: {0}", mgr.SSLVersion())); mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional var channel = mgr.AddTCPClient("client", LogLevels.NORMAL, ChannelRetry.Default, "127.0.0.1", 20000); //optionally, add a listener for the channel state channel.AddStateListener(state => Console.WriteLine("channel state: " + state)); var config = new MasterStackConfig(); //setup your stack configuration here. config.link.localAddr = 1; config.link.remoteAddr = 10; var master = channel.AddMasterSA("master", PrintingSOEHandler.Instance, application, config); // define users on the master master.AddUser(User.Default, UpdateKey.Demo(0xFF, KeyWrapAlgorithm.AES_128)); // you a can optionally add various kinds of polls var integrityPoll = master.AddClassScan(ClassField.AllClasses, TimeSpan.FromMinutes(1), TaskConfig.Default); var rangePoll = master.AddRangeScan(30, 2, 5, 7, TimeSpan.FromSeconds(20), TaskConfig.Default); var classPoll = master.AddClassScan(ClassField.AllEventClasses, TimeSpan.FromSeconds(5), TaskConfig.Default); /* you can also do very custom scans * var headers = new Header[] { Header.Range8(1, 2, 7, 8), Header.Count8(2, 3, 7) }; * var weirdPoll = master.AddScan(headers, TimeSpan.FromSeconds(20)); */ master.Enable(); // enable communications Console.WriteLine("Enter a command"); while (true) { switch (Console.ReadLine()) { case "a": // perform an ad-hoc scan of all analogs master.ScanAllObjects(30, 0, TaskConfig.Default); break; case "c": var crob = new ControlRelayOutputBlock(ControlCode.PULSE_ON, 1, 100, 100); var commands = CommandHeader.From(IndexedValue.From(crob, 0)); var task = master.SelectAndOperate(commands, TaskConfig.With(User.Default)); task.ContinueWith((result) => Console.WriteLine("Result: " + result.Result)); break; case "l": // add interpretation to the current logging level var filters = channel.GetLogFilters(); channel.SetLogFilters(filters.Add(LogFilters.TRANSPORT_TX | LogFilters.TRANSPORT_RX)); break; case "i": integrityPoll.Demand(); break; case "r": rangePoll.Demand(); break; case "e": classPoll.Demand(); break; case "x": return(0); default: break; } } }
static int Main(string[] args) { IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(); mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional var channel = mgr.AddTCPClient("client", LogLevels.NORMAL, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2), "127.0.0.1", 20000); //optionally, add a listener for the channel state channel.AddStateListener(state => Console.WriteLine("channel state: " + state)); var config = new MasterStackConfig(); //setup your stack configuration here. config.link.localAddr = 1; config.link.remoteAddr = 10; var master = channel.AddMaster("master", PrintingSOEHandler.Instance, DefaultMasterApplication.Instance, config); // you a can optionally add various kinds of polls var integrityPoll = master.AddClassScan(ClassField.AllClasses, TimeSpan.FromMinutes(1)); var rangePoll = master.AddRangeScan(30, 2, 5, 7, TimeSpan.FromSeconds(20)); var classPoll = master.AddClassScan(ClassField.AllEventClasses, TimeSpan.FromSeconds(5)); // you a can optionally add state callbacks for monitoring these polls integrityPoll.AddScanCallback((PollState state) => Console.WriteLine("integrity poll state change: " + state)); classPoll.AddScanCallback((PollState state) => Console.WriteLine("class poll state change: " + state)); rangePoll.AddScanCallback((PollState state) => Console.WriteLine("range poll state change: " + state)); master.Enable(); // enable communications Console.WriteLine("Enter an index to send a command"); while (true) { switch (Console.ReadLine()) { case "c": var crob = new ControlRelayOutputBlock(ControlCode.PULSE, 1, 100, 100); var future = master.GetCommandProcessor().SelectAndOperate(crob, 0); future.Listen((result) => Console.WriteLine("Result: " + result)); break; case "l": // add interpretation to the current logging level var filters = channel.GetLogFilters(); channel.SetLogFilters(filters.Add(LogFilters.TRANSPORT_TX | LogFilters.TRANSPORT_RX)); break; case "i": integrityPoll.Demand(); break; case "r": rangePoll.Demand(); break; case "e": classPoll.Demand(); break; case "x": return(0); default: break; } } }