private void UpdateAttributes()
        {
            bindingSource1.Clear();
            List <GXDLMSAttributeSettings> list = new List <GXDLMSAttributeSettings>();

            string[] names = (Target as IGXDLMSBase).GetNames();
            for (int pos = 0; pos != (Target as IGXDLMSBase).GetAttributeCount(); ++pos)
            {
                GXDLMSAttributeSettings a = new GXDLMSAttributeSettings()
                {
                    Index = pos + 1, Name = names[pos]
                };
                Target.Attributes.Add(a);
                //Logical name is always read-only.
                if (pos == 0)
                {
                    if (version < 3)
                    {
                        a.Access = AccessMode.Read;
                    }
                    else
                    {
                        a.Access3 = AccessMode3.Read;
                    }
                }
                else
                {
                    if (version < 3)
                    {
                        AccessMode mode = Target.GetAccess(1 + pos);
                        a.Access = mode;
                    }
                    else
                    {
                        AccessMode3 mode = Target.GetAccess3(1 + pos);
                        a.Access3 = mode;
                    }
                }
                list.Add(a);
            }
            foreach (var it in list)
            {
                bindingSource1.Add(it);
            }
            Accessrights.DataSource = bindingSource1;
            //Show method access levels of COSEM object.
            bindingSource3.Clear();
            list.Clear();
            //Add all methods.
            names = (Target as IGXDLMSBase).GetMethodNames();
            for (int pos = 0; pos != (Target as IGXDLMSBase).GetMethodCount(); ++pos)
            {
                GXDLMSAttributeSettings a = new GXDLMSAttributeSettings()
                {
                    Index = pos + 1, Name = names[pos]
                };
                Target.MethodAttributes.Add(a);
                if (version < 3)
                {
                    MethodAccessMode mode = Target.GetMethodAccess(1 + pos);
                    a.MethodAccess = mode;
                }
                else
                {
                    MethodAccessMode3 mode = Target.GetMethodAccess3(1 + pos);
                    a.MethodAccess3 = mode;
                }
                list.Add(a);
            }
            foreach (var it in list)
            {
                bindingSource3.Add(it);
            }
            MethodAccessrights.DataSource = bindingSource3;
        }
