/// <summary> /// Connect to the meter and try to send HDLC frame that is too big. /// </summary> /// <param name="settings">Settings.</param> /// <param name="output">Generated output.</param> public static void InvalidHdlcFrame(GXSettings settings, GXOutput output) { if (settings.client.InterfaceType == InterfaceType.HDLC) { Reader.GXDLMSReader reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.iec); reader.WaitTime = settings.WaitTime; settings.media.Open(); settings.client.Limits.MaxInfoRX = settings.client.Limits.MaxInfoTX = 64; reader.SNRMRequest(); byte[] data = GXDLMSTranslator.HexToBytes("7E A0 41 03 21 10 B1 EA E6 E6 00 60 33 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 07 80 05 47 75 72 75 78 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 1E 1D FF FF ED 2C 7E"); GXReplyData reply = new GXReplyData(); reader.ReadDataBlock(data, reply); } }
/// <summary> /// Connect to the meter and try to send password in two part. /// </summary> /// <param name="settings">Settings.</param> /// <param name="output">Generated output.</param> public static void PasswordInTwoPart(GXSettings settings, GXOutput output) { if (settings.client.InterfaceType == InterfaceType.HDLC) { Reader.GXDLMSReader reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.iec); //GXDLMSClient cl = new GXDLMSClient(true, 16, 1, Authentication.Low, null, InterfaceType.HDLC); //Reader.GXDLMSReader reader = new Reader.GXDLMSReader(cl, settings.media, settings.trace, settings.iec); reader.WaitTime = settings.WaitTime; settings.media.Open(); settings.client.Limits.MaxInfoRX = settings.client.Limits.MaxInfoTX = 64; reader.SNRMRequest(); settings.client.Authentication = Authentication.Low; settings.client.Password = ASCIIEncoding.ASCII.GetBytes("Gurux"); reader.AarqRequest(); } }
internal static int GetParameters(string[] args, GXSettings settings) { List <GXCmdParameter> parameters = GXCommon.GetParameters(args, "bh:p:c:s:r:it:a:p:wP:x:S:e:C:"); GXNet net = null; foreach (GXCmdParameter it in parameters) { switch (it.Tag) { case 'w': settings.client.InterfaceType = InterfaceType.WRAPPER; break; case 'r': if (string.Compare(it.Value, "sn", true) == 0) { settings.client.UseLogicalNameReferencing = false; } else if (string.Compare(it.Value, "ln", true) == 0) { settings.client.UseLogicalNameReferencing = true; } else { throw new ArgumentException("Invalid reference option."); } break; case 'h': //Host address. if (settings.media == null) { settings.media = new GXNet(); } net = settings.media as GXNet; net.HostName = it.Value; break; case 't': //Trace. try { settings.trace = (TraceLevel)Enum.Parse(typeof(TraceLevel), it.Value); } catch (Exception) { throw new ArgumentException("Invalid Authentication option. (Error, Warning, Info, Verbose, Off)"); } break; case 'p': //Port. if (settings.media == null) { settings.media = new GXNet(); } net = settings.media as GXNet; net.Port = int.Parse(it.Value); break; case 'P': //Password settings.client.Password = ASCIIEncoding.ASCII.GetBytes(it.Value); break; case 'i': //IEC. settings.iec = true; break; case 'e': //Exclude object type. foreach (string ot in it.Value.Split(',')) { settings.excludedObjects.Add((ObjectType)Enum.Parse(typeof(ObjectType), ot)); } break; case 'S': //Serial Port settings.media = new GXSerial(); GXSerial serial = settings.media as GXSerial; string[] tmp = it.Value.Split(':'); serial.PortName = tmp[0]; if (tmp.Length > 1) { serial.BaudRate = int.Parse(tmp[1]); serial.DataBits = int.Parse(tmp[2].Substring(0, 1)); serial.Parity = (Parity)Enum.Parse(typeof(Parity), tmp[2].Substring(1, tmp[2].Length - 2)); serial.StopBits = (StopBits)int.Parse(tmp[2].Substring(tmp[2].Length - 1, 1)); } else { serial.BaudRate = 9600; serial.DataBits = 8; serial.Parity = Parity.None; serial.StopBits = StopBits.One; } break; case 'a': try { settings.client.Authentication = (Authentication)Enum.Parse(typeof(Authentication), it.Value); } catch (Exception) { throw new ArgumentException("Invalid Authentication option. (None, Low, High, HighMd5, HighSha1, HighGmac, HighSha256)"); } break; case 'C': settings.tests = 0; foreach (string ot in it.Value.Split(',')) { settings.tests |= (ConformanceTest)Enum.Parse(typeof(ConformanceTest), ot); } break; case 'o': break; case 'c': settings.client.ClientAddress = int.Parse(it.Value); break; case 's': settings.client.ServerAddress = int.Parse(it.Value); break; case 'x': settings.path = it.Value; break; case '?': switch (it.Tag) { case 'c': throw new ArgumentException("Missing mandatory client option."); case 's': throw new ArgumentException("Missing mandatory server option."); case 'h': throw new ArgumentException("Missing mandatory host name option."); case 'p': throw new ArgumentException("Missing mandatory port option."); case 'r': throw new ArgumentException("Missing mandatory reference option."); case 'a': throw new ArgumentException("Missing mandatory authentication option."); case 'S': throw new ArgumentException("Missing mandatory Serial port option.\n"); case 't': throw new ArgumentException("Missing mandatory trace option.\n"); case 'e': throw new ArgumentException("Missing mandatory exclude object type option.\n"); default: ShowHelp(); return(1); } default: ShowHelp(); return(1); } } if (settings.media == null) { ShowHelp(); return(1); } return(0); }
static int Main(string[] args) { SetAddRemoveProgramsIcon(); GXOutput ouput = new Test.GXOutput(); GXSettings settings = new GXSettings(); List <KeyValuePair <GXDLMSXmlPdu, List <string> > > differences = new List <KeyValuePair <GXDLMSXmlPdu, List <string> > >(); GXDLMSConverter c = new GXDLMSConverter(); try { if (args.Length == 0) { GXProperties dlg = new GXProperties(settings); if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(0); } } else { //Handle command line parameters. int ret = GXSettings.GetParameters(args, settings); if (ret != 0) { return(ret); } } //////////////////////////////////////// //Check media connection settings. if (!(settings.media is GXSerial || settings.media is GXNet)) { throw new Exception("Unknown media type."); } //Read basic tests to pass DLMS Conformance tests. //Breen Book: 4.1.8.4 Mandatory contents of a COSEM logical device //1. Read Association view. //2. Check Logical Device Name //3. Check SAP. if ((settings.tests & ConformanceTest.Cosem) != 0) { ouput.writer.Write("<h2>Cosem tests:</h2>"); GXTests.Basic(settings, ouput); } } catch (Exception e) { if (settings.trace > TraceLevel.Off) { Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Gurux Conformance Test ended."); Console.WriteLine(e.Message); } return(1); } try { if ((settings.tests & ConformanceTest.Init) != 0) { ouput.writer.Write("<h2>Initialization tests:</h2>"); GXTests.Init(settings, ouput); } } catch (Exception ex) { if (settings.trace > TraceLevel.Off) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(ex.Message); } return(1); } try { if (settings.path != null) { ouput.writer.Write("<h2>Extra tests:</h2>"); GXTests.Extra(settings, ouput); } } catch (Exception ex) { if (settings.trace > TraceLevel.Off) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(ex.Message); } return(1); } Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Gurux Conformance Test ended."); ouput.writer.Flush(); Process.Start(ouput.GetName()); return(0); }
public GXProperties(GXSettings settings) { Target = settings; Target.client.UseLogicalNameReferencing = false; InitializeComponent(); LNSettings.Dock = SNSettings.Dock = DockStyle.Fill; SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication, Security.Encryption, Security.AuthenticationEncryption }); NetProtocolCB.Items.AddRange(new object[] { NetworkType.Tcp, NetworkType.Udp }); ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged); NetworkSettingsGB.Width = this.Width - NetworkSettingsGB.Left; CustomSettings.Bounds = SerialSettingsGB.Bounds = TerminalSettingsGB.Bounds = NetworkSettingsGB.Bounds; ManufacturerCB.DrawMode = MediasCB.DrawMode = ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed; StartProtocolCB.Items.Add(StartProtocolType.IEC); StartProtocolCB.Items.Add(StartProtocolType.DLMS); GXNet net = new GXNet() { Protocol = NetworkType.Tcp }; GXSerial serial = new GXSerial(); MediasCB.Items.Add(net); MediasCB.Items.Add(serial); //Initialize serial settings. string[] ports = GXSerial.GetPortNames(); this.SerialPortCB.Items.AddRange(ports); GXManufacturerCollection Manufacturers = new GXManufacturerCollection(); if (GXManufacturerCollection.IsFirstRun()) { if (MessageBox.Show(this, Properties.Resources.InstallManufacturersOnlineTxt, Properties.Resources.CTT, MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { GXManufacturerCollection.UpdateManufactureSettings(); } } GXManufacturerCollection.ReadManufacturerSettings(Manufacturers); int pos = 0; foreach (GXManufacturer it in Manufacturers) { int index = this.ManufacturerCB.Items.Add(it); if (it.Identification == Properties.Settings.Default.SelectedManufacturer) { pos = index; } } ManufacturerCB.SelectedIndex = pos; if (Properties.Settings.Default.WaitTime != 0) { WaitTimeTB.Value = Properties.Settings.Default.WaitTime; } if (Properties.Settings.Default.Media == "Net") { MediasCB.SelectedIndex = 0; net.Settings = Properties.Settings.Default.MediaSettings; } else { MediasCB.SelectedIndex = 1; serial.Settings = Properties.Settings.Default.MediaSettings; } if (SerialPortCB.Items.Count != 0) { SerialPortCB.SelectedItem = serial.PortName; } HostNameTB.Text = net.HostName; PortTB.Text = net.Port.ToString(); NetProtocolCB.SelectedItem = net.Protocol; ShowConformance(Target.client.ProposedConformance); }
/// <summary> /// Execute basic tests. /// </summary> /// <param name="settings">Settings.</param> /// <param name="output">Generated output.</param> public static bool Basic(GXSettings settings, GXOutput output) { Reader.GXDLMSReader reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.iec); reader.WaitTime = settings.WaitTime; try { settings.media.Open(); } catch (System.Net.Sockets.SocketException e) { //If failed to make connection to the meter. output.Errors.Add("Failed to connect to the meter: " + e.Message); output.MakeReport(); return(false); } if (settings.trace > TraceLevel.Error) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Initialize connection."); } reader.InitializeConnection(); if (settings.trace > TraceLevel.Error) { Console.WriteLine("Get association view."); } reader.GetAssociationView(false); if (settings.client.UseLogicalNameReferencing) { output.PreInfo.Add("Testing using Logical Name referencing."); } else { output.PreInfo.Add("Testing using Short Name referencing."); } output.PreInfo.Add("Authentication level: " + settings.client.Authentication); output.PreInfo.Add("Total amount of objects: " + settings.client.Objects.Count.ToString()); if (settings.client.UseLogicalNameReferencing) { if (settings.trace > TraceLevel.Error) { Console.WriteLine("Finding Logical Device Name and SAP."); } GXDLMSObject ldn = settings.client.Objects.FindByLN(ObjectType.None, "0.0.42.0.0.255"); GXDLMSObjectCollection saps = settings.client.Objects.GetObjects(ObjectType.SapAssignment); if (ldn == null && saps.Count == 0) { output.Errors.Add("Logical Device Name or SAP is not implemented. Read more: GB: 4.1.8.4."); } if (settings.trace > TraceLevel.Error) { if (ldn != null) { reader.Read(ldn, 2); output.PreInfo.Add("Meter Logical Device Name is: " + (ldn as GXDLMSData).Value.ToString() + "."); } if (saps.Count != 0) { output.PreInfo.Add("SAP is not implemented."); } } } //Check OBIS codes. foreach (GXDLMSObject it in settings.client.Objects) { if (it.Description == "Invalid") { output.Errors.Add("Invalid OBIS code " + it.LogicalName + " for <a target=\"_blank\" href=http://www.gurux.fi/" + it.GetType().FullName + ">" + it.ObjectType + "</a>."); if (settings.trace > TraceLevel.Warning) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(it.LogicalName + ": Invalid OBIS code."); } } } //Read structures of Cosem objects. List <KeyValuePair <string, List <GXDLMSXmlPdu> > > cosemTests = new List <KeyValuePair <string, List <GXDLMSXmlPdu> > >(); GXDLMSTranslator translator = new GXDLMSTranslator(TranslatorOutputType.SimpleXml); foreach (string it in GetTests()) { using (Stream stream = typeof(Program).Assembly.GetManifestResourceStream(it)) using (StreamReader sr = new StreamReader(stream)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(sr.ReadToEnd()); XmlNodeList list = doc.SelectNodes("/Messages/GetRequest/GetRequestNormal"); ObjectType ot = ObjectType.None; foreach (XmlNode node in list) { ot = (ObjectType)int.Parse(node.SelectNodes("AttributeDescriptor/ClassId")[0].Attributes["Value"].Value); //If this object type is skipped. if (settings.excludedObjects.Contains(ot)) { output.Info.Add("Skipping " + ot.ToString() + " object types."); break; } int index = int.Parse(node.SelectNodes("AttributeDescriptor/AttributeId")[0].Attributes["Value"].Value); //Update logical name. foreach (GXDLMSObject obj in settings.client.Objects.GetObjects(ot)) { if ((obj.GetAccess(index) & AccessMode.Read) != 0) { string tmp = GXCommon.ToHex(LogicalNameToBytes(obj.LogicalName), false); foreach (XmlNode n in list) { XmlAttribute ln = n.SelectNodes("AttributeDescriptor/InstanceId")[0].Attributes["Value"]; ln.Value = tmp; } cosemTests.Add(new KeyValuePair <string, List <GXDLMSXmlPdu> >(ot.ToString(), settings.client.LoadXml(doc.InnerXml))); } } break; } } } foreach (KeyValuePair <string, List <GXDLMSXmlPdu> > it in cosemTests) { try { Execute(settings, reader, it.Key, it.Value, output); } catch (Exception ex) { if (settings.trace > TraceLevel.Off) { Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine(ex.Message); } } } List <ObjectType> unknownDataTypes = new List <ObjectType>(); foreach (GXDLMSObject o in settings.client.Objects) { if (!unknownDataTypes.Contains(o.ObjectType)) { bool found = false; foreach (KeyValuePair <string, List <GXDLMSXmlPdu> > t in cosemTests) { if (o.ObjectType.ToString() == t.Key) { found = true; break; } } if (!found) { unknownDataTypes.Add(o.ObjectType); output.Warnings.Add("<a target=\"_blank\" href=http://www.gurux.fi/" + o.GetType().FullName + ">" + o.ObjectType + "</a> is not tested."); } } } //Check InactivityTimeout. bool fail = false; int rc = reader.RetryCount; int wt = reader.WaitTime; int inactivityTimeout; if (settings.client.InterfaceType == InterfaceType.HDLC) { GXDLMSHdlcSetup s = (GXDLMSHdlcSetup)settings.client.Objects.GetObjects(ObjectType.IecHdlcSetup)[0]; s.InactivityTimeout = 0; reader.Read(s, 8); inactivityTimeout = s.InactivityTimeout; output.PreInfo.Add("HdlcSetup default inactivity timeout value is " + inactivityTimeout + " seconds."); if ((s.GetAccess(8) & AccessMode.Write) != 0) { //Wait second. s.InactivityTimeout = 1; reader.Write(s, 8); Thread.Sleep(2000); try { reader.WaitTime = 1000; reader.RetryCount = 0; reader.Read(s, 8); } catch (Exception) { //This should fails. fail = true; } reader.InitializeConnection(); s.InactivityTimeout = inactivityTimeout; reader.Write(s, 8); if (!fail) { output.Errors.Add("HdlcSetup failed. InactivityTimeout don't work."); } } else { output.PreInfo.Add("HdlcSetup inactivity timeout is not tested."); } } else { GXDLMSTcpUdpSetup s = (GXDLMSTcpUdpSetup)settings.client.Objects.GetObjects(ObjectType.TcpUdpSetup)[0]; s.InactivityTimeout = 0; reader.Read(s, 6); inactivityTimeout = s.InactivityTimeout; output.PreInfo.Add("TcpUdpSetup default inactivity timeout value is " + inactivityTimeout + " seconds."); if ((s.GetAccess(6) & AccessMode.Write) != 0) { //Wait second. s.InactivityTimeout = 1; reader.Write(s, 6); Thread.Sleep(2000); try { reader.WaitTime = 1000; reader.RetryCount = 0; reader.Read(s, 6); } catch (Exception) { //This should fails. fail = true; } reader.InitializeConnection(); s.InactivityTimeout = inactivityTimeout; reader.Write(s, 6); if (!fail) { output.Errors.Add("TcpUdpSetup failed. InactivityTimeout don't work."); } } else { output.PreInfo.Add("TcpUdpSetup inactivity timeout is not tested."); } } reader.WaitTime = wt; reader.RetryCount = rc; output.MakeReport(); return(true); }
private static void Execute(GXSettings settings, GXDLMSReader reader, string name, List <GXDLMSXmlPdu> actions, GXOutput output) { GXReplyData reply = new GXReplyData(); string ln = null; int index = 0; ObjectType ot = ObjectType.None; List <KeyValuePair <ObjectType, int> > succeeded = new List <KeyValuePair <ObjectType, int> >(); foreach (GXDLMSXmlPdu it in actions) { if (it.Command == Command.Snrm && settings.client.InterfaceType == InterfaceType.WRAPPER) { continue; } if (it.Command == Command.DisconnectRequest && settings.client.InterfaceType == InterfaceType.WRAPPER) { break; } //Send if (it.IsRequest()) { XmlNode i = it.XmlNode.SelectNodes("GetRequestNormal")[0]; if (i == null) { ot = ObjectType.None; index = 0; ln = null; } else { ot = (ObjectType)int.Parse(i.SelectNodes("AttributeDescriptor/ClassId")[0].Attributes["Value"].Value); index = int.Parse(i.SelectNodes("AttributeDescriptor/AttributeId")[0].Attributes["Value"].Value); ln = (i.SelectNodes("AttributeDescriptor/InstanceId")[0].Attributes["Value"].Value); ln = GetLogicalName(ln); } reply.Clear(); if (settings.trace > TraceLevel.Warning) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(it.ToString()); } byte[][] tmp = settings.client.PduToMessages(it); reader.ReadDataBlock(tmp, reply); } else if (reply.Data.Size != 0) { List <string> list = it.Compare(reply.ToString()); if (list.Count != 0) { if (ot == ObjectType.None) { foreach (string err in list) { output.Errors.Add(err); } } else { // output.Errors.Add("<div class=\"description\">\r\n"); output.Errors.Add("<a target=\"_blank\" href=http://www.gurux.fi/Gurux.DLMS.Objects.GXDLMS" + ot + ">" + ot + "</a> " + ln + " attribute " + index + " is <div class=\"tooltip\">invalid."); output.Errors.Add("<span class=\"tooltiptext\">"); output.Errors.Add("Expected:</b><br/>"); output.Errors.Add(it.PduAsXml.Replace("<", "<").Replace(">", ">").Replace("\r\n", "<br/>")); output.Errors.Add("<br/><b>Actual:</b><br/>"); output.Errors.Add(reply.ToString().Replace("<", "<").Replace(">", ">").Replace("\r\n", "<br/>")); output.Errors.Add("</span></div>"); // output.Errors.Add("</div>"); } Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Test" + name + "failed. Invalid reply: " + string.Join("\n", list.ToArray())); } else { if (ot == ObjectType.None) { output.Info.Add(name + " succeeded."); } else { succeeded.Add(new KeyValuePair <ObjectType, int>(ot, index)); } } if (settings.trace > TraceLevel.Warning) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(reply.ToString()); } } } if (succeeded.Count != 0) { StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"tooltip\">" + ln); sb.Append("<span class=\"tooltiptext\">"); foreach (var it in succeeded) { sb.Append("Index: " + it.Value + "<br/>"); } sb.Append("</span></div>"); sb.Append(" " + settings.converter.GetDescription(ln, succeeded[0].Key)[0] + " " + "<a target=\"_blank\" href=http://www.gurux.fi/Gurux.DLMS.Objects.GXDLMS" + ot + ">" + ot + "</a>."); output.Info.Add(sb.ToString()); } }
/// <summary> /// Execute extra tests. /// </summary> /// <param name="settings">Settings.</param> /// <param name="output">Generated output.</param> public static bool Extra(GXSettings settings, GXOutput output) { List <string> files = new List <string>(); FileAttributes attr = File.GetAttributes(settings.path); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { files.AddRange(Directory.GetFiles(settings.path, "*.xml")); } else { files.Add(settings.path); } Reader.GXDLMSReader reader = null; //Read additional tests. string name; foreach (string file in files) { name = Path.GetFileNameWithoutExtension(file); if (settings.trace > TraceLevel.Warning) { Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(name); } List <GXDLMSXmlPdu> actions = settings.client.Load(file); if (actions.Count == 0) { continue; } try { reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.iec); reader.WaitTime = settings.WaitTime; try { settings.media.Open(); } catch (System.Net.Sockets.SocketException e) { //If failed to make connection to the meter. output.Errors.Add("Failed to connect to the meter: " + e.Message); output.MakeReport(); return(false); } //Send SNRM if not in xml. if (settings.client.InterfaceType == InterfaceType.HDLC) { if (!ContainsCommand(actions, Command.Snrm)) { reader.SNRMRequest(); } } //Send AARQ if not in xml. if (!ContainsCommand(actions, Command.Aarq)) { if (!ContainsCommand(actions, Command.Snrm)) { reader.AarqRequest(); } } Execute(settings, reader, name, actions, output); } catch (Exception ex) { output.Errors.Add(name + " failed."); } finally { //Send AARQ if not in xml. if (!ContainsCommand(actions, Command.DisconnectRequest)) { reader.Disconnect(); } else { settings.media.Close(); } } } output.MakeReport(); return(true); }
/// <summary> /// Execute connection tests. /// </summary> /// <param name="settings">Settings.</param> /// <param name="output">Generated output.</param> public static bool Init(GXSettings settings, GXOutput output) { // PasswordInTwoPart(settings, output); // InvalidHdlcFrame(settings, output); List <string> files = new List <string>(); Reader.GXDLMSReader reader = null; if (settings.client.UseLogicalNameReferencing) { files.AddRange(GetLNTests()); } else { files.AddRange(GetSNTests()); } //Read additional tests. foreach (string name in files) { List <GXDLMSXmlPdu> actions; using (Stream stream = typeof(Program).Assembly.GetManifestResourceStream(name)) { using (StreamReader sr = new StreamReader(stream)) { actions = settings.client.Load(sr); } } if (actions.Count == 0) { continue; } try { reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.iec); reader.WaitTime = settings.WaitTime; try { settings.media.Open(); } catch (System.Net.Sockets.SocketException e) { //If failed to make connection to the meter. output.Errors.Add("Failed to connect to the meter: " + e.Message); output.MakeReport(); return(false); } //Send SNRM if not in xml. if (settings.client.InterfaceType == InterfaceType.HDLC) { if (!ContainsCommand(actions, Command.Snrm)) { reader.SNRMRequest(); } } //Send AARQ if not in xml. if (!ContainsCommand(actions, Command.Aarq)) { if (!ContainsCommand(actions, Command.Snrm)) { reader.AarqRequest(); } } Execute(settings, reader, name, actions, output); } catch (Exception ex) { output.Errors.Add(name + " failed."); } finally { //Send AARQ if not in xml. if (!ContainsCommand(actions, Command.DisconnectRequest)) { reader.Disconnect(); } else { settings.media.Close(); } } } output.MakeReport(); return(true); }