Ejemplo n.º 1
0
 public MainForm()
 {
     InitializeComponent();
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
     this.IsMdiContainer  = true;
     mainform             = this;
     toolStripComboBox1.Items.Add("Chinese");
     toolStripComboBox1.Items.Add("English");
     toolStripComboBox1.SelectedIndex = 0;
     //toolStripOpen.Text = "  Open  ";
     SwitchShowUI();
     toolStripComboBox1.SelectedIndex = 1;
     UHFAPP.IPConfig.IPEntity ipEntity = IPConfig.getIPConfig();
     if (ipEntity != null)
     {
         txtPort.Text      = ipEntity.Port.ToString();
         ipControl1.IpData = new string[] { ipEntity.Ip[0], ipEntity.Ip[1], ipEntity.Ip[2], ipEntity.Ip[3] };
     }
 }
Ejemplo n.º 2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            //if (btnConnect.Text == strOpen1 || btnConnect.Text == strOpen2)
            if (btnConnect.Text == strOpen1)
            {
                //----------------------------
                if (txtPort.Text == "")
                {
                    MessageBox.Show("fail!");
                    return;
                }
                char[] port = txtPort.Text.ToCharArray();
                for (int k = 0; k < port.Length; k++)
                {
                    if (port[k] != '0' && port[k] != '1' && port[k] != '2' && port[k] != '3' && port[k] != '4' &&
                        port[k] != '5' && port[k] != '6' && port[k] != '7' && port[k] != '8' && port[k] != '9')
                    {
                        MessageBox.Show("only numbers are allowed!");
                        return;
                    }
                }


                uint          portData = uint.Parse(txtPort.Text);
                string[]      tempIp   = ipControl1.IpData;
                StringBuilder sb       = new StringBuilder();
                sb.Append(tempIp[0]);
                sb.Append(".");
                sb.Append(tempIp[1]);
                sb.Append(".");
                sb.Append(tempIp[2]);
                sb.Append(".");
                sb.Append(tempIp[3]);
                string ip = sb.ToString();


                //---------------------------
                string        msg = Common.isEnglish ? "connecting..." : "connecting...";
                frmWaitingBox f   = new frmWaitingBox((obj, args) =>
                {
                    bool result = false;
                    result      = UHFAPI.getInstance().TcpConnect(ip, portData);
                    if (result)
                    {
                        this.Invoke(new EventHandler(delegate
                        {
                            combCommunicationMode.Enabled = false;
                            txtPort.Enabled    = false;
                            ipControl1.Enabled = false;
                            //if (btnConnect.Text == strOpen1)
                            btnConnect.Text = strClose1;

                            /*else
                             *  btnConnect.Text = strClose2;*/

                            isOpen = true;
                            if (eventOpen != null)
                            {
                                eventOpen(true);
                            }

                            UHFAPP.IPConfig.IPEntity entity = new IPConfig.IPEntity();
                            entity.Port = (int)portData;
                            entity.Ip   = ipControl1.IpData;
                            IPConfig.setIPConfig(entity);

                            MenuItemScanEPC.Enabled             = true;
                            MenuItemReadWriteTag.Enabled        = true;
                            configToolStripMenuItem.Enabled     = true;
                            uHFVersionToolStripMenuItem.Enabled = true;
                            killLockToolStripMenuItem.Enabled   = true;
                            toolStripMenuItem1.Enabled          = true;
                            //  MenuItemReceiveEPC.Enabled = true;
                        }));
                    }
                    else
                    {
                        //MessageBox.Show("f");
                        frmWaitingBox.message = "fail";
                        Thread.Sleep(1000);
                    }
                }, msg);
                f.ShowDialog(this);
            }
            else
            {
                UHFAPI.getInstance().TcpDisconnect();
                combCommunicationMode.Enabled = true;
                txtPort.Enabled    = true;
                ipControl1.Enabled = true;
                //if (btnConnect.Text == strClose1)
                btnConnect.Text = strOpen1;

                /*else
                 *  btnConnect.Text = strOpen2;*/

                isOpen = false;
                if (eventOpen != null)
                {
                    eventOpen(false);
                }
                MenuItemScanEPC.Enabled             = false;
                MenuItemReadWriteTag.Enabled        = false;
                configToolStripMenuItem.Enabled     = false;
                uHFVersionToolStripMenuItem.Enabled = false;
                killLockToolStripMenuItem.Enabled   = false;
                toolStripMenuItem1.Enabled          = false;
                //MenuItemReceiveEPC.Enabled = false;
            }
        }