Example #2
0
        public void OnValueChanged(GXDLMSViewArguments arg)
        {
            GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName;

            //object list.
            if (arg.Index == 2)
            {
                GXDLMSObjectCollection items = target.ObjectList;
                ObjectsView.Items.Clear();
                if (items != null)
                {
                    foreach (GXDLMSObject it in items)
                    {
                        ListViewItem li = ObjectsView.Items.Add(it.ObjectType.ToString());
                        li.SubItems.Add(it.Version.ToString()); //Version
                        li.SubItems.Add(it.LogicalName);
                        li.Tag = it;
                        //access_rights: access_right
                        if (it is IGXDLMSBase)
                        {
                            string str = null;
                            //Show attribute access.
                            int cnt = (it as IGXDLMSBase).GetAttributeCount();
                            for (int pos = 1; pos != cnt + 1; ++pos)
                            {
                                if (str != null)
                                {
                                    str += ", ";
                                }
                                if (target.Version < 3)
                                {
                                    AccessMode mode = it.GetAccess(pos);
                                    str += pos.ToString() + " = " + mode;
                                }
                                else
                                {
                                    AccessMode3 mode = it.GetAccess3(pos);
                                    str += pos.ToString() + " = " + mode;
                                }
                            }
                            li.SubItems.Add(str);
                            //Show method access.
                            str = null;
                            cnt = (it as IGXDLMSBase).GetMethodCount();
                            for (int pos = 1; pos != cnt + 1; ++pos)
                            {
                                if (str != null)
                                {
                                    str += ", ";
                                }
                                if (target.Version < 3)
                                {
                                    MethodAccessMode mode = it.GetMethodAccess(pos);
                                    str += pos.ToString() + " = " + mode;
                                }
                                else
                                {
                                    MethodAccessMode3 mode = it.GetMethodAccess3(pos);
                                    str += pos.ToString() + " = " + mode;
                                }
                            }
                            li.SubItems.Add(str);
                        }
                    }
                }
            }
            //Associated partners ID.
            else if (arg.Index == 3)
            {
                ClientSAPTb.Text = Convert.ToString(target.ClientSAP);
                ServerSAPTb.Text = Convert.ToString(target.ServerSAP);
            }
            else if (arg.Index == 4)
            {
                try
                {
                    this.ApplicationContextIDCb.SelectedIndexChanged -= new System.EventHandler(this.ApplicationContextIDCb_SelectedIndexChanged);
                    ApplicationContextIDCb.Items.Clear();
                    if (target.ApplicationContextName.ContextId == ApplicationContextName.LogicalName ||
                        target.ApplicationContextName.ContextId == ApplicationContextName.LogicalNameWithCiphering)
                    {
                        ApplicationContextIDCb.Items.AddRange(new object[] {
                            ApplicationContextName.LogicalName, ApplicationContextName.LogicalNameWithCiphering
                        });
                    }
                    else
                    {
                        ApplicationContextIDCb.Items.AddRange(new object[] {
                            ApplicationContextName.ShortName, ApplicationContextName.ShortNameWithCiphering
                        });
                    }
                    // Application context name.
                    ApplicationJointISOCTTTb.Text            = Convert.ToString(target.ApplicationContextName.JointIsoCtt);
                    ApplicationCountryTb.Text                = Convert.ToString(target.ApplicationContextName.Country);
                    ApplicationCountryNameTb.Text            = Convert.ToString(target.ApplicationContextName.CountryName);
                    ApplicationIdentifiedOrganizationTb.Text = Convert.ToString(target.ApplicationContextName.IdentifiedOrganization);
                    ApplicationDLMSUATb.Text                        = Convert.ToString(target.ApplicationContextName.DlmsUA);
                    ApplicationContextTb.Text                       = Convert.ToString(target.ApplicationContextName.ApplicationContext);
                    ApplicationContextIDCb.SelectedItem             = target.ApplicationContextName.ContextId;
                    ApplicationRegistrationAuthorityCb.SelectedItem = FindCountry(target.ApplicationContextName.JointIsoCtt, target.ApplicationContextName.Country, target.ApplicationContextName.CountryName);
                }
                finally
                {
                    ApplicationContextIDCb.SelectedIndexChanged += new System.EventHandler(this.ApplicationContextIDCb_SelectedIndexChanged);
                }
            }
            else if (arg.Index == 5)
            {
                // xDLMS_context_info
                ShowConformance(target.XDLMSContextInfo.Conformance);
                MaxReceivePDUSizeTb.Text = target.XDLMSContextInfo.MaxReceivePduSize.ToString();
                MaxSendPDUSizeTb.Text    = target.XDLMSContextInfo.MaxSendPduSize.ToString();
                DLMSVersionNumberTB.Text = target.XDLMSContextInfo.DlmsVersionNumber.ToString();
                CypheringInfoTb.Text     = GXDLMSTranslator.ToHex(target.XDLMSContextInfo.CypheringInfo);
            }
            else if (arg.Index == 6)
            {
                Freeze = true;
                // authentication_mechanism_name
                AuthenticationJointISOCTTTb.Text            = Convert.ToString(target.AuthenticationMechanismName.JointIsoCtt);
                AuthenticationCountryTb.Text                = Convert.ToString(target.AuthenticationMechanismName.Country);
                AuthenticationCountryNameTb.Text            = Convert.ToString(target.AuthenticationMechanismName.CountryName);
                AuthenticationIdentifiedorganizationTb.Text = Convert.ToString(target.AuthenticationMechanismName.IdentifiedOrganization);
                AuthenticationDLMSUATb.Text        = Convert.ToString(target.AuthenticationMechanismName.DlmsUA);
                AuthenticationMechanismNameTb.Text = Convert.ToString(target.AuthenticationMechanismName.AuthenticationMechanismName);
                AuthenticationMechanismIdCb.Text   = Convert.ToString(target.AuthenticationMechanismName.MechanismId);
                AuthenticationRegistrationAuthorityCb.SelectedItem = FindCountry(target.AuthenticationMechanismName.JointIsoCtt, target.AuthenticationMechanismName.Country, target.AuthenticationMechanismName.CountryName);
                Freeze = false;
            }
            else if (arg.Index == 7)
            {
                //Secret.
                if (GXHelpers.IsAscii(target.Secret))
                {
                    SecretAsciiCb.Checked = true;
                    SecretTB.Text         = ASCIIEncoding.ASCII.GetString(target.Secret);
                }
                else
                {
                    SecretTB.Text = GXDLMSTranslator.ToHex(target.Secret);
                }
            }
            else if (arg.Index == 9)
            {
                SecuritySetupCb.Items.Clear();
                //security_setup_reference
                if (target.Parent != null)
                {
                    SecuritySetupCb.Items.Add("");
                    foreach (GXDLMSSecuritySetup it in target.Parent.GetObjects(ObjectType.SecuritySetup))
                    {
                        SecuritySetupCb.Items.Add(it);
                        if (target.SecuritySetupReference == it.LogicalName)
                        {
                            SecuritySetupCb.SelectedIndexChanged -= new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                            SecuritySetupCb.SelectedItem          = it;
                            SecuritySetupCb.SelectedIndexChanged += new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                        }
                    }
                }
                else
                {
                    GXDLMSSecuritySetup it = new GXDLMSSecuritySetup(target.SecuritySetupReference);
                    SecuritySetupCb.Items.Add(it);
                    SecuritySetupCb.SelectedIndexChanged -= new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                    SecuritySetupCb.SelectedItem          = it;
                    SecuritySetupCb.SelectedIndexChanged += new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                }
            }
            //User list.
            else if (arg.Index == 10)
            {
                List <KeyValuePair <byte, string> > items = target.UserList;
                UsersList.Items.Clear();
                if (items != null)
                {
                    foreach (KeyValuePair <byte, string> it in items)
                    {
                        ListViewItem li = UsersList.Items.Add(it.Key.ToString());
                        li.SubItems.Add(it.Value);
                        li.Tag = it.Key;
                    }
                }
            }
            else if (arg.Index == 11) //Current user
            {
                foreach (ListViewItem it in UsersList.Items)
                {
                    if ((byte)it.Tag == target.CurrentUser.Key)
                    {
                        it.Selected = true;
                    }
                    else if (it.Selected)
                    {
                        it.Selected = false;
                    }
                }
            }
        }
