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); } }
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(); } }