Esempio n. 1
0
        public GXNotifyService(ILogger <GXNotifyService> logger, IOptions <NotifyOptions> optionsAccessor)
        {
            _useLogicalNameReferencing = optionsAccessor.Value.UseLogicalNameReferencing;
            _systemTitle       = optionsAccessor.Value.SystemTitle;
            _blockCipherKey    = optionsAccessor.Value.BlockCipherKey;
            _interfaceType     = optionsAccessor.Value.Interface;
            _logger            = logger;
            notify             = new GXNet((NetworkType)optionsAccessor.Value.NetworkType, optionsAccessor.Value.Port);
            ExpirationTime     = optionsAccessor.Value.ExpirationTime;
            notify.OnReceived += OnNotifyReceived;
            _logger.LogInformation("Listening notifications in port: " + notify.Port);
            notify.Open();

            /*
             * if (!string.IsNullOrEmpty(n.Parser))
             * {
             * string[] tmp = n.Parser.Split(";");
             * //GXNotifyListener.Parser = new Gurux.DLMS.AMI.NotifyParser.GXNotifyParser();
             * string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), tmp[0]);
             * Assembly asm = Assembly.LoadFile(path);
             * foreach (Type type in asm.GetTypes())
             * {
             *    //if (!type.IsAbstract && type.IsClass && typeof(IGXNotifyParser).IsAssignableFrom(type))
             *    {
             *        GXNotifyListener.Parser = Activator.CreateInstance(type) as IGXNotifyParser;
             *        break;
             *    }
             * }
             * //GXNotifyListener.Parser = asm.CreateInstance(tmp[1]) as IGXNotifyParser;
             * }
             */
        }
