Exemple #1
0
 public void KeepAliveStart()
 {
     if (InactivityMode != InactivityMode.None)
     {
         KeepAlive.Interval = Manufacturers.FindByIdentification(this.Manufacturer).KeepAliveInterval;
         KeepAlive.Start();
     }
 }
 /// <summary>
 /// After UpdateObjects call objects can be read using Objects property.
 /// </summary>
 public void UpdateObjects()
 {
     try
     {
         GXDLMSObjectCollection objs = Comm.GetObjects();
         objs.Tag = this;
         int pos = 0;
         foreach (GXDLMSObject it in objs)
         {
             ++pos;
             NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count);
             Objects.Add(it);
         }
         GXLogWriter.WriteLog("--- Created " + Objects.Count.ToString() + " objects. ---");
         //Read registers units and scalers.
         int cnt = Objects.Count;
         if (!UseLogicalNameReferencing)
         {
             GXLogWriter.WriteLog("--- Reading Access rights. ---");
             try
             {
                 foreach (GXDLMSAssociationShortName sn in Objects.GetObjects(ObjectType.AssociationShortName))
                 {
                     if (sn.Version > 1)
                     {
                         Comm.ReadValue(sn, 3);
                     }
                 }
             }
             catch (Exception ex)
             {
                 GXLogWriter.WriteLog(ex.Message);
             }
             GXLogWriter.WriteLog("--- Reading Access rights end. ---");
         }
         GXLogWriter.WriteLog("--- Reading scalers and units. ---");
         this.OnProgress(this, "Reading scalers and units.", cnt + pos + 1, 3 * cnt);
         if ((Comm.client.NegotiatedConformance & Gurux.DLMS.Enums.Conformance.MultipleReferences) != 0)
         {
             List <KeyValuePair <GXDLMSObject, int> > list = new List <KeyValuePair <GXDLMSObject, int> >();
             foreach (GXDLMSObject it in Objects)
             {
                 if (it is GXDLMSRegister && (it.GetAccess(3) & AccessMode.Read) != 0)
                 {
                     list.Add(new KeyValuePair <GXDLMSObject, int>(it, 3));
                 }
                 if (it is GXDLMSDemandRegister && (it.GetAccess(4) & AccessMode.Read) != 0)
                 {
                     list.Add(new KeyValuePair <GXDLMSObject, int>(it, 4));
                 }
             }
             if (list.Count != 0)
             {
                 try
                 {
                     Comm.ReadList(list);
                 }
                 catch (Exception)
                 {
                     //Show error.
                 }
             }
         }
         else
         {
             for (pos = 0; pos != cnt; ++pos)
             {
                 GXDLMSObject it = Objects[pos];
                 if (it is GXDLMSRegister)
                 {
                     //Read scaler first.
                     try
                     {
                         if ((it.GetAccess(3) & AccessMode.Read) != 0)
                         {
                             Comm.ReadValue(it, 3);
                         }
                     }
                     catch (Exception ex)
                     {
                         GXLogWriter.WriteLog(ex.Message);
                         it.SetAccess(3, AccessMode.NoAccess);
                         if (ex is GXDLMSException)
                         {
                             continue;
                         }
                         throw ex;
                     }
                 }
                 if (it is GXDLMSDemandRegister)
                 {
                     //Read scaler first.
                     try
                     {
                         if ((it.GetAccess(4) & AccessMode.Read) != 0)
                         {
                             Comm.ReadValue(it, 4);
                         }
                     }
                     catch (Exception ex)
                     {
                         GXLogWriter.WriteLog(ex.Message);
                         UpdateError(it, 4, ex);
                         if (ex is GXDLMSException)
                         {
                             continue;
                         }
                         throw ex;
                     }
                     //Read Period
                     try
                     {
                         Comm.ReadValue(it, 8);
                     }
                     catch (Exception ex)
                     {
                         GXLogWriter.WriteLog(ex.Message);
                         UpdateError(it, 8, ex);
                         if (ex is GXDLMSException)
                         {
                             continue;
                         }
                         throw ex;
                     }
                     //Read number of periods
                     try
                     {
                         Comm.ReadValue(it, 9);
                     }
                     catch (Exception ex)
                     {
                         GXLogWriter.WriteLog(ex.Message);
                         UpdateError(it, 9, ex);
                         if (ex is GXDLMSException)
                         {
                             continue;
                         }
                         throw ex;
                     }
                 }
             }
         }
         GXLogWriter.WriteLog("--- Reading scalers and units end. ---");
         this.OnProgress(this, "Reading profile generic columns.", cnt, cnt);
         foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric))
         {
             ++pos;
             //Read Profile Generic Columns.
             try
             {
                 NotifyProgress(this, "Get profile generic columns", (2 * cnt) + pos, 3 * objs.Count);
                 UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer));
                 if (it.CaptureObjects == null || it.CaptureObjects.Count == 0)
                 {
                     continue;
                 }
             }
             catch
             {
                 GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName));
                 continue;
             }
         }
     }
     finally
     {
         NotifyProgress(this, "", 0, 0);
     }
 }
