void RefreshDevice(GXDLMSDevice dev, bool bRefresh) { try { if (bRefresh) { dev.KeepAliveStop(); } TreeNode deviceNode = (TreeNode)ObjectTreeItems[dev]; if (bRefresh) { OnProgress(dev, "Refresh device", 0, 1); UpdateTransaction(true); RemoveObject(dev); while (dev.Objects.Count != 0) { RemoveObject(dev.Objects[0]); } GXManufacturer m = Manufacturers.FindByIdentification(dev.Manufacturer); dev.ObisCodes = m.ObisCodes; //Walk through object tree. dev.UpdateObjects(); //Read registers units and scalers. int cnt = dev.Objects.Count; GXLogWriter.WriteLog("--- Reading scalers and units. ---"); for (int pos = 0; pos != cnt; ++pos) { GXDLMSObject it = dev.Objects[pos]; GXObisCode obj = m.ObisCodes.FindByLN(it.ObjectType, it.LogicalName, null); if (obj != null) { UpdateFromObisCode(it, obj); } else { continue; } } GXLogWriter.WriteLog("--- Reading scalers and units end. ---"); /* TODO: if (!m.UseLogicalNameReferencing) { GXLogWriter.WriteLog("--- Reading Access rights. ---"); try { foreach (GXDLMSAssociationShortName sn in dev.Objects.GetObjects(ObjectType.AssociationShortName)) { dev.Comm.Read(sn, 3); } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); } GXLogWriter.WriteLog("--- Reading Access rights end. ---"); } * */ this.OnProgress(dev, "Reading scalers and units.", cnt, cnt); GroupItems(GroupsMnu.Checked); } } catch (ThreadAbortException) { //User has cancel action. Do nothing. } catch (Exception Ex) { throw Ex; } finally { if (bRefresh) { dev.KeepAliveStart(); UpdateTransaction(false); } } }
void ReadDevice(GXDLMSDevice dev) { try { dev.Comm.OnBeforeRead += new ReadEventHandler(OnBeforeRead); dev.Comm.OnAfterRead += new ReadEventHandler(OnAfterRead); dev.KeepAliveStop(); int cnt = dev.Objects.Count; if (cnt == 0) { RefreshDevice(dev, true); //Do not try to refresh and read values at the same time. return; } int pos = 0; foreach (GXDLMSObject it in dev.Objects) { OnProgress(dev, "Reading " + it.LogicalName + "...", ++pos, cnt); dev.Comm.Read(this, it, 0); DLMSItemOnChange(it, false, 0, null); } } catch (Exception Ex) { throw Ex; } finally { dev.Comm.OnBeforeRead -= new ReadEventHandler(OnBeforeRead); dev.Comm.OnAfterRead -= new ReadEventHandler(OnAfterRead); dev.KeepAliveStart(); } }