Esempio n. 2
0
        void SendPush(GXDLMSPushSetup target)
        {
            int pos = target.Destination.IndexOf(':');

            if (pos == -1)
            {
                throw new ArgumentException("Invalid destination.");
            }
            GXDLMSNotify notify = new GXDLMSNotify(true, 1, 1, InterfaceType.WRAPPER);

            byte[][] data = notify.GeneratePushSetupMessages(DateTime.MinValue, target);
            string   host = target.Destination.Substring(0, pos);
            int      port = int.Parse(target.Destination.Substring(pos + 1));
            GXNet    net  = new GXNet(NetworkType.Tcp, host, port);

            try
            {
                net.Open();
                foreach (byte[] it in data)
                {
                    net.Send(it, null);
                }
            }
            finally
            {
                net.Close();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Read selected item.
 /// </summary>
 /// <param name="eventSender"></param>
 /// <param name="eventArgs"></param>
 private void IntervalTimer_Tick(System.Object eventSender, System.EventArgs eventArgs)
 {
     try
     {
         if (!Net1.IsOpen)
         {
             Net1.Open();
             System.Threading.Thread.Sleep(400);
             Net1.Close();
             return;
         }
         SendBtn_Click(SendBtn, new System.EventArgs());
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="port">Port to listen.</param>
 public GXDLMSPushListener(int port)
 {
     // TODO: Must set communication specific settings.
     media                       = new GXNet(NetworkType.Tcp, port);
     media.Trace                 = TraceLevel.Verbose;
     media.OnReceived           += new Gurux.Common.ReceivedEventHandler(OnReceived);
     media.OnClientConnected    += new Gurux.Common.ClientConnectedEventHandler(OnClientConnected);
     media.OnClientDisconnected += new Gurux.Common.ClientDisconnectedEventHandler(OnClientDisconnected);
     media.OnError              += new Gurux.Common.ErrorEventHandler(OnError);
     media.Open();
 }
Esempio n. 5
0
        public Startup(IConfiguration configuration)
        {
            int port = configuration.GetSection("Listener").Get <ListenerOptions>().Port;

            if (port != 0)
            {
                listener = new GXNet(NetworkType.Tcp, port);
                listener.OnClientConnected += OnClientConnected;
                Console.WriteLine("Listening port:" + listener.Port);
                listener.Open();
            }
            Configuration = configuration;
            ServerAddress = configuration.GetSection("Client").Get <ClientOptions>().Address;
            Console.WriteLine("RestAddress: " + ServerAddress);
        }
Esempio n. 6
0
        public GXListenerService(ILogger <GXListenerService> logger, IOptions <ListenerOptions> optionsAccessor)
        {
            _logger = logger;
            int port = optionsAccessor.Value.Port;

            GXListener._logger = logger;
            listener           = new GXNet((NetworkType)optionsAccessor.Value.NetworkType, port);
            if (listener.Protocol == NetworkType.Tcp)
            {
                listener.OnClientConnected += GXListener.OnClientConnected;
            }
            else
            {
                listener.OnReceived += GXListener.OnOnReceived;
            }
            _logger.LogInformation("Listening incoming connections in port:" + listener.Port);
            listener.Open();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            try
            {
                int   port  = 4059;
                GXNet media = new GXNet(NetworkType.Tcp, "localhost", port);
                GXDLMSSecureNotify notify = new GXDLMSSecureNotify(true, 16, 1, InterfaceType.WRAPPER);
                // Un-comment this if you want to send encrypted push messages.
                // notify.Ciphering.Security = Security.AuthenticationEncryption;
                GXDLMSPushSetup p     = new GXDLMSPushSetup();
                GXDLMSClock     clock = new GXDLMSClock();
                p.PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(p, new GXDLMSCaptureObject(2, 0)));
                p.PushObjectList.Add(new KeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(clock, new GXDLMSCaptureObject(2, 0)));

                ///////////////////////////////////////////////////////////////////////
                //Create Gurux DLMS server component for Short Name and start listen events.
                GXDLMSPushListener pushListener = new GXDLMSPushListener(port);
                Console.WriteLine("Listening DLMS Push IEC 62056-47 messages on port " + port + ".");
                Console.WriteLine("Press X to close and Enter to send a Push message.");
                ConsoleKey key;
                while ((key = Console.ReadKey().Key) != ConsoleKey.X)
                {
                    if (key == ConsoleKey.Enter)
                    {
                        Console.WriteLine("Sending Push message.");
                        media.Open();
                        clock.Time = DateTime.Now;
                        foreach (byte[] it in notify.GeneratePushSetupMessages(DateTime.MinValue, p))
                        {
                            media.Send(it, null);
                        }
                        Thread.Sleep(100);
                        media.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 8
0
 static void Main(string[] args)
 {
     try
     {
         GXNet server = new GXNet(NetworkType.Tcp, 7777);
         server.Open();
         server.OnClientConnected    += OnClientConnected;
         server.OnClientDisconnected += OnClientDisconnected;
         server.OnReceived           += OnReceived;
         Console.WriteLine("This server is listening port {0} and waiting incoming connections from the meters.", server.Port);
         Console.WriteLine("This server can be used with DLMS meters that are using dynamic IP addresses.");
         while (Console.ReadKey().Key != ConsoleKey.Enter)
         {
             ;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 9
0
        static void Main(string[] args)
        {
            try
            {
                int port = 4059;
                GXNet media = new GXNet(NetworkType.Tcp, "localhost", port);
                GXDLMSNotify cl = new GXDLMSNotify(true, 1, 1, InterfaceType.WRAPPER);
                GXDLMSPushSetup p = new GXDLMSPushSetup();
                GXDLMSClock clock = new GXDLMSClock();
                p.PushObjectList.Add(new KeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(p, new GXDLMSCaptureObject(2, 0)));
                p.PushObjectList.Add(new KeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(clock, new GXDLMSCaptureObject(2, 0)));

                ///////////////////////////////////////////////////////////////////////
                //Create Gurux DLMS server component for Short Name and start listen events.
                GXDLMSPushListener pushListener = new GXDLMSPushListener(port);
                Console.WriteLine("Listening DLMS Push IEC 62056-47 messages on port " + port + ".");
                Console.WriteLine("Press X to close and Enter to send a Push message.");
                ConsoleKey key;
                while ((key = Console.ReadKey().Key) != ConsoleKey.X)
                {
                    if (key == ConsoleKey.Enter)
                    {
                        Console.WriteLine("Sending Push message.");
                        media.Open();
                        clock.Time = DateTime.Now;
                        foreach (byte[] it in cl.GeneratePushSetupMessages(DateTime.MinValue, p))
                        {
                            media.Send(it, null);
                        }
                        Thread.Sleep(100);
                        media.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }        
Esempio n. 10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="port">Port to listen.</param>
 public GXDLMSPushListener(int port)
     : base(true, 1, 1, InterfaceType.WRAPPER)
 {
     // TODO: Must set communication specific settings.
     media = new GXNet(NetworkType.Tcp, port);
     media.Trace = TraceLevel.Verbose;
     media.OnReceived += new Gurux.Common.ReceivedEventHandler(OnReceived);
     media.OnClientConnected += new Gurux.Common.ClientConnectedEventHandler(OnClientConnected);
     media.OnClientDisconnected += new Gurux.Common.ClientDisconnectedEventHandler(OnClientDisconnected);
     media.OnError += new Gurux.Common.ErrorEventHandler(OnError);
     media.Open();
 }
Esempio n. 11
0
 void SendPush(GXDLMSPushSetup target)
 {
     int pos = target.Destination.IndexOf(':');
     if (pos == -1)
     {
         throw new ArgumentException("Invalid destination.");
     }
     GXDLMSNotify notify = new GXDLMSNotify(true, 1, 1, InterfaceType.WRAPPER);
     byte[][] data = notify.GeneratePushSetupMessages(DateTime.MinValue, target);
     string host = target.Destination.Substring(0, pos);
     int port = int.Parse(target.Destination.Substring(pos + 1));
     GXNet net = new GXNet(NetworkType.Tcp, host, port);
     try
     {
         net.Open();
         foreach (byte[] it in data)
         {
             net.Send(it, null);
         }
     }
     finally
     {
         net.Close();
     }
 }
        /// <summary>
        /// Generic initialize for all servers.
        /// </summary>
        /// <param name="server"></param>
        public void Initialize(int port)
        {
            Media = new GXNet(NetworkType.Tcp, port);
            Media.OnReceived += new Gurux.Common.ReceivedEventHandler(OnReceived);
            Media.OnClientConnected += new Gurux.Common.ClientConnectedEventHandler(OnClientConnected);
            Media.OnClientDisconnected += new Gurux.Common.ClientDisconnectedEventHandler(OnClientDisconnected);
            Media.OnError += new Gurux.Common.ErrorEventHandler(OnError);
            Media.Open();
            ///////////////////////////////////////////////////////////////////////
            //Add Logical Device Name. 123456 is meter serial number.
            GXDLMSData d = new GXDLMSData("0.0.42.0.0.255");
            d.Value = "Gurux123456";
            //Set access right. Client can't change Device name.
            d.SetAccess(2, AccessMode.Read);
            //Value is get as Octet String.
            d.SetDataType(2, DataType.OctetString);
            Items.Add(d);
            //Add Last avarage.
            GXDLMSRegister r = new GXDLMSRegister("1.1.21.25.0.255");
            //Set access right. Client can't change average value.
            r.SetAccess(2, AccessMode.Read);
            Items.Add(r);
            //Add default clock. Clock's Logical Name is 0.0.1.0.0.255.
            GXDLMSClock clock = new GXDLMSClock();
            clock.Begin = new GXDateTime(-1, 9, 1, -1, -1, -1, -1);
            clock.End = new GXDateTime(-1, 3, 1, -1, -1, -1, -1);
            clock.Deviation = 0;
            Items.Add(clock);
            //Add Tcp Udp setup. Default Logical Name is 0.0.25.0.0.255.
            GXDLMSTcpUdpSetup tcp = new GXDLMSTcpUdpSetup();
            Items.Add(tcp);
            ///////////////////////////////////////////////////////////////////////
            //Add Load profile.
            GXDLMSProfileGeneric pg = new GXDLMSProfileGeneric("1.0.99.1.0.255");
            //Set capture period to 60 second.
            pg.CapturePeriod = 60;
            //Maximum row count.
            pg.ProfileEntries = 100;
            pg.SortMethod = SortMethod.FiFo;
            pg.SortObject = clock;
            //Add colums.
            //Set saved attribute index.
            clock.SelectedAttributeIndex = 2;
            pg.CaptureObjects.Add(clock);
            //Set saved attribute index.
            r.SelectedAttributeIndex = 2;
            pg.CaptureObjects.Add(r);
            Items.Add(pg);
            //Add initial rows.
            pg.Buffer.Add(new object[] { DateTime.Now, (int)10 });
            ///////////////////////////////////////////////////////////////////////
            //Add Auto connect object.
            GXDLMSAutoConnect ac = new GXDLMSAutoConnect();
            ac.Mode = AutoConnectMode.AutoDiallingAllowedAnytime;
            ac.Repetitions = 10;
            ac.RepetitionDelay = 60;
            //Calling is allowed between 1am to 6am.
            ac.CallingWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 1, 0, 0, -1), new GXDateTime(-1, -1, -1, 6, 0, 0, -1)));
            ac.Destinations = new string[] { "www.gurux.org"};
            Items.Add(ac);

            ///////////////////////////////////////////////////////////////////////
            //Add Activity Calendar object.
            GXDLMSActivityCalendar activity = new GXDLMSActivityCalendar();
            activity.CalendarNameActive = "Active";            
            activity.SeasonProfileActive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Summer time", new GXDateTime(-1, 3, 31, -1, -1, -1, -1), "")};
            activity.WeekProfileTableActive = new GXDLMSWeekProfile[]{new GXDLMSWeekProfile("Monday", 1, 1, 1, 1, 1, 1, 1)};
            activity.DayProfileTableActive = new GXDLMSDayProfile[]{new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[]{new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "test", 1)})};
            activity.CalendarNamePassive = "Passive";
            activity.SeasonProfilePassive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Winter time", new GXDateTime(-1, 10, 30, -1, -1, -1, -1), "")};
            activity.WeekProfileTablePassive = new GXDLMSWeekProfile[]{new GXDLMSWeekProfile("Tuesday", 1, 1, 1, 1, 1, 1, 1)};
            activity.DayProfileTablePassive = new GXDLMSDayProfile[] { new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[] { new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "0.0.1.0.0.255", 1) }) };
            activity.Time = new GXDateTime(DateTime.Now);
            Items.Add(activity);

            ///////////////////////////////////////////////////////////////////////
            //Add Optical Port Setup object.
            GXDLMSIECOpticalPortSetup optical = new GXDLMSIECOpticalPortSetup();
            optical.DefaultMode = OpticalProtocolMode.Default;
            optical.ProposedBaudrate = BaudRate.Baudrate9600;
            optical.DefaultBaudrate = BaudRate.Baudrate300;
            optical.ResponseTime = LocalPortResponseTime.ms200;
            optical.DeviceAddress = "Gurux";
            optical.Password1 = "Gurux1";
            optical.Password2 = "Gurux2";
            optical.Password5 = "Gurux5";
            Items.Add(optical);

            ///////////////////////////////////////////////////////////////////////
            //Add Demand Register object.
            GXDLMSDemandRegister dr = new GXDLMSDemandRegister();
            dr.LogicalName = "0.0.1.0.0.255";
            dr.CurrentAvarageValue = (uint) 10;
            dr.LastAvarageValue = (uint) 20;
            dr.Status = (byte)1;
            dr.StartTimeCurrent = dr.CaptureTime = new GXDateTime(DateTime.Now);
            dr.Period = 10;
            dr.NumberOfPeriods = 1;
            Items.Add(dr);

            ///////////////////////////////////////////////////////////////////////
            //Add Register Monitor object.
            GXDLMSRegisterMonitor rm = new GXDLMSRegisterMonitor();
            rm.LogicalName = "0.0.1.0.0.255";
            rm.Thresholds = new object[] { (int)0x1234, (int)0x5678 };
            GXDLMSActionSet set = new GXDLMSActionSet();
            set.ActionDown.LogicalName = rm.LogicalName;
            set.ActionDown.ScriptSelector = 1;
            set.ActionUp.LogicalName = rm.LogicalName;
            set.ActionUp.ScriptSelector = 2;            
            rm.Actions = new GXDLMSActionSet[] {set };
            rm.MonitoredValue.Update(r, 2);
            Items.Add(rm);
            
            ///////////////////////////////////////////////////////////////////////
            //Add action schedule object.
            GXDLMSActionSchedule actionS = new GXDLMSActionSchedule();
            actionS.LogicalName = "0.0.1.0.0.255";
            actionS.ExecutedScriptLogicalName = "1.2.3.4.5.6";
            actionS.ExecutedScriptSelector = 1;
            actionS.Type = SingleActionScheduleType.SingleActionScheduleType1;
            actionS.ExecutionTime = new GXDateTime[] {new GXDateTime(DateTime.Now) };
            Items.Add(actionS);            

            ///////////////////////////////////////////////////////////////////////
            //Add SAP Assignment object.
            GXDLMSSapAssignment sap = new GXDLMSSapAssignment();
            sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(1, "Gurux"));
            sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(16, "Gurux-2"));
            Items.Add(sap);

            ///////////////////////////////////////////////////////////////////////
            //Add Auto Answer object.
            GXDLMSAutoAnswer aa = new GXDLMSAutoAnswer();
            aa.Mode = AutoConnectMode.EmailSending;
            aa.ListeningWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 6, -1, -1, -1), new GXDateTime(-1, -1, -1, 8, -1, -1, -1)));
            aa.Status = AutoAnswerStatus.Inactive;
            aa.NumberOfCalls = 0;
            aa.NumberOfRingsInListeningWindow = 1;
            aa.NumberOfRingsOutListeningWindow = 2;
            Items.Add(aa);

            ///////////////////////////////////////////////////////////////////////
            //Add Modem Configuration object.
            GXDLMSModemConfiguration mc = new GXDLMSModemConfiguration();
            mc.CommunicationSpeed = BaudRate.Baudrate57600;
            GXDLMSModemInitialisation init = new GXDLMSModemInitialisation();
            init.Request = "AT";
            init.Response = "OK";
            init.Delay = 0;
            mc.InitialisationStrings = new GXDLMSModemInitialisation[] { init };
            Items.Add(mc);

            ///////////////////////////////////////////////////////////////////////
            //Add Mac Address Setup object.
            GXDLMSMacAddressSetup mac = new GXDLMSMacAddressSetup();
            mac.MacAddress = "00:11:22:33:44:55:66";
            Items.Add(mac);            
            ///////////////////////////////////////////////////////////////////////
            //Server must initialize after all objects are added.
            Initialize();
        }