//得到ini中所有IP记录
        private void GetAllAddressFormINI()
        {
            listBox1.Items.Clear();
            byte[] result;

            if (inihelper.ExistINIFile())
            {
                result = inihelper.IniReadValues("DefaultHosts", null);
                string   value = Encoding.Default.GetString(result);
                string[] list  = value.Split('\0');
                foreach (string item in list)
                {
                    if (item != "")
                    {
                        string _value = inihelper.IniReadValue("DefaultHosts", item);
                        listBox1.Items.Add(item + ":" + _value);
                    }
                }
            }
            else
            {
                MessageBox.Show("找不到opcsvc.ini文件!");
            }
        }
Exemple #2
0
        private void Menu_Connect_Click(object sender, EventArgs e)
        {
            server = new MyServer(this);
            try
            {
                server.Start();
                connect = true;
                toolStripStatusLabel1.Text = "连接状态:" + connect;
                button1.Enabled            = true;
                button2.Enabled            = true;
                button3.Enabled            = true;
                button4.Enabled            = true;

                browser = new MyBrowser(server);
                try
                {
                    this.root = browser.GetRoot();
                    //login
                    sessions.Clear();
                    foreach (string item in root)
                    {
                        try
                        {
                            int id = browser.LogInToOpcUser(item);
                            MessageBox.Show(item.ToString() + " Log in to OPC Ok,连接成功!");
                            sessions.Add(new User(id, item));
                        }
                        catch (Exception exc)
                        {
                            MessageBox.Show("Log in to OPC failed", exc.Message);
                        }
                    }

                    //ComboBox
                    byte[]   result;
                    INIClass inihelper = new INIClass(ConfigurationSettings.AppSettings["INIFilePath"]);
                    if (inihelper.ExistINIFile())
                    {
                        result = inihelper.IniReadValues("DefaultHosts", null);
                        string   value = Encoding.Default.GetString(result);
                        string[] list  = value.Split('\0');
                        foreach (string _item in list)
                        {
                            if (_item != "")
                            {
                                string _value = inihelper.IniReadValue("DefaultHosts", _item);
                                comboBox1.Items.Add(_item + ":" + _value);
                                //Items.Add(_item + ":" + _value);
                            }
                        }
                        comboBox1.Enabled       = true;
                        comboBox1.SelectedIndex = 0;
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Browser: parsing error.", exc.Message);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("连接远程服务器出现错误:" + exc.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }