コード例 #1
0
ファイル: Rtu.cs プロジェクト: AKllX/Gemini
        public Rtu(int id, string name, IPEndpoint clientAddress, IPEndpoint hostAddres, ushort localDNP3Addres, ushort remoteDNP3Address,
            Dictionary<int, int> bins, Dictionary<int, int> analogs, Dictionary<int, int> counters, DatabaseTemplate dt, GeminiMap gmap)
        {
            Id = id;
            Name = name;
            //Considerando uma RTU por Canal
            if (Core.LoggingEnabled)
            {
                Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.ALL, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print());
            }
            else
            {
                Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.NONE, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print());
            }

            //Configuração Padrão de RTU é Outstation
            Config = new OutstationStackConfig
            {
                databaseTemplate = dt
            };
            Config.link.remoteAddr = remoteDNP3Address;
            Config.link.localAddr = localDNP3Addres;
            DNP3ToSNMPBinaries = bins;
            DNP3ToSNMPAnalogs = analogs;
            DNP3ToSNMPCounters = counters;
            Outstation = Channel.AddOutstation(name, RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, Config);
            Outstation.Enable();
            geminiMap = gmap;

            Target = new SnmpTarget(clientAddress.address, clientAddress.port, Core.Settings.SNMPTimeout, Core.Settings.SNMPRetry);

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPBinaries)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPAnalogs)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPCounters)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            MonitorThread = new Timer(new TimerCallback(Update), null, TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(Core.Settings.GatewayPoolingTime));
        }
コード例 #2
0
        static int Main(string[] args)
        {
            IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, new PrintingLogAdapter());

            var channel = mgr.AddTCPClient(
                "client",
                LogLevels.NORMAL | LogLevels.APP_COMMS,
                new ChannelRetry(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(5)),
                new List <IPEndpoint> {
                new IPEndpoint("127.0.0.1", 20000)
            },
                ChannelListener.Print()
                );

            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), PrintingSOEHandler.Instance, TaskConfig.Default);
            var rangePoll     = master.AddRangeScan(30, 2, 5, 7, TimeSpan.FromSeconds(20), PrintingSOEHandler.Instance, TaskConfig.Default);
            var classPoll     = master.AddClassScan(ClassField.AllEventClasses, TimeSpan.FromSeconds(5), PrintingSOEHandler.Instance, 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, PrintingSOEHandler.Instance, 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(OperationType.PULSE_ON, TripCloseCode.NUL, false, 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;
                }
            }
        }
コード例 #3
0
ファイル: RTU.cs プロジェクト: lailasr/Gemini
        public Rtu(string name, IPEndpoint hostAddres, ushort localDNP3Addres, ushort remoteDNP3Address)
        {
            //Considerando uma RTU por Canal
            Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.ALL, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print());
            Config  = new OutstationStackConfig();
            Config.databaseTemplate = new DatabaseTemplate(4, 0, 1, 1, 1, 1, 1, 0, 0);
            Config.databaseTemplate.analogs[0].clazz  = PointClass.Class2;
            Config.outstation.config.allowUnsolicited = false;
            Config.link.remoteAddr = remoteDNP3Address;
            Config.link.localAddr  = localDNP3Addres;

            Outstation = Channel.AddOutstation(name, RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, Config);
            Outstation.Enable();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: MPapst/dnp3
        static int Main(string[] args)
        {
            IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, new PrintingLogAdapter());

            var channel = mgr.AddTCPServer("server", LogLevels.NORMAL, ServerAcceptMode.CloseExisting, new IPEndpoint("0.0.0.0", 20000), ChannelListener.Print());

            var config = new OutstationStackConfig();

            // configure the various measurements in our database
            config.databaseTemplate.binary.Add(3, new BinaryConfig());
            config.databaseTemplate.binary.Add(7, new BinaryConfig());
            config.databaseTemplate.analog.Add(0, new AnalogConfig());
            // ....
            config.outstation.config.allowUnsolicited = true;

            // Optional: setup your stack configuration here
            config.link.localAddr  = 10;
            config.link.remoteAddr = 1;

            var outstation = channel.AddOutstation("outstation", RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, config);

            outstation.Enable(); // enable communications

            Console.WriteLine("Press <Enter> to change a value");
            bool   binaryValue = false;
            double analogValue = 0;

            while (true)
            {
                switch (Console.ReadLine())
                {
                case ("x"):
                    return(0);

                default:
                {
                    binaryValue = !binaryValue;
                    ++analogValue;

                    // create a changeset and load it
                    var changeset = new ChangeSet();

                    var binaryFlags = new Flags();
                    binaryFlags.Set(BinaryQuality.ONLINE);

                    var analogFlags = new Flags();
                    analogFlags.Set(AnalogQuality.ONLINE);


                    changeset.Update(new Binary(binaryValue, binaryFlags, new DNPTime(DateTime.UtcNow)), 3);
                    changeset.Update(new Analog(analogValue, analogFlags, DNPTime.Now), 0);
                    outstation.Load(changeset);
                }
                break;
                }
            }
        }
コード例 #5
0
        static int Main(string[] args)
        {
            IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, new PrintingLogAdapter());

            var channel = mgr.AddTCPServer("server", LogLevels.NORMAL, ChannelRetry.Default, "0.0.0.0", 20000, ChannelListener.Print());

            var config = new OutstationStackConfig();

            // configure the various measurements in our database
            config.databaseTemplate = new DatabaseTemplate(4, 1, 1, 1, 1, 1, 1, 0);
            config.databaseTemplate.binaries[0].clazz = PointClass.Class2;
            // ....
            config.outstation.config.allowUnsolicited = true;

            // Optional: setup your stack configuration here
            config.link.localAddr  = 10;
            config.link.remoteAddr = 1;

            var outstation = channel.AddOutstation("outstation", RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, config);

            outstation.Enable(); // enable communications

            Console.WriteLine("Press <Enter> to change a value");
            bool   binaryValue = false;
            double analogValue = 0;

            while (true)
            {
                switch (Console.ReadLine())
                {
                case ("x"):
                    return(0);

                default:
                {
                    binaryValue = !binaryValue;
                    ++analogValue;

                    // create a changeset and load it
                    var changeset = new ChangeSet();
                    changeset.Update(new Binary(binaryValue, 1, DateTime.Now), 0);
                    changeset.Update(new Analog(analogValue, 1, DateTime.Now), 0);
                    outstation.Load(changeset);
                }
                break;
                }
            }
        }