Exemplo n.º 1
0
        /// <summary>
        /// Updates the tag numbers starting from the specified element group node.
        /// </summary>
        private void UpdateTagNums(TreeNode startGroupNode)
        {
            // validate start node
            if (startGroupNode?.Tag is not ElemGroupConfig)
            {
                return;
            }

            // get start tag number
            TreeNode prevGroupNode = startGroupNode.PrevNode;
            int      tagNum        = prevGroupNode?.Tag is ElemGroupConfig prevElemGroup
                ? prevElemGroup.StartTagNum + prevElemGroup.Elems.Count
                : 1;

            // update element groups and elements
            for (int nodeIdx = startGroupNode.Index, nodeCnt = elemGroupsNode.Nodes.Count;
                 nodeIdx < nodeCnt; nodeIdx++)
            {
                TreeNode        groupNode = elemGroupsNode.Nodes[nodeIdx];
                ElemGroupConfig elemGroup = (ElemGroupConfig)groupNode.Tag;
                elemGroup.StartTagNum = tagNum;

                int elemTagNum = tagNum;
                tagNum += elemGroup.Elems.Count;

                foreach (TreeNode elemNode in groupNode.Nodes)
                {
                    ElemTag elem = (ElemTag)elemNode.Tag;
                    elem.TagNum = elemTagNum++;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows the element configuration.
        /// </summary>
        private void ShowElemConfig(ElemTag elemTag)
        {
            ctrlElemGroup.Visible = false;
            ctrlElem.Visible      = true;
            ctrlCmd.Visible       = false;

            ctrlElem.ElemTag = elemTag;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmDeviceTemplate(AppDirs appDirs, CustomUi customUi)
            : this()
        {
            this.appDirs   = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
            this.customUi  = customUi ?? throw new ArgumentNullException(nameof(customUi));
            elemGroupsNode = treeView.Nodes["elemGroupsNode"];
            commandsNode   = treeView.Nodes["commandsNode"];

            template          = null;
            modified          = false;
            selectedNode      = null;
            selectedElemGroup = null;
            selectedElemTag   = null;
            selectedCmd       = null;

            SaveOnly = false;
            FileName = "";
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the child nodes of the specified element group node.
        /// Affects the element address, tag number and node text.
        /// </summary>
        private void UpdateElemNodes(TreeNode groupNode)
        {
            if (groupNode?.Tag is not ElemGroupConfig elemGroup)
            {
                return;
            }

            treeView.BeginUpdate();
            int elemAddr   = elemGroup.Address;
            int elemTagNum = elemGroup.StartTagNum;

            foreach (TreeNode elemNode in groupNode.Nodes)
            {
                ElemTag elemTag = (ElemTag)elemNode.Tag;
                elemTag.Address = elemAddr;
                elemTag.TagNum  = elemTagNum++;
                elemNode.Text   = elemTag.NodeText;
                elemAddr       += (ushort)elemTag.Elem.Quantity;
            }

            treeView.EndUpdate();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fills the tree view according to the device template.
        /// </summary>
        private void FillTree()
        {
            // reset selected objects
            selectedNode      = null;
            selectedElemGroup = null;
            selectedElemTag   = null;
            selectedCmd       = null;
            ShowElemGroupConfig(null);

            try
            {
                treeView.BeginUpdate();
                elemGroupsNode.Nodes.Clear();
                commandsNode.Nodes.Clear();

                // fill element groups
                foreach (ElemGroupConfig elemGroup in template.ElemGroups)
                {
                    elemGroupsNode.Nodes.Add(CreateElemGroupNode(elemGroup));
                }

                // fill commands
                foreach (CmdConfig modbusCmd in template.Cmds)
                {
                    commandsNode.Nodes.Add(CreateCmdNode(modbusCmd));
                }

                elemGroupsNode.Expand();
                commandsNode.Expand();
                treeView.SelectedNode = elemGroupsNode;
            }
            finally
            {
                treeView.EndUpdate();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Shows the element configuration.
        /// </summary>
        private void ShowElemConfig(ElemTag elemTag)
        {
            if (elemTag == null)
            {
                txtElemName.Text           = "";
                txtElemTagCode.Text        = "";
                pnlElemTagCodeWarn.Visible = false;
                txtElemTagNum.Text         = "";
                txtElemAddress.Text        = "";
                rbBool.Checked             = true;
                txtElemByteOrder.Text      = "";
                chkElemReadOnly.Checked    = false;
                chkElemIsBitMask.Checked   = false;
                gbElem.Enabled             = false;
            }
            else
            {
                ElemGroupConfig elemGroup = elemTag.ElemGroup;
                ElemConfig      elem      = elemTag.Elem;

                txtElemName.Text           = elem.Name;
                txtElemTagCode.Text        = elem.TagCode;
                pnlElemTagCodeWarn.Visible = string.IsNullOrEmpty(elem.TagCode);
                txtElemTagNum.Text         = elemTag.TagNum.ToString();
                txtElemAddress.Text        = elemTag.AddressRange;

                if (elem.ElemType == ElemType.Bool)
                {
                    rbUShort.Enabled    = rbShort.Enabled = rbUInt.Enabled = rbInt.Enabled =
                        rbULong.Enabled = rbLong.Enabled = rbFloat.Enabled = rbDouble.Enabled = false;
                    rbBool.Enabled      = true;
                }
                else
                {
                    rbUShort.Enabled    = rbShort.Enabled = rbUInt.Enabled = rbInt.Enabled =
                        rbULong.Enabled = rbLong.Enabled = rbFloat.Enabled = rbDouble.Enabled = true;
                    rbBool.Enabled      = false;
                }

                switch (elem.ElemType)
                {
                case ElemType.UShort:
                    rbUShort.Checked = true;
                    break;

                case ElemType.Short:
                    rbShort.Checked = true;
                    break;

                case ElemType.UInt:
                    rbUInt.Checked = true;
                    break;

                case ElemType.Int:
                    rbInt.Checked = true;
                    break;

                case ElemType.ULong:
                    rbULong.Checked = true;
                    break;

                case ElemType.Long:
                    rbLong.Checked = true;
                    break;

                case ElemType.Float:
                    rbFloat.Checked = true;
                    break;

                case ElemType.Double:
                    rbDouble.Checked = true;
                    break;

                default:
                    rbBool.Checked = true;
                    break;
                }

                txtElemByteOrder.Text    = elem.ByteOrder;
                txtElemByteOrder.Enabled = elemGroup.ByteOrderEnabled;
                chkElemReadOnly.Checked  = elem.ReadOnly;
                chkElemReadOnly.Enabled  = elemGroup.ReadOnlyEnabled;
                chkElemIsBitMask.Checked = elem.IsBitMask;
                chkElemIsBitMask.Enabled = elemGroup.BitMaskEnabled;
                gbElem.Enabled           = true;
            }
        }
Exemplo n.º 7
0
        private ElemTag elemTag; // the element metadata


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public CtrlElem()
        {
            InitializeComponent();
            elemTag = null;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a node that represents the specified element.
 /// </summary>
 private static TreeNode CreateElemNode(ElemTag elemTag)
 {
     return(TreeViewExtensions.CreateNode(elemTag, "elem.png"));
 }