Пример #1
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         List <GXDLMSObjectDefinition> items = new List <GXDLMSObjectDefinition>();
         if (value != null)
         {
             foreach (Object[] it in (Object[])value)
             {
                 GXDLMSObjectDefinition item = new GXDLMSObjectDefinition();
                 item.ClassId     = (ObjectType)Convert.ToInt32(it[0]);
                 item.LogicalName = GXDLMSObject.toLogicalName((byte[])it[1]);
                 items.Add(item);
             }
         }
         RegisterAssignment = items.ToArray();
     }
     else if (index == 3)
     {
         MaskList.Clear();
         if (value != null)
         {
             foreach (Object[] it in (Object[])value)
             {
                 List <byte> index_list = new List <byte>();
                 foreach (byte b in (Object[])it[1])
                 {
                     index_list.Add(b);
                 }
                 MaskList.Add(new KeyValuePair <byte[], byte[]>((byte[])it[0], index_list.ToArray()));
             }
         }
     }
     else if (index == 4)
     {
         if (value == null)
         {
             ActiveMask = null;
         }
         else
         {
             ActiveMask = (byte[])value;
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Пример #2
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         ObjectList.Clear();
         if (value != null)
         {
             foreach (Object[] item in (Object[])value)
             {
                 ushort       sn      = (ushort)(Convert.ToInt32(item[0]) & 0xFFFF);
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[1]);
                 int          version = Convert.ToInt32(item[2]);
                 String       ln      = GXDLMSObject.toLogicalName((byte[])item[3]);
                 GXDLMSObject obj     = null;
                 if (Parent != null)
                 {
                     obj = Parent.FindBySN(sn);
                 }
                 if (obj == null)
                 {
                     obj = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     if (obj != null)
                     {
                         obj.LogicalName = ln;
                         obj.ShortName   = sn;
                         obj.Version     = version;
                     }
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (index == 3)
     {
         if (value == null)
         {
             foreach (GXDLMSObject it in ObjectList)
             {
                 for (int pos = 1; pos != (it as IGXDLMSBase).GetAttributeCount(); ++pos)
                 {
                     it.SetAccess(pos, AccessMode.NoAccess);
                 }
             }
         }
         else
         {
             UpdateAccessRights((Object[])value);
         }
     }
     else if (index == 4)
     {
         if (value is string)
         {
             SecuritySetupReference = value.ToString();
         }
         else
         {
             SecuritySetupReference = GXDLMSClient.ChangeType(value as byte[], DataType.OctetString).ToString();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Пример #3
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         ObjectList.Clear();
         if (value != null)
         {
             foreach (Object[] item in (Object[])value)
             {
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[0]);
                 int          version = Convert.ToInt32(item[1]);
                 String       ln      = GXDLMSObject.toLogicalName((byte[])item[2]);
                 GXDLMSObject obj     = null;
                 if (Parent != null)
                 {
                     obj = Parent.FindByLN(type, ln);
                 }
                 if (obj == null)
                 {
                     obj             = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                     obj.Version     = version;
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     UpdateAccessRights(obj, (Object[])item[3]);
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (index == 3)
     {
         ClientSAP = Convert.ToByte(((Object[])value)[0]);
         ServerSAP = Convert.ToUInt16(((Object[])value)[1]);
     }
     else if (index == 4)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 ApplicationContextName.JointIsoCtt = 0;
                 ++pos;
                 ApplicationContextName.Country = 0;
                 ++pos;
                 ApplicationContextName.CountryName = 0;
                 ++pos;
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 ApplicationContextName.DlmsUA             = arr[++pos];
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 ApplicationContextName.ContextId          = arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ContextId = arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             ApplicationContextName.JointIsoCtt            = Convert.ToByte(arr[0]);
             ApplicationContextName.Country                = Convert.ToByte(arr[1]);
             ApplicationContextName.CountryName            = Convert.ToUInt16(arr[2]);
             ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             ApplicationContextName.DlmsUA             = Convert.ToByte(arr[4]);
             ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]);
             ApplicationContextName.ContextId          = Convert.ToByte(arr[6]);
         }
     }
     else if (index == 5)
     {
         Object[] arr = (Object[])value;
         XDLMSContextInfo.Conformance       = arr[0].ToString();
         XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]);
         XDLMSContextInfo.MaxSendPpuSize    = Convert.ToUInt16(arr[2]);
         XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]);
         XDLMSContextInfo.QualityOfService  = Convert.ToSByte(arr[4]);
         XDLMSContextInfo.CypheringInfo     = (byte[])arr[5];
     }
     else if (index == 6)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 AuthenticationMechanismMame.JointIsoCtt = 0;
                 ++pos;
                 AuthenticationMechanismMame.Country = 0;
                 ++pos;
                 AuthenticationMechanismMame.CountryName = 0;
                 ++pos;
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             AuthenticationMechanismMame.JointIsoCtt            = Convert.ToByte(arr[0]);
             AuthenticationMechanismMame.Country                = Convert.ToByte(arr[1]);
             AuthenticationMechanismMame.CountryName            = Convert.ToUInt16(arr[2]);
             AuthenticationMechanismMame.IdentifiedOrganization = Convert.ToByte(arr[3]);
             AuthenticationMechanismMame.DlmsUA = Convert.ToByte(arr[4]);
             AuthenticationMechanismMame.AuthenticationMechanismName = Convert.ToByte(arr[5]);
             AuthenticationMechanismMame.MechanismId = (Authentication)Convert.ToByte(arr[6]);
         }
     }
     else if (index == 7)
     {
         Secret = (byte[])value;
     }
     else if (index == 8)
     {
         if (value == null)
         {
             AssociationStatus = AssociationStatus.NonAssociated;
         }
         else
         {
             AssociationStatus = (AssociationStatus)Convert.ToInt32(value);
         }
     }
     else if (index == 9)
     {
         SecuritySetupReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Пример #4
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         if (CaptureObjects == null || CaptureObjects.Count == 0)
         {
             throw new Exception("Read capture objects first.");
         }
         if (value != null && (value as object[]).Length != 0)
         {
             DateTime lastDate = DateTime.MinValue;
             foreach (object[] row in (value as object[]))
             {
                 if ((row as object[]).Length != CaptureObjects.Count)
                 {
                     throw new Exception("Number of columns do not match.");
                 }
                 for (int pos = 0; pos != row.Length; ++pos)
                 {
                     DataType type = CaptureObjects[pos].Key.GetUIDataType(CaptureObjects[pos].Value.AttributeIndex);
                     if (row[pos] is byte[])
                     {
                         if (type != DataType.None && row[pos] is byte[])
                         {
                             row[pos] = GXDLMSClient.ChangeType(row[pos] as byte[], type);
                             if (row[pos] is GXDateTime)
                             {
                                 GXDateTime dt = (GXDateTime)row[pos];
                                 lastDate = dt.Value;
                             }
                         }
                     }
                     else if (type == DataType.DateTime && row[pos] == null && CapturePeriod != 0)
                     {
                         if (lastDate == DateTime.MinValue && Buffer.Count != 0)
                         {
                             lastDate = ((GXDateTime)Buffer[Buffer.Count - 1].GetValue(pos)).Value;
                         }
                         if (lastDate != DateTime.MinValue)
                         {
                             lastDate = lastDate.AddSeconds(CapturePeriod);
                             row[pos] = new GXDateTime(lastDate);
                         }
                     }
                     if (CaptureObjects[pos].Key is GXDLMSRegister && CaptureObjects[pos].Value.AttributeIndex == 2)
                     {
                         double scaler = (CaptureObjects[pos].Key as GXDLMSRegister).Scaler;
                         if (scaler != 1)
                         {
                             try
                             {
                                 row[pos] = Convert.ToDouble(row[pos]) * scaler;
                             }
                             catch
                             {
                                 //Skip error
                             }
                         }
                     }
                 }
                 Buffer.Add(row);
             }
             EntriesInUse = Buffer.Count;
         }
     }
     else if (index == 3)
     {
         Buffer.Clear();
         EntriesInUse = 0;
         CaptureObjects.Clear();
         GXDLMSObjectCollection objects = new GXDLMSObjectCollection();
         foreach (object it in value as object[])
         {
             object[] tmp = it as object[];
             if (tmp.Length != 4)
             {
                 throw new GXDLMSException("Invalid structure format.");
             }
             ObjectType   type           = (ObjectType)Convert.ToInt16(tmp[0]);
             string       ln             = GXDLMSObject.toLogicalName((byte[])tmp[1]);
             int          attributeIndex = Convert.ToInt16(tmp[2]);
             int          dataIndex      = Convert.ToInt16(tmp[3]);
             GXDLMSObject obj            = null;
             if (Parent != null)
             {
                 obj = Parent.FindByLN(type, ln);
             }
             if (obj == null)
             {
                 obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
             }
             CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
             objects.Add(obj);
         }
         GXDLMSClient.UpdateOBISCodes(objects);
     }
     else if (index == 4)
     {
         CapturePeriod = Convert.ToInt32(value);
     }
     else if (index == 5)
     {
         SortMethod = (SortMethod)Convert.ToInt32(value);
     }
     else if (index == 6)
     {
         if (value != null)
         {
             object[] tmp = value as object[];
             if (tmp.Length != 4)
             {
                 throw new GXDLMSException("Invalid structure format.");
             }
             ObjectType type = (ObjectType)Convert.ToInt16(tmp[0]);
             string     ln   = GXDLMSObject.toLogicalName((byte[])tmp[1]);
             SortAttributeIndex = Convert.ToInt16(tmp[2]);
             SortDataIndex      = Convert.ToInt16(tmp[3]);
             SortObject         = null;
             foreach (var it in CaptureObjects)
             {
                 if (it.Key.ObjectType == type && it.Key.LogicalName == ln)
                 {
                     SortObject = it.Key;
                     break;
                 }
             }
         }
         else
         {
             SortObject = null;
         }
     }
     else if (index == 7)
     {
         EntriesInUse = Convert.ToInt32(value);
     }
     else if (index == 8)
     {
         ProfileEntries = Convert.ToInt32(value);
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }