Example #1
0
        static int Main(string[] args)
        {
            IDNP3Manager mgr = DNP3ManagerFactory.CreateManager(1, new PrintingLogAdapter());
            //一個管理者
            var channel = mgr.AddTCPServer("server", LogLevels.NORMAL, ServerAcceptMode.CloseExisting, new IPEndpoint("127.0.0.1", 20000), ChannelListener.Print());
            //創造一個Channel
            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; // outstation ip
            config.link.remoteAddr = 1;  //master addr

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

            //把設定檔丟到Channel物件裡面
            outstation.Enable(); // enable communications

            Console.WriteLine("Press <Enter> to change a value");
            //要放進去暫存器的數值
            bool   binaryValue = false;
            double analogValue = 0;

            while (true)
            { //按下 Enter 會改變二元值 跟增加類比數值
                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;
                }
            }
        }
Example #2
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);

            // Optional: add a listener for the channel state
            channel.AddStateListener(state => Console.WriteLine("channel state: " + state));

            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;
                    System.Console.WriteLine("Change Binary 0 to: " + binaryValue);
                    System.Console.WriteLine("Change Analog 9 to: " + 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;
                }
            }
        }
Example #3
0
        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();
        }
Example #4
0
File: Rtu.cs Project: 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));
        }
Example #5
0
        static void Main(string[] args)
        {
            IDNP3Manager mgr = DNP3ManagerFactory.CreateManager();

            mgr.AddLogHandler(PrintingLogAdapter.Instance); //this is optional
            var channel = mgr.AddTCPServer("server", LogLevels.NORMAL, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), "0.0.0.0", 20000);

            // Optional: add a listener for the channel state
            channel.AddStateListener(state => Console.WriteLine("channel state: " + state));

            var config = new OutstationStackConfig();

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

            // Optional: overide the default reporting variations
            config.outstation.eventConfig.binary  = EventBinaryResponse.Group2Var2;
            config.outstation.staticConfig.analog = StaticAnalogResponse.Group30Var5;

            // 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 randomly change a value");
            var  database = outstation.GetDatabase();
            bool value    = false;

            while (true)
            {
                Console.ReadLine();
                value = !value;
                System.Console.WriteLine("Change Binary 1 to: " + value);
                database.Start();
                database.Update(new Binary(value, 1, DateTime.Now), 0);
                database.End();
            }
        }
        public OutstationDialog(IDNP3Config config, IOutstationModule module)
        {
            InitializeComponent();

            this.config = config;
            this.initialConfig = module.DefaultConfig;
            this.allowTemplateEdit = module.AllowTemplateEditing;
            this.textBoxID.Text = module.DefaultLogName;

            this.linkConfigControl.Configuration = initialConfig.link;

            if (allowTemplateEdit)
            {
                comboBoxTemplate.DataSource = config.Templates.Select(kv => kv.Key).ToList();
            }
            else
            {
                groupBoxDatabase.Enabled = false;
            }
        }
Example #7
0
        public OutstationDialog(IDNP3Config config, IOutstationModule module)
        {
            InitializeComponent();

            this.config            = config;
            this.initialConfig     = module.DefaultConfig;
            this.allowTemplateEdit = module.AllowTemplateEditing;
            this.textBoxID.Text    = module.DefaultLogName;

            this.linkConfigControl.Configuration = initialConfig.link;

            if (allowTemplateEdit)
            {
                comboBoxTemplate.DataSource = config.Templates.Select(kv => kv.Key).ToList();
            }
            else
            {
                groupBoxDatabase.Enabled = false;
            }
        }
        private void ConfigureOutstation()
        {
            var outstationConfig = new OutstationStackConfig();

            // configure the various measurements in our database
            //outstationConfig.databaseTemplate = new DatabaseTemplate(4, 1, 1, 1, 1, 1, 1, 0);
            outstationConfig.databaseTemplate = new DatabaseTemplate(
                (ushort)0,
                (ushort)0,
                (ushort)255,
                (ushort)0,
                (ushort)0,
                (ushort)0,
                (ushort)0,
                (ushort)0);

            var template = outstationConfig.databaseTemplate;


            outstationConfig.outstation.config.allowUnsolicited = true;

            outstationConfig.link.localAddr  = 10;
            outstationConfig.link.remoteAddr = 1;
            outstationConfig.outstation.buffer.maxAnalogEvents             = (uint)random.Next();
            outstationConfig.outstation.buffer.maxAnalogOutputStatusEvents = (uint)random.Next();
            outstationConfig.outstation.buffer.maxBinaryEvents             = (uint)random.Next();
            outstationConfig.outstation.buffer.maxBinaryOutputStatusEvents = (uint)random.Next();
            outstationConfig.outstation.buffer.maxCounterEvents            = (uint)random.Next();
            outstationConfig.outstation.buffer.maxDoubleBinaryEvents       = (uint)random.Next();
            outstationConfig.outstation.buffer.maxFrozenCounterEvents      = (uint)random.Next();

            outstation = channel.AddOutstation("outstation", RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, outstationConfig);
            if (outstation != null)
            {
                outstation.Enable(); // enable communications
            }
        }
Example #9
0
 IOutstationInstance IOutstationFactory.CreateInstance(IOutstation outstation, string name, OutstationStackConfig config)
 {
     return(new OutstationInstance(commandHandler, application, outstation, config, name));
 }
Example #10
0
        public OutstationInstance(ProxyCommandHandler handler, EventedOutstationApplication application, IOutstation outstation, OutstationStackConfig config, string alias)
        {
            this.handler     = handler;
            this.application = application;
            this.outstation  = outstation;
            this.alias       = alias;

            this.cache = new MeasurementCache(config.databaseTemplate);
        }
        public OutstationInstance(ProxyCommandHandler handler, EventedOutstationApplication application, IOutstation outstation, OutstationStackConfig config, string alias)
        {
            this.handler = handler;
            this.application = application;
            this.outstation = outstation;
            this.alias = alias;

            this.cache = new MeasurementCache(config.databaseTemplate);
        }
 IOutstationInstance IOutstationFactory.CreateInstance(IOutstation outstation, string name, OutstationStackConfig config)
 {
     return new OutstationInstance(commandHandler, application, outstation, config, name);
 }
        public OutstationInstance(ProxyCommandHandler handler, EventedOutstationApplication application, IOutstation outstation, OutstationStackConfig config, string alias)
        {
            this.handler = handler;
            this.application = application;
            this.outstation = outstation;
            this.alias = alias;

            this.form = new OutstationForm(outstation, handler);
        }
Example #14
0
        public OutstationInstance(ProxyCommandHandler handler, EventedOutstationApplication application, IOutstation outstation, OutstationStackConfig config, string alias)
        {
            this.handler     = handler;
            this.application = application;
            this.outstation  = outstation;
            this.alias       = alias;

            this.form = new OutstationForm(outstation, handler);
        }