Example #3
0
        public void OnValueChanged(GXDLMSViewArguments arg)
        {
            GXDLMSAssociationShortName target = Target as GXDLMSAssociationShortName;
            GXDLMSObjectCollection     items  = target.ObjectList;

            if (arg.Index == 2)
            {
                ObjectsView.Items.Clear();
                if (items != null)
                {
                    SNItems.Clear();
                    foreach (GXDLMSObject it in items)
                    {
                        ListViewItem li = ObjectsView.Items.Add(Convert.ToString(it.ShortName, 16));
                        li.SubItems.AddRange(new string[] { it.ObjectType.ToString(), it.Version.ToString(),
                                                            it.LogicalName });
                        //access_rights: access_right
                        StringBuilder str = new StringBuilder();
                        //Show attribute access.
                        int cnt = (it as IGXDLMSBase).GetAttributeCount();
                        for (int pos = 1; pos != cnt + 1; ++pos)
                        {
                            if (str != null)
                            {
                                str.Append(", ");
                            }
                            if (target.Version < 3)
                            {
                                AccessMode mode = it.GetAccess(pos);
                                str.Append(pos.ToString() + " = " + mode);
                            }
                            else
                            {
                                AccessMode3 mode = it.GetAccess3(pos);
                                str.Append(pos.ToString() + " = " + mode);
                            }
                        }
                        li.SubItems.Add(str.ToString());
                        //Show method access.
                        str.Length = 0;
                        cnt        = (it as IGXDLMSBase).GetMethodCount();
                        for (int pos = 1; pos != cnt + 1; ++pos)
                        {
                            if (str != null)
                            {
                                str.Append(", ");
                            }
                            if (target.Version < 3)
                            {
                                MethodAccessMode mode = it.GetMethodAccess(pos);
                                str.Append(pos.ToString() + " = " + mode);
                            }
                            else
                            {
                                MethodAccessMode3 mode = it.GetMethodAccess3(pos);
                                str.Append(pos.ToString() + " = " + mode);
                            }
                        }
                        li.SubItems.Add(str.ToString());
                        if (it.ShortName != 0)
                        {
                            SNItems.Add(it.ShortName, li);
                        }
                        li.Tag = it;
                    }
                }
            }
            //Update Access rights.
            if (arg.Index == 3)
            {
                //access_rights: access_right
                foreach (GXDLMSObject it in items)
                {
                    ListViewItem  li  = SNItems[it.ShortName];
                    StringBuilder str = new StringBuilder();
                    //Show attribute access.
                    int cnt = (it as IGXDLMSBase).GetAttributeCount();
                    for (int pos = 1; pos != cnt + 1; ++pos)
                    {
                        if (str != null)
                        {
                            str.Append(", ");
                        }
                        AccessMode mode = it.GetAccess(pos);
                        str.Append(pos.ToString() + " = " + mode);
                    }
                    li.SubItems[4].Text = str.ToString();
                    //Show method access.
                    str.Length = 0;
                    cnt        = (it as IGXDLMSBase).GetMethodCount();
                    for (int pos = 1; pos != cnt + 1; ++pos)
                    {
                        if (str != null)
                        {
                            str.Append(", ");
                        }
                        MethodAccessMode mode = it.GetMethodAccess(pos);
                        str.Append(pos.ToString() + " = " + mode);
                    }
                    li.SubItems[5].Text = str.ToString();
                }
            }
            //security_setup_reference
            else if (arg.Index == 4)
            {
                //security_setup_reference
                foreach (GXDLMSSecuritySetup it in target.Parent.GetObjects(ObjectType.SecuritySetup))
                {
                    SecuritySetupCb.Items.Add(it);
                    if (target.SecuritySetupReference == it.LogicalName)
                    {
                        SecuritySetupCb.SelectedIndexChanged -= new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                        SecuritySetupCb.SelectedItem          = it;
                        SecuritySetupCb.SelectedIndexChanged += new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged);
                    }
                }
            }
        }