Пример #1
0
 public PortCommandsEditForm(PortCommands[] portCommands)
 {
     InitializeComponent();
     m_portCommands         = portCommands[0];
     m_portCommands_default = portCommands[1];
     m_datatable            = m_portCommands.CreateDataTable();
     m_datatable_default    = portCommands[1].CreateDataTable();
     if (m_datatable != null)
     {
         DataSet dataset = (DataSet)(dgvPortCommands.DataSource);
         if (dataset != null)
         {
             dataset.Dispose();
         }
         dataset = new DataSet();
         dataset.Tables.Add(m_datatable);
         dgvPortCommands.DataSource = dataset;
         dgvPortCommands.DataMember = "PortCommands";
     }
     dgvPortCommands.Columns[dgvPortCommands.Columns.Count - 1].Visible = false;
 }
Пример #2
0
        private void SetPortConfigDisplay()
        {
            int node_id = 0;

            this.Text = "ConfigTool  -" + m_portConfigFile.FileName;
            tvPortInfo.BeginUpdate();
            tvPortInfo.Nodes.Add("Module Config");
            tvPortInfo.Nodes[0].ContextMenuStrip = cmsPortConfig;

            if (m_portConfigFile.m_portConfigArray.Count > 0)
            {
                tvPortInfo.Nodes[0].Nodes.Add("Group Port Config");
                for (int i = 0; i < m_portConfigFile.m_portConfigArray.Count; i++)
                {
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortConfig)(m_portConfigFile.m_portConfigArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig;

                    PortConfig[] currentPortConfig = new PortConfig[] { (PortConfig)m_portConfigFile.m_portConfigArray[i],
                                                                        (PortConfig)m_portConfigFile_default.m_portConfigArray[i] };

                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortConfig;
                }

                node_id++;
            }
            if (m_portConfigFile.m_portCommandsArray.Count > 0)
            {
                tvPortInfo.Nodes[0].Nodes.Add("Group Port Commands");
                for (int i = 0; i < m_portConfigFile.m_portCommandsArray.Count; i++)
                {
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortCommands)(m_portConfigFile.m_portCommandsArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig;
                    PortCommands[] currentPortCommands = new PortCommands[] { (PortCommands)m_portConfigFile.m_portCommandsArray[i],
                                                                              (PortCommands)m_portConfigFile_default.m_portCommandsArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortCommands;
                }
                node_id++;
            }
            if (m_portConfigFile.m_pcPortConfigArray.Count > 0)
            {
                tvPortInfo.Nodes[0].Nodes.Add("Modbus PC Port");
                for (int i = 0; i < m_portConfigFile.m_pcPortConfigArray.Count; i++)
                {
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add("Modbus PC Port " + i);
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig;
                    PortConfig[] currentPortConfig = new PortConfig[] { (PortConfig)m_portConfigFile.m_pcPortConfigArray[i],
                                                                        (PortConfig)m_portConfigFile_default.m_pcPortConfigArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortConfig;
                }
                node_id++;
            }
            if (m_portConfigFile.m_pcPortCommandsArray.Count > 0)
            {
                tvPortInfo.Nodes[0].Nodes.Add("Modbus PC Port Commands");
                for (int i = 0; i < m_portConfigFile.m_pcPortCommandsArray.Count; i++)
                {
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortCommands)(m_portConfigFile.m_pcPortCommandsArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig;
                    PortCommands[] currentPortCommands = new PortCommands[] { (PortCommands)m_portConfigFile.m_pcPortCommandsArray[i],
                                                                              (PortCommands)m_portConfigFile_default.m_pcPortCommandsArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortCommands;
                }
                node_id++;
            }

            if (m_portConfigFile.m_etherNetPortArray.Count > 0)
            {
                tvPortInfo.Nodes[0].Nodes.Add("EtherNet");
                for (int i = 0; i < m_portConfigFile.m_etherNetPortArray.Count; i++)
                {
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetPortArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig;
                    PortConfig[] currentEtherNet = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetPortArray[i],
                                                                      (PortConfig)m_portConfigFile_default.m_etherNetPortArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentEtherNet;

                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetClientConfigArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[0].ContextMenuStrip = cmsPortConfig;
                    PortConfig[] curEtherNetClientCfg = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetClientConfigArray[i],
                                                                           (PortConfig)m_portConfigFile_default.m_etherNetClientConfigArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[0].Tag = curEtherNetClientCfg;

                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortCommands)(m_portConfigFile.m_etherNetClientCommandsArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[1].ContextMenuStrip = cmsPortConfig;
                    PortCommands[] curEtherNetClientCmd = new PortCommands[] { (PortCommands)m_portConfigFile.m_etherNetClientCommandsArray[i],
                                                                               (PortCommands)m_portConfigFile_default.m_etherNetClientCommandsArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[1].Tag = curEtherNetClientCmd;


                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetServerConfigArray[i])).GetName());
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[2].ContextMenuStrip = cmsPortConfig;
                    PortConfig[] curEtherNetServerCfg = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetServerConfigArray[i],
                                                                           (PortConfig)m_portConfigFile_default.m_etherNetServerConfigArray[i] };
                    tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[2].Tag = curEtherNetServerCfg;
                }
                node_id++;
            }

            tvPortInfo.Nodes[0].Nodes.Add(m_portConfigFile.m_dataRemap.GetName());
            tvPortInfo.Nodes[0].Nodes[node_id].ContextMenuStrip = cmsPortConfig;
            PortCommands[] curDataRemap = new PortCommands[] { (PortCommands)m_portConfigFile.m_dataRemap,
                                                               (PortCommands)m_portConfigFile_default.m_dataRemap };
            tvPortInfo.Nodes[0].Nodes[node_id].Tag = curDataRemap;

            tvPortInfo.Nodes[0].Expand();
            tvPortInfo.EndUpdate();
            ShowAllContent();
        }
