Exemple #1
0
 public List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > Refresh(GXDLMSProfileGeneric item, GXDLMSCommunicator comm)
 {
     if (item.LogicalName.CompareTo("0.0.99.1.2.255") == 0) // LoadProfile1EndOfRecordingData
     {
         List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > items = new List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >();
         //Read profile generic columns.
         object       value   = comm.GetProfileGenericColumns(item.Name);
         byte[]       data    = comm.Read("0.0.99.128.1.255", ObjectType.ProfileGeneric, 2);
         byte[]       allData = comm.ReadDataBlock(data, "Get profile generic columns...", 1);
         object[]     values  = (object[])comm.m_Cosem.GetValue(allData);
         Array        info    = values[0] as Array;
         GXDLMSObject obj     = new GXDLMSData();
         obj.Description = "DateTime";
         obj.SetUIDataType(1, DataType.DateTime);
         items.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(1, 0)));
         obj             = new GXDLMSData();
         obj.Description = "Status";
         items.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(2, 0)));
         //Two last items contains Start and end date.
         int cnt = 4;
         for (int pos = 0; pos < info.Length - 2; pos += 2)
         {
             obj             = new GXDLMSData();
             obj.LogicalName = GXHelpers.ConvertFromDLMS(info.GetValue(pos), DataType.OctetString, DataType.OctetString, false).ToString();
             object scalerUnit = info.GetValue(pos + 1);
             obj.Description = "";
             items.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(++cnt, 0)));
         }
         LastDateTime = ((GXDateTime)GXDLMS.Common.GXHelpers.ConvertFromDLMS(info.GetValue(info.Length - 1), DataType.OctetString, DataType.DateTime, true)).Value;
         return(items);
     }
     return(null);
 }
Exemple #2
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);
            }
        }