void UpdateObject(GXDLMSObject it, GXDLMSCategory item)
 {
     item.ShortName = (UInt16)it.ShortName;
     item.LogicalName = it.LogicalName;
     if (it.ShortName != 0)
     {
         item.Name = string.Format("0x{0} {1} {2}", it.ShortName.ToString("X4"), it.LogicalName, it.Description);
     }
     else
     {
         item.Name = it.LogicalName + " " + it.Description;
     }
     //Update description.
     item.Description = it.Description;
     //Update atribute index.
     for (int pos = 2; pos != (it as IGXDLMSBase).GetAttributeCount() + 1; ++pos)
     {
         string name = (it as IGXDLMSBase).GetNames()[pos - 1];
         object value = it.GetValues()[pos - 1];
         GXDLMSProperty prop;
         if (((pos == 2 || pos == 3) && it.ObjectType == ObjectType.DemandRegister) || 
             (pos == 2 && it.ObjectType == ObjectType.ExtendedRegister))
         {
             prop = new GXDLMSRegister();
             prop.ObjectType = it.ObjectType;
             prop.LogicalName = it.LogicalName;
             prop.ShortName = it.ShortName;
             prop.Name = name;
             prop.AttributeOrdinal = pos;
         }
         else
         {
             prop = new GXDLMSProperty(it.ObjectType, it.LogicalName, it.ShortName, name, pos);
         }
         item.Properties.Add(prop);
         prop.DLMSType = it.GetDataType(pos);
         //Update scaler and unit.
         if ((pos == 4 && it.ObjectType == ObjectType.DemandRegister) ||
             (pos == 3 && it.ObjectType == ObjectType.ExtendedRegister))
         {
             prop.ValueType = DataType.String;
         }
         else
         {
             if (value is Enum)
             {
                 prop.ForcePresetValues = true;
                 foreach (object val in Enum.GetValues(value.GetType()))
                 {
                     prop.Values.Add(new GXValueItem(val.ToString(), (int)val));
                 }
             }
             else
             {
                 prop.ValueType = it.GetUIDataType(pos);
                 if (prop.ValueType == DataType.None)
                 {
                     prop.ValueType = it.GetDataType(pos);
                 }
             }
         }
         prop.AccessMode = (Gurux.Device.AccessMode)it.GetAccess(pos);
     }            
 }
 /// <summary>
 /// Update categories data.
 /// </summary>
 /// <param name="trace"></param>
 /// <param name="progressbar"></param>
 /// <param name="media"></param>
 /// <param name="Device"></param>
 /// <param name="wt"></param>
 /// <param name="cosem"></param>
 /// <param name="man"></param>
 /// <param name="objs"></param>
 /// <param name="dataItems"></param>
 /// <param name="registers"></param>
 private object UpdateData(Gurux.Common.IGXMedia media, GXDLMSDevice Device, int wt, GXDLMSClient cosem, GXManufacturer man, GXDLMSObject it, GXCategory dataItems, GXCategory registers)
 {
     GXObisCode code = man.ObisCodes.FindByLN(it.ObjectType, it.LogicalName, null);            
     if (it.ObjectType == ObjectType.Register)
     {
         GXDLMSRegister prop = new GXDLMSRegister();
         UpdateObject(it, prop, 2);
         registers.Properties.Add(prop);
         return prop;
     }
     else if (it.ObjectType == Gurux.DLMS.ObjectType.Data)
     {
         GXDLMSProperty prop = new GXDLMSProperty();
         prop.ObjectType = ObjectType.Data;
         UpdateObject(it, prop, 2);
         dataItems.Properties.Add(prop);
         return prop;
     }
     else if (it.ObjectType == Gurux.DLMS.ObjectType.ProfileGeneric)
     {
         GXDLMSProfileGeneric pg = it as GXDLMSProfileGeneric;
         GXDLMSTable table = new GXDLMSTable();
         table.Name = it.LogicalName + " " + it.Description;
         table.ShortName = it.ShortName;
         table.LogicalName = it.LogicalName;
         table.AccessMode = Gurux.Device.AccessMode.Read;
         foreach(var it2 in pg.CaptureObjects)
         {
             GXDLMSProperty prop;
             if (it2.Key is Gurux.DLMS.Objects.GXDLMSRegister)
             {
                 Gurux.DLMS.Objects.GXDLMSRegister tmp = it2.Key as Gurux.DLMS.Objects.GXDLMSRegister;
                 GXDLMSRegister r = new GXDLMSRegister();
                 prop = r;
                 r.Scaler = tmp.Scaler;
                 r.Unit = tmp.Unit.ToString();                    
             }
             else
             {
                 prop = new GXDLMSProperty();
             }
             int index = it2.Value.AttributeIndex;
             prop.Name = it2.Key.LogicalName + " " + it2.Key.Description;
             prop.ObjectType = it2.Key.ObjectType;
             prop.AttributeOrdinal = index;
             prop.LogicalName = it2.Key.LogicalName;
             table.Columns.Add(prop);
             prop.DLMSType = it.GetDataType(index);                    
             prop.ValueType = it2.Key.GetUIDataType(index);
         }
         Device.Tables.Add(table);
         return table; 
     }
     GXDLMSCategory cat = new GXDLMSCategory();
     cat.ObjectType = it.ObjectType;
     UpdateObject(it, cat);
     Device.Categories.Add(cat);
     return cat;            
 }