Пример #3
0
        public int PortConfigInit(string filename)
        {
            FileStream fs;

            byte[] b = null;

            int          buffer_start;
            int          buffer_len;
            string       field_name = null;
            UTF8Encoding temp       = new UTF8Encoding(true);
            string       content    = null;

            if (filename != null)
            {
                using (fs = File.OpenRead(filename))
                {
                    b = new byte[fs.Length];
                    if (fs.Read(b, 0, (int)fs.Length) != fs.Length)
                    {
                        return(-1);
                    }
                }
            }

            m_xmlDoc = new XmlDocument();
            string desc_file = System.Windows.Forms.Application.StartupPath + "\\description.xml";

            if (!File.Exists(desc_file))
            {
                File.WriteAllText(desc_file, Config.Resource.Resource.Description);
            }
            //m_xmlDoc.LoadXml(Config.Resource.Resource.Description);
            m_xmlDoc.Load(desc_file);
            if (filename != null)
            {
                content = temp.GetString(b).Replace("	", "    ");
                //buffer_start = 0;
                buffer_start   = content.IndexOf(MODULE_HASH);
                buffer_len     = content.IndexOf('[', buffer_start + 1) - buffer_start;
                m_moduleConfig = content.Substring(buffer_start, buffer_len);
                //m_moduleConfig = new PortConfig(MODULE_HASH, content.Substring(buffer_start, buffer_len));
            }
            for (int i = 0; i < PORT_CFG_NUM; i++)
            {
                if (i >= PORT_CFG_NUM / 2)
                {
                    field_name = "[Modbus G" + (i - PORT_CFG_NUM / 2 + 1) + "B]";
                }
                else
                {
                    field_name = "[Modbus G" + (i + 1) + "A]";
                }

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }

                        m_portConfigArray.Add(new PortConfig(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_PORT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_PORT_CONFIG)));
                    }
                }
                else
                {
                    m_portConfigArray.Add(new PortConfig(field_name, null, Config.EditType.EDIT_PORT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_PORT_CONFIG)));
                }
            }
            for (int i = 0; i < PORT_CFG_NUM; i++)
            {
                if (i >= PORT_CFG_NUM / 2)
                {
                    field_name = "[Modbus G" + (i - PORT_CFG_NUM / 2 + 1) + "B Commands]";
                }
                else
                {
                    field_name = "[Modbus G" + (i + 1) + "A Commands]";
                }

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }
                        m_portCommandsArray.Add(new PortCommands(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_PORT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_PORT_COMMAND)));
                    }
                }
                else
                {
                    m_portCommandsArray.Add(new PortCommands(field_name, null, Config.EditType.EDIT_PORT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_PORT_COMMAND)));
                }
            }
            for (int i = 0; i < PORT_PC_NUM; i++)
            {
                field_name = "[Modbus PC Port " + i + "]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }

                        m_pcPortConfigArray.Add(new PortConfig(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_PCPORT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_PCPORT_CONFIG)));
                    }
                }
                else
                {
                    m_pcPortConfigArray.Add(new PortConfig(field_name, null, Config.EditType.EDIT_PCPORT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_PCPORT_CONFIG)));
                }
            }
            for (int i = 0; i < PORT_PC_NUM; i++)
            {
                field_name = "[Modbus PC Port " + i + " Commands]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }

                        m_pcPortCommandsArray.Add(new PortCommands(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_PCPORT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_PCPORT_COMMAND)));
                    }
                }
                else
                {
                    m_pcPortCommandsArray.Add(new PortCommands(field_name, null, Config.EditType.EDIT_PCPORT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_PCPORT_COMMAND)));
                }
            }

            for (int i = 0; i < PORT_ETHERNET_NUM; i++)
            {
                field_name = "[Ethernet " + i + "]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }
                        m_etherNetPortArray.Add(new PortConfig(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_ETHERNET_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CONFIG)));
                    }
                }
                else
                {
                    m_etherNetPortArray.Add(new PortConfig(field_name, null, Config.EditType.EDIT_ETHERNET_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CONFIG)));
                }
            }
            for (int i = 0; i < PORT_ETHERNET_NUM; i++)
            {
                field_name = "[Ethernet Client " + i + "]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }
                        m_etherNetClientConfigArray.Add(new PortConfig(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_ETHERNET_CLIENT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CLIENT_CONFIG)));
                    }
                }
                else
                {
                    m_etherNetClientConfigArray.Add(new PortConfig(field_name, null, Config.EditType.EDIT_ETHERNET_CLIENT_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CLIENT_CONFIG)));
                }
            }
            for (int i = 0; i < PORT_ETHERNET_NUM; i++)
            {
                field_name = "[Ethernet Client " + i + " Commands]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }
                        m_etherNetClientCommandsArray.Add(new PortCommands(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_ETHERNET_CLIENT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CLIENT_COMMAND)));
                    }
                }
                else
                {
                    m_etherNetClientCommandsArray.Add(new PortCommands(field_name, null, Config.EditType.EDIT_ETHERNET_CLIENT_COMMAND, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_CLIENT_COMMAND)));
                }
            }
            for (int i = 0; i < PORT_ETHERNET_NUM; i++)
            {
                field_name = "[Ethernet Server " + i + "]";

                if (filename != null)
                {
                    buffer_start = content.IndexOf(field_name);
                    if (buffer_start > 0)
                    {
                        buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                        if (buffer_len < 0)
                        {
                            buffer_len = content.Length - buffer_start;
                        }
                        m_etherNetServerConfigArray.Add(new PortConfig(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_ETHERNET_SERVER_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_SERVER_CONFIG)));
                    }
                }
                else
                {
                    m_etherNetServerConfigArray.Add(new PortConfig(field_name, null, Config.EditType.EDIT_ETHERNET_SERVER_CONFIG, GetXmlNodeList(Config.EditType.EDIT_ETHERNET_SERVER_CONFIG)));
                }
            }

            field_name = "[Data Remap]";
            if (filename != null)
            {
                buffer_start = content.IndexOf(field_name);
                if (buffer_start > 0)
                {
                    buffer_len = content.IndexOf('[', buffer_start + 1) - buffer_start;
                    if (buffer_len < 0)
                    {
                        buffer_len = content.Length - buffer_start;
                    }
                    m_dataRemap = new PortCommands(field_name, content.Substring(buffer_start, buffer_len), Config.EditType.EDIT_DATA_REMAP, GetXmlNodeList(Config.EditType.EDIT_DATA_REMAP));
                }
            }
            else
            {
                m_dataRemap = new PortCommands(field_name, null, Config.EditType.EDIT_DATA_REMAP, GetXmlNodeList(Config.EditType.EDIT_DATA_REMAP));
            }
            PortConfigCheckContent();

            return(1);
        }