Пример #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            byte[] ip             = new byte[32];
            int    CommPort       = 0;
            uint   PortOrBaudRate = 0;

            if ((!Regex.IsMatch(comboBoxIP.Text, "^[0-9.]+$")) || comboBoxIP.Text.Length < 7 || comboBoxIP.Text.Length > 15)
            {
                MessageBox.Show(rm.GetString("strMsgInvalidIPAdd"));
                return;
            }
            ip = Encoding.ASCII.GetBytes(comboBoxIP.Text);     // 由string获得byte数组
            if (!Regex.IsMatch(textBoxPort.Text, "^[0-9]+$") || textBoxPort.Text.Length > 5)
            {
                MessageBox.Show(rm.GetString("strMsgInvalidPort"));
                return;
            }
            PortOrBaudRate = UInt32.Parse(textBoxPort.Text);
            // 使用委托异步线程执行连接,同时启动定时器,等待
            DeleConnectDev dcd = new DeleConnectDev(ConnectDevice);

            dcd.BeginInvoke(ip, CommPort, PortOrBaudRate, null, null);
            bConnected            = false;
            timerConnect.Interval = 3000; // 等待3秒时间
            timerConnect.Start();
        }
Пример #2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            byte[] ip = new byte[32];  // required by RFID Reader API
            ip = Encoding.ASCII.GetBytes(comboBoxIP.Text);
            uint port = UInt32.Parse(textBoxPort.Text);

            // TODO: check IP and port here

            DeleConnectDev dcd = new DeleConnectDev(ConnectDevice);
            dcd.BeginInvoke(ip, port, null, null);

            labelMsg.Text = "连接中...";
            _bConnected = false;  // init status value for the new connect
            btnDisconnect.Enabled = true;
            btnConnect.Enabled = false;
            btnStartReadData.Enabled = false;
            btnStopReadData.Enabled = false;
            comboBoxIP.Enabled = false;
            textBoxPort.Enabled = false;

            timerConnect.Interval = HttpCfg.rfid_timeout;  // timer for connect timeout
            timerConnect.Start();
        }