Exemplo n.º 1
0
 /// <summary>
 /// Closes network connection.
 /// </summary>
 /// <param name="eventSender"></param>
 /// <param name="eventArgs"></param>
 private void CloseBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
 {
     try
     {
         Net1.Close();
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
     }
 }
Exemplo 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();
            }
        }
Exemplo n.º 3
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogWarning("Notify service is stopping.");
     if (notify != null)
     {
         notify.OnReceived -= OnNotifyReceived;
         notify.Close();
     }
     return(Task.CompletedTask);
 }
Exemplo n.º 4
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogWarning("Listener service is stopping.");
     if (listener != null)
     {
         if (listener.Protocol == NetworkType.Tcp)
         {
             listener.OnClientConnected -= GXListener.OnClientConnected;
         }
         else
         {
             listener.OnReceived -= GXListener.OnOnReceived;
         }
         listener.Close();
     }
     return(Task.CompletedTask);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Close connection to the meter.
 /// </summary>
 public void Close()
 {
     if (Media != null && Client != null)
     {
         try
         {
             Console.WriteLine("Disconnecting from the meter.");
             GXReplyData reply = new GXReplyData();
             ReadDLMSPacket(Client.DisconnectRequest(), reply);
             Media.Close();
         }
         catch
         {
         }
         Media  = null;
         Client = null;
     }
 }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }        
Exemplo n.º 8
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();
     }
 }