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)); }
static void Main(string[] args) { Core.Start(); SnmpTarget retAbelSantana = new SnmpTarget("10.7.5.150"); retAbelSantana.InsertObject("batteryTemperaturesValue", ".1.3.6.1.4.1.12148.10.10.7.5.0"); SnmpV2Packet result = retAbelSantana.GetUpdate(); IPEndpoint myEndPoint = new IPEndpoint("0.0.0.0", 20500); Rtu rtu = new Rtu("Teste DNP3", myEndPoint, 2, 1); ChangeSet changeSet; int currentValue; while (true) { if (result != null) { changeSet = new ChangeSet(); if (result.Pdu.ErrorStatus != 0) { Console.WriteLine("Error in SNMP reply. Error {0} index {1}", result.Pdu.ErrorStatus, result.Pdu.ErrorIndex); } else { currentValue = Convert.ToInt32(result.Pdu.VbList[0].Value.ToString()); changeSet.Update(new Analog(currentValue, 1, DateTime.Now), 0); Console.WriteLine("Atualizando valor da analógica para " + currentValue); rtu.Outstation.Load(changeSet); } } else { Console.WriteLine("Erro SNMP Nulo"); } Thread.Sleep(15000); } }