Exemplo n.º 1
0
        private void btn_OK_Click(object sender, EventArgs e)
        {
            bool isConnect = false;                                 // 连接是否成功

            if (cb_ConnectType.SelectedIndex == 0)
            {
                if (cb_ComNum.SelectedIndex >= 0 && cb_BPS.SelectedIndex >= 0)
                {
                    this.tb_ConnParam.Text = cb_ComNum.Text + ":" + cb_BPS.Text;
                    isConnect = CLReader.CreateSerialConn(this.tb_ConnParam.Text, contextForm);
                }
                // Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/ConnectDeviceT", "SerialConnect", tb_ConnParam.Text.Trim());
            }
            else if (cb_ConnectType.SelectedIndex == 1)
            {
                isConnect = CLReader.CreateTcpConn(tb_ConnParam.Text.Trim(), contextForm);
                ////Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/ConnectDeviceT", "TcpConnect", tb_ConnParam.Text.Trim());
            }
            else if (cb_ConnectType.SelectedIndex == 2)
            {
                if (cb_ComNum.SelectedIndex >= 0 && cb_BPS.SelectedIndex >= 0 && !String.IsNullOrEmpty(tb_485Address.Text))
                {
                    this.tb_ConnParam.Text = tb_485Address.Text.Trim() + ":" + cb_ComNum.Text + ":" + cb_BPS.Text;
                    isConnect = CLReader.Create485Conn(this.tb_ConnParam.Text, contextForm);
                }
                // Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/ConnectDeviceT", "_485Connect", tb_ConnParam.Text.Trim());
            }
            if (isConnect)                                          // 如果连接成功
            {
                ////if (contextForm.IsMultiConnect == false)            // 单读写器模式
                ////{
                ////    contextForm.CloseNowConnect();
                ////}
                ////else
                ////{
                if (!String.IsNullOrEmpty(contextForm.ConnID))
                {
                    ClouReaderAPI.CLReader.DIC_CONNECT[contextForm.ConnID].log = null;
                }
                ////}
                contextForm.ConnID = tb_ConnParam.Text.Trim();
                this.DialogResult  = DialogResult.OK;

                //if (this.DialogResult != DialogResult.OK)
                //{
                ////Save to Registry for the connection type
                //RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\AssetSystemInfo");

                ////storing the values
                //key.SetValue("ConnectionType", cb_ConnectType.Text);
                //key.SetValue("ConnectionParam", cb_ComNum.Text);
                //key.SetValue("ConnectionParam2", cb_BPS.Text);
                //key.Close();
                //}
            }
            else
            {
                this.DialogResult = DialogResult.No;
            }
        }
Exemplo n.º 2
0
        // 添加连接事件
        private void contextItem_addConn_Click(object sender, EventArgs e)
        {
            DialogResult dr = DialogResult.No;
            TreeNode     tn = tv_ConnectList.SelectedNode;

            //
            if (tn.Name.Equals("SerialRoot"))
            {
                MyForm.Dialog.AddSerial dialog = new MyForm.Dialog.AddSerial(this);
                dr = dialog.ShowDialog(this);
            }
            else if (tn.Name.Equals("RootTcpClient"))
            {
                CLReader.CreateTcpConn("10.8.170.120:7206", this);
            }
            else if (tn.Name.Equals("RootTcpServer"))
            {
            }
            else
            {
            }
            if (dr == DialogResult.OK)
            {
                FlushTreeView();
            }
        }
Exemplo n.º 3
0
        private void btn_OK_Click(object sender, EventArgs e)
        {
            bool isConnect = false;                                 // 连接是否成功

            if (cb_ConnectType.SelectedIndex == 0)
            {
                if (cb_ComNum.SelectedIndex >= 0 && cb_BPS.SelectedIndex >= 0)
                {
                    this.tb_ConnParam.Text = cb_ComNum.Text + ":" + cb_BPS.Text;
                    isConnect = CLReader.CreateSerialConn(this.tb_ConnParam.Text, contextForm);
                }
                // Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/AddConnect", "SerialConnect", tb_ConnParam.Text.Trim());
            }
            else if (cb_ConnectType.SelectedIndex == 1)
            {
                isConnect = CLReader.CreateTcpConn(tb_ConnParam.Text.Trim(), contextForm);
                Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/AddConnect", "TcpConnect", tb_ConnParam.Text.Trim());
            }
            else if (cb_ConnectType.SelectedIndex == 2)
            {
                if (cb_ComNum.SelectedIndex >= 0 && cb_BPS.SelectedIndex >= 0 && !String.IsNullOrEmpty(tb_485Address.Text))
                {
                    this.tb_ConnParam.Text = tb_485Address.Text.Trim() + ":" + cb_ComNum.Text + ":" + cb_BPS.Text;
                    isConnect = CLReader.Create485Conn(this.tb_ConnParam.Text, contextForm);
                }
                // Helper.MyXmlHelper.UpdateInnerText(XMLFIENAME, "Root/AddConnect", "_485Connect", tb_ConnParam.Text.Trim());
            }
            if (isConnect)                                          // 如果连接成功
            {
                if (contextForm.IsMultiConnect == false)            // 单读写器模式
                {
                    contextForm.CloseNowConnect();
                }
                else
                {
                    if (!String.IsNullOrEmpty(contextForm.ConnID))
                    {
                        ClouReaderAPI.CLReader.DIC_CONNECT[contextForm.ConnID].log = null;
                    }
                }
                contextForm.ConnID = tb_ConnParam.Text.Trim();
                this.DialogResult  = DialogResult.OK;
            }
            else
            {
                this.DialogResult = DialogResult.No;
            }
        }