Exemple #3
0
        /// <summary>
        /// After UpdateObjects call objects can be read using Objects property.
        /// </summary>
        public void UpdateObjects()
        {
            try
            {
                GXDLMSObjectCollection objs = Comm.GetObjects();
                objs.Tag = this;
                int pos = 0;
                foreach (GXDLMSObject it in objs)
                {
                    //Profile Generic objects are added later.
                    if (it.ObjectType == ObjectType.ProfileGeneric)
                    {
                        continue;
                    }
                    if (it.GetType() == typeof(GXDLMSObject))
                    {
                        continue;
                    }
                    ++pos;
                    NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count);
                    m_Objects.Add(it);
                }
                GXLogWriter.WriteLog("--- Created " + m_Objects.Count.ToString() + " objects. ---");
                int objPos = 0;
                //Read registers units and scalers.
                int cnt = Objects.Count;
                GXLogWriter.WriteLog("--- Reading scalers and units. ---");
                for (pos = 0; pos != cnt; ++pos)
                {
                    GXDLMSObject it = Objects[pos];
                    it.UpdateDefaultValueItems();
                    this.OnProgress(this, "Reading scalers and units.", pos + 1, cnt);
                    if (it is GXDLMSRegister)
                    {
                        object data = it.ShortName;
                        if (it.ShortName == 0)
                        {
                            data = it.LogicalName;
                        }
                        //Read scaler first.
                        DataType type = DataType.None;
                        try
                        {
                            data = Comm.ReadValue(data, it.ObjectType, 3, ref type);
                            object tmp = GXHelpers.ConvertFromDLMS(data, DataType.None, DataType.None, false);
                            //Actaris ACE 6000 is returning wrong value here.
                            if (tmp is object[])
                            {
                                object[] scalerUnit = (object[])tmp;
                                ((GXDLMSRegister)it).Scaler = Math.Pow(10, Convert.ToInt32(scalerUnit.GetValue(0)));
                                ((GXDLMSRegister)it).Unit   = (Unit)Convert.ToInt32(scalerUnit.GetValue(1));
                            }
                        }
                        catch (Exception ex)
                        {
                            GXLogWriter.WriteLog(ex.Message);
                            UpdateError(it, 3, ex);
                            if (ex is GXDLMSException)
                            {
                                continue;
                            }
                            throw ex;
                        }
                    }
                    if (it is GXDLMSDemandRegister)
                    {
                        object name = it.ShortName;
                        object data;
                        if (it.ShortName == 0)
                        {
                            name = it.LogicalName;
                        }
                        //Read scaler first.
                        DataType type           = DataType.None;
                        byte     attributeOrder = 4;
                        try
                        {
                            data = Comm.ReadValue(name, it.ObjectType, attributeOrder, ref type);
                            Array scalerUnit = (Array)GXHelpers.ConvertFromDLMS(data, DataType.None, DataType.None, false);
                            ((GXDLMSDemandRegister)it).Scaler = Math.Pow(10, Convert.ToInt32(scalerUnit.GetValue(0)));
                            ((GXDLMSDemandRegister)it).Unit   = (Unit)Convert.ToInt32(scalerUnit.GetValue(1));
                            //Read Period
                            data = Comm.ReadValue(name, it.ObjectType, 8, ref type);
                            ((GXDLMSDemandRegister)it).Period = Convert.ToUInt64(data);
                            //Read number of periods
                            data = Comm.ReadValue(name, it.ObjectType, 9, ref type);
                            ((GXDLMSDemandRegister)it).NumberOfPeriods = Convert.ToUInt32(data);
                        }
                        catch (Exception ex)
                        {
                            GXLogWriter.WriteLog(ex.Message);
                            UpdateError(it, 3, ex);
                            if (ex is GXDLMSException)
                            {
                                continue;
                            }
                            throw ex;
                        }
                    }
                }
                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(this, "Reading scalers and units.", cnt, cnt);
                foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric))
                {
                    ++pos;
                    NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count);
                    //Read Profile Generic Columns.
                    try
                    {
                        NotifyProgress(this, "Get profile generic columns", ++objPos, objs.Count);
                        UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer));
                        if (it.CaptureObjects == null || it.CaptureObjects.Count == 0)
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName));
                        continue;
                    }
                    m_Objects.Add(it);
                }
            }
            finally
            {
                NotifyProgress(this, "", 0, 0);
            }
        }
Exemple #4
0
 /// <summary>
 /// After UpdateObjects call objects can be read using Objects property.
 /// </summary>
 public void UpdateObjects()
 {
     try
     {
         GXDLMSObjectCollection objs = Comm.GetObjects();
         objs.Tag = this;
         int pos = 0;
         foreach (GXDLMSObject it in objs)
         {
             ++pos;
             NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count);
             m_Objects.Add(it);
         }
         GXLogWriter.WriteLog("--- Created " + m_Objects.Count.ToString() + " objects. ---");
         //Read registers units and scalers.
         int cnt = Objects.Count;
         GXLogWriter.WriteLog("--- Reading scalers and units. ---");
         for (pos = 0; pos != cnt; ++pos)
         {
             GXDLMSObject it = Objects[pos];
             this.OnProgress(this, "Reading scalers and units.", cnt + pos + 1, 3 * cnt);
             if (it is GXDLMSRegister)
             {
                 //Read scaler first.
                 try
                 {
                     Comm.ReadValue(it, 3);
                 }
                 catch (Exception ex)
                 {
                     GXLogWriter.WriteLog(ex.Message);
                     UpdateError(it, 3, ex);
                     if (ex is GXDLMSException)
                     {
                         continue;
                     }
                     throw ex;
                 }
             }
             if (it is GXDLMSDemandRegister)
             {
                 try
                 {
                     //Read scaler first.
                     Comm.ReadValue(it, 4);
                     //Read Period
                     Comm.ReadValue(it, 8);
                     //Read number of periods
                     Comm.ReadValue(it, 9);
                 }
                 catch (Exception ex)
                 {
                     GXLogWriter.WriteLog(ex.Message);
                     UpdateError(it, 3, ex);
                     if (ex is GXDLMSException)
                     {
                         continue;
                     }
                     throw ex;
                 }
             }
         }
         GXLogWriter.WriteLog("--- Reading scalers and units end. ---");
         if (!UseLogicalNameReferencing)
         {
             GXLogWriter.WriteLog("--- Reading Access rights. ---");
             try
             {
                 foreach (GXDLMSAssociationShortName sn in Objects.GetObjects(ObjectType.AssociationShortName))
                 {
                     Comm.ReadValue(sn, 3);
                 }
             }
             catch (Exception ex)
             {
                 GXLogWriter.WriteLog(ex.Message);
             }
             GXLogWriter.WriteLog("--- Reading Access rights end. ---");
         }
         this.OnProgress(this, "Reading profile generic columns.", cnt, cnt);
         foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric))
         {
             ++pos;
             //Read Profile Generic Columns.
             try
             {
                 NotifyProgress(this, "Get profile generic columns", (2 * cnt) + pos, 3 * objs.Count);
                 UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer));
                 if (it.CaptureObjects == null || it.CaptureObjects.Count == 0)
                 {
                     continue;
                 }
             }
             catch
             {
                 GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName));
                 continue;
             }
         }
     }
     finally
     {
         NotifyProgress(this, "", 0, 0);
     }
 }