void UpdateAccessRights(GXDLMSObject obj, Object[] buff) { if (buff.Length != 0) { foreach (Object[] attributeAccess in (Object[])buff[0]) { int id = Convert.ToInt32(attributeAccess[0]); int mode = Convert.ToInt32(attributeAccess[1]); obj.SetAccess(id, (AccessMode)mode); } foreach (Object[] methodAccess in (Object[])buff[1]) { int id = Convert.ToInt32(methodAccess[0]); int tmp; //If version is 0. if (methodAccess[1] is Boolean) { tmp = ((Boolean)methodAccess[1]) ? 1 : 0; } else//If version is 1. { tmp = Convert.ToInt32(methodAccess[1]); } obj.SetMethodAccess(id, (MethodAccessMode)tmp); } } }
void UpdateAccessRights(Object[] buff) { foreach (Object[] access in buff) { ushort sn = Convert.ToUInt16(access[0]); GXDLMSObject obj = ObjectList.FindBySN(sn); if (obj != null) { foreach (Object[] attributeAccess in (Object[])access[1]) { int id = Convert.ToInt32(attributeAccess[0]); int mode = Convert.ToInt32(attributeAccess[1]); obj.SetAccess(id, (AccessMode)mode); } foreach (Object[] methodAccess in (Object[])access[2]) { int id = Convert.ToInt32(methodAccess[0]); int mode = Convert.ToInt32(methodAccess[1]); obj.SetMethodAccess(id, (MethodAccessMode)mode); } } } }
void UpdateAccessRights(List <object> buff) { foreach (List <object> access in buff) { ushort sn = (ushort)((short)access[0] & 0xFFFF); GXDLMSObject obj = ObjectList.FindBySN(sn); if (obj != null) { foreach (List <object> attributeAccess in (List <object>)access[1]) { int id = Convert.ToInt32(attributeAccess[0]); int mode = Convert.ToInt32(attributeAccess[1]); obj.SetAccess(id, (AccessMode)mode); } foreach (List <object> methodAccess in (List <object>)access[2]) { int id = Convert.ToInt32(methodAccess[0]); int mode = Convert.ToInt32(methodAccess[1]); obj.SetMethodAccess(id, (MethodAccessMode)mode); } } } }
private static void UpdateError(GXDLMSObject it, int attributeIndex, Exception ex) { GXDLMSException t = ex as GXDLMSException; if (t != null) { if (t.ErrorCode == 1 || t.ErrorCode == 3) { it.SetAccess(attributeIndex, AccessMode.NoAccess); } else { MessageBox.Show(ex.Message); } } else { throw ex; } }
/// <summary> /// Read object. /// </summary> /// <param name="InitialValues"></param> /// <param name="obj"></param> /// <param name="attribute"></param> public void Read(object sender, GXDLMSObject obj, int attribute) { GXReplyData reply = new GXReplyData(); foreach (int it in (obj as IGXDLMSBase).GetAttributeIndexToRead()) { reply.Clear(); if (obj is GXDLMSProfileGeneric && it == 2) { if (OnBeforeRead != null) { OnBeforeRead(obj, it); } try { CurrentProfileGeneric = obj as GXDLMSProfileGeneric; OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived); if (CurrentProfileGeneric.AccessSelector == AccessRange.Range || CurrentProfileGeneric.AccessSelector == AccessRange.Last) { byte[][] tmp = client.ReadRowsByRange(CurrentProfileGeneric, Convert.ToDateTime(CurrentProfileGeneric.From), Convert.ToDateTime(CurrentProfileGeneric.To)); ReadDataBlock(tmp[0], "Reading profile generic data", 1, reply); } else if (CurrentProfileGeneric.AccessSelector == AccessRange.Entry) { byte[][] tmp = client.ReadRowsByEntry(CurrentProfileGeneric, Convert.ToInt32(CurrentProfileGeneric.From), Convert.ToInt32(CurrentProfileGeneric.To)); ReadDataBlock(tmp[0], "Reading profile generic data " + CurrentProfileGeneric.Name, 1, reply); } else //Read all. { byte[] tmp = client.Read(CurrentProfileGeneric, 2)[0]; ReadDataBlock(tmp, "Reading profile generic data " + CurrentProfileGeneric.Name, 1, reply); } } finally { if (OnAfterRead != null) { OnAfterRead(obj, it); } OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(OnProfileGenericDataReceived); } continue; } else { if (OnBeforeRead != null) { OnBeforeRead(obj, it); } byte[] data = client.Read(obj.Name, obj.ObjectType, it)[0]; try { ReadDataBlock(data, "Read object type " + obj.ObjectType + " index: " + it, reply); } catch (GXDLMSException ex) { if (ex.ErrorCode == 3 || //If read is denied. ex.ErrorCode == 4 || // Undefined object. ex.ErrorCode == 13) //Actaris returns access violation error. { obj.SetAccess(it, AccessMode.NoAccess); continue; } else { throw ex; } } if (obj is IGXDLMSBase) { object value = reply.Value; DataType type; if (value is byte[] && (type = obj.GetUIDataType(it)) != DataType.None) { value = GXDLMSClient.ChangeType((byte[])value, type); } client.UpdateValue(obj, it, value); } if (OnAfterRead != null) { OnAfterRead(obj, it); } obj.SetLastReadTime(it, DateTime.Now); //If only selected attribute is read. if (attribute != 0) { break; } } } }
/// <summary> /// Reserved for internal use. /// </summary> /// <param name="objectType"></param> /// <param name="version"></param> /// <param name="baseName"></param> /// <param name="logicalName"></param> /// <param name="accessRights"></param> /// <param name="attributeIndex"></param> /// <param name="dataIndex"></param> internal static void UpdateObjectData(GXDLMSObject obj, ObjectType objectType, object version, object baseName, object logicalName, object accessRights) { obj.ObjectType = objectType; // Check access rights... if (accessRights != null && accessRights.GetType().IsArray) { //access_rights: access_right object[] access = (object[])accessRights; foreach (object[] attributeAccess in (object[])access[0]) { int id = Convert.ToInt32(attributeAccess[0]); AccessMode mode = (AccessMode)Convert.ToInt32(attributeAccess[1]); //With some meters id is negative. if (id > 0) { obj.SetAccess(id, mode); } } if (((object[])access[1]).Length != 0) { if (((object[])access[1])[0] is object[]) { foreach (object[] methodAccess in (object[])access[1]) { int id = Convert.ToInt32(methodAccess[0]); int tmp; //If version is 0. if (methodAccess[1] is Boolean) { tmp = ((Boolean)methodAccess[1]) ? 1 : 0; } else//If version is 1. { tmp = Convert.ToInt32(methodAccess[1]); } obj.SetMethodAccess(id, (MethodAccessMode)tmp); } } else //All versions from Actaris SL 7000 do not return collection as standard says. { object[] arr = (object[])access[1]; int id = Convert.ToInt32(arr[0]) + 1; int tmp; //If version is 0. if (arr[1] is Boolean) { tmp = ((Boolean)arr[1]) ? 1 : 0; } else//If version is 1. { tmp = Convert.ToInt32(arr[1]); } obj.SetMethodAccess(id, (MethodAccessMode)tmp); } } } if (baseName != null) { obj.ShortName = Convert.ToUInt16(baseName); } if (version != null) { obj.Version = Convert.ToInt32(version); } if (logicalName is byte[]) { obj.LogicalName = GXDLMSObject.toLogicalName((byte[])logicalName); } else { obj.LogicalName = logicalName.ToString(); } }
/// <summary> /// Reserved for internal use. /// </summary> /// <param name="objectType"></param> /// <param name="version"></param> /// <param name="baseName"></param> /// <param name="logicalName"></param> /// <param name="accessRights"></param> /// <param name="attributeIndex"></param> /// <param name="dataIndex"></param> internal static void UpdateObjectData(GXDLMSObject obj, ObjectType objectType, object version, object baseName, object logicalName, object accessRights, int attributeIndex, int dataIndex) { obj.ObjectType = objectType; // Check access rights... if (accessRights != null && accessRights.GetType().IsArray) { //access_rights: access_right object[] access = (object[])accessRights; foreach (object[] attributeAccess in (object[])access[0]) { int id = Convert.ToInt32(attributeAccess[0]); AccessMode mode = (AccessMode)Convert.ToInt32(attributeAccess[1]); //With some meters id is negative. if (id > 0) { obj.SetAccess(id, mode); } } foreach (object[] methodAccess in (object[])access[1]) { int id = Convert.ToInt32(methodAccess[0]); int tmp; //If version is 0. if (methodAccess[1] is Boolean) { tmp = ((Boolean)methodAccess[1]) ? 1 : 0; } else//If version is 1. { tmp = Convert.ToInt32(methodAccess[1]); } obj.SetMethodAccess(id, (MethodAccessMode)tmp); } } ((IGXDLMSColumnObject)obj).SelectedAttributeIndex = attributeIndex; ((IGXDLMSColumnObject)obj).SelectedDataIndex = dataIndex; if (baseName != null) { obj.ShortName = Convert.ToUInt16(baseName); } if (version != null) { obj.Version = Convert.ToInt32(version); } if (logicalName is byte[]) { obj.LogicalName = GXDLMSObject.toLogicalName((byte[])logicalName); } else { obj.LogicalName = logicalName.ToString(); } }
/// <summary> /// Read object. /// </summary> /// <param name="InitialValues"></param> /// <param name="obj"></param> /// <param name="attribute"></param> public void Read(object sender, GXDLMSObject obj, int attribute) { foreach (int it in (obj as IGXDLMSBase).GetAttributeIndexToRead()) { if (obj is GXDLMSProfileGeneric && it == 2) { if (OnBeforeRead != null) { OnBeforeRead(obj, it); } try { CurrentProfileGeneric = obj as GXDLMSProfileGeneric; OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived); if (CurrentProfileGeneric.AccessSelector != AccessRange.Entry) { GXDLMSObject obj2 = CurrentProfileGeneric.CaptureObjects[0].Key; byte[] tmp = m_Cosem.ReadRowsByRange(CurrentProfileGeneric.Name, obj2.LogicalName, obj2.ObjectType, obj2.Version, Convert.ToDateTime(CurrentProfileGeneric.From), Convert.ToDateTime(CurrentProfileGeneric.To)); ReadDataBlock(tmp, "Reading profile generic data", 1); } else { byte[] tmp = m_Cosem.ReadRowsByEntry(CurrentProfileGeneric.Name, Convert.ToInt32(CurrentProfileGeneric.From), Convert.ToInt32(CurrentProfileGeneric.To)); ReadDataBlock(tmp, "Reading profile generic data " + CurrentProfileGeneric.Name, 1); } } finally { if (OnAfterRead != null) { OnAfterRead(obj, it); } OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(OnProfileGenericDataReceived); } continue; } else { if (OnBeforeRead != null) { OnBeforeRead(obj, it); } byte[] data = m_Cosem.Read(obj.Name, obj.ObjectType, it)[0]; try { data = ReadDataBlock(data, "Read object type " + obj.ObjectType + " index: " + it); } catch (GXDLMSException ex) { if (ex.ErrorCode == 3 || //If read is denied. ex.ErrorCode == 4 || // Undefined object. ex.ErrorCode == 13) //Actaris returns access violation error. { obj.SetAccess(it, AccessMode.NoAccess); continue; } else { throw ex; } } if (obj is IGXDLMSBase) { object value = m_Cosem.GetValue(data); DataType type; if (value is byte[] && (type = obj.GetUIDataType(it)) != DataType.None) { value = GXDLMS.Common.GXHelpers.ConvertFromDLMS(value, obj.GetDataType(it), type, true); } (obj as IGXDLMSBase).SetValue(it, value); } if (OnAfterRead != null) { OnAfterRead(obj, it); } obj.SetLastReadTime(it, DateTime.Now); //If only selected attribute is read. if (attribute != 0) { break; } } } }
void UpdateAccessRights(GXDLMSObject obj, Object[] buff) { foreach (Object[] attributeAccess in (Object[])buff[0]) { int id = Convert.ToInt32(attributeAccess[0]); int mode = Convert.ToInt32(attributeAccess[1]); obj.SetAccess(id, (AccessMode)mode); } foreach (Object[] methodAccess in (Object[])buff[1]) { int id = Convert.ToInt32(methodAccess[0]); int tmp; //If version is 0. if (methodAccess[1] is Boolean) { tmp = ((Boolean)methodAccess[1]) ? 1 : 0; } else//If version is 1. { tmp = Convert.ToInt32(methodAccess[1]); } obj.SetMethodAccess(id, (MethodAccessMode)tmp); } }