/// <summary> /// Read association view. /// </summary> public bool GetAssociationView(string outputFile) { if (outputFile != null) { //Save Association view to the cache so it is not needed to retrieve every time. if (File.Exists(outputFile)) { try { Client.Objects.Clear(); Client.Objects.AddRange(GXDLMSObjectCollection.Load(outputFile)); return(false); } catch (Exception) { if (File.Exists(outputFile)) { File.Delete(outputFile); } } } } GXReplyData reply = new GXReplyData(); ReadDataBlock(Client.GetObjectsRequest(), reply); Client.ParseObjects(reply.Data, true); //Access rights must read differently when short Name referencing is used. if (!Client.UseLogicalNameReferencing) { GXDLMSAssociationShortName sn = (GXDLMSAssociationShortName)Client.Objects.FindBySN(0xFA00); if (sn != null && sn.Version > 0) { Read(sn, 3); } } if (outputFile != null) { try { Client.Objects.Save(outputFile, new GXXmlWriterSettings() { Values = false }); } catch (Exception) { //It's OK if this fails. return(false); } } return(true); }
public GXValuesDlg(Dictionary <Type, List <IGXDLMSView> > views, string path) { InitializeComponent(); Views = views; foreach (GXDLMSObject it in GXDLMSObjectCollection.Load(path)) { ListViewItem li = new ListViewItem(it.LogicalName); li.Tag = it; ObjectList.Items.Add(li); } if (ObjectList.Items.Count != 0) { ObjectList.Items[0].Selected = true; } }
static int Main(string[] args) { Settings settings = new Settings(); Reader.GXDLMSReader reader = null; try { //////////////////////////////////////// //Handle command line parameters. int ret = Settings.GetParameters(args, settings); if (ret != 0) { return(ret); } //////////////////////////////////////// //Initialize connection settings. if (settings.media is GXSerial) { GXSerial serial = settings.media as GXSerial; if (settings.iec) { serial.BaudRate = 300; serial.DataBits = 7; serial.Parity = System.IO.Ports.Parity.Even; serial.StopBits = System.IO.Ports.StopBits.One; } else { serial.BaudRate = 9600; serial.DataBits = 8; serial.Parity = System.IO.Ports.Parity.None; serial.StopBits = System.IO.Ports.StopBits.One; } } else if (settings.media is GXNet) { } else { throw new Exception("Unknown media type."); } //////////////////////////////////////// reader = new Reader.GXDLMSReader(settings.client, settings.media, settings.trace, settings.invocationCounter, settings.iec); settings.media.Open(); //Some meters need a break here. Thread.Sleep(1000); if (settings.readObjects.Count != 0) { bool read = false; if (settings.outputFile != null) { try { settings.client.Objects.Clear(); settings.client.Objects.AddRange(GXDLMSObjectCollection.Load(settings.outputFile)); read = true; } catch (Exception) { //It's OK if this fails. } } reader.InitializeConnection(); if (!read) { reader.GetAssociationView(settings.outputFile); } foreach (KeyValuePair <string, int> it in settings.readObjects) { object val = reader.Read(settings.client.Objects.FindByLN(ObjectType.None, it.Key), it.Value); reader.ShowValue(val, it.Value); } if (settings.outputFile != null) { try { settings.client.Objects.Save(settings.outputFile, new GXXmlWriterSettings() { IgnoreDefaultValues = false }); } catch (Exception) { //It's OK if this fails. } } } else { reader.ReadAll(settings.outputFile); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.ToString()); if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } return(1); } finally { if (reader != null) { reader.Close(); } if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine("Ended. Press any key to continue."); Console.ReadKey(); } } return(0); }