Пример #1
0
        private void UDPConnect()
        {
            if (udpPU == null && udpPK == null && udpPTVC == null)
            {
                try
                {
                    udpPU = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort1.Text));
                    udpPK = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort2.Text));
                    udpPTVC = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort3.Text));

                    if (udpPU.Open() && udpPK.Open() && udpPTVC.Open())
                    {
                        cntTimeouts       = 0; cntSuccess = 0;
                        udpPU.received   += udp_receivedPU;
                        udpPK.received   += udp_receivedPK;
                        udpPTVC.received += udp_receivedPTVC;

                        btnConnect.Text      = "Стоп обмен";
                        btnConnect.BackColor = Color.LightGreen;
                    }
                    else
                    {
                        MessageBox.Show("Ошибка открытия порта!","DSP Firmware");
                        //AddToList("Ошибка подключения");
                        btnConnect.Text      = "Старт обмен";
                        btnConnect.BackColor = Color.Transparent;

                        udpPU   = null;
                        udpPK   = null;
                        udpPTVC = null;
                    }
                }
                catch (Exception ex) { udpPU = null; udpPK = null; udpPTVC = null; MessageBox.Show(ex.Message + "\n\n\nНе удалось установить соединение.","UDP Connect"); }
            }
            else
            {
                try
                {
                    udpPU.Close();
                    udpPK.Close();
                    udpPTVC.Close();
                    btnConnect.BackColor = Color.Transparent;
                    btnConnect.Text      = "Старт обмен";
                    bCommandBusy         = false;
                    udpPU   = null;
                    udpPK   = null;
                    udpPTVC = null;
                }
                catch (Exception ex) { udpPU = null; udpPK = null; udpPTVC = null; MessageBox.Show(ex.Message,"UDPConnect"); }
            }
        }
Пример #2
0
        public void UDPConnect()
        {
            if (udpPU == null && udpPK == null && udpPTVC == null)
            {
                try
                {
                    udpPU = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort1.Text));
                    udpPK = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort2.Text));
                    udpPTVC = new Udp(
                        new System.Net.IPAddress(getIPAddr(1)),
                        int.Parse(_frmMainWindow._frmSettings.txtIPPort3.Text));

                    if (udpPU.Open() && udpPK.Open() && udpPTVC.Open())
                    {
                        _frmBoardSignals.countSuccessPU     = _frmBoardSignals.countSuccessPK = _frmBoardSignals.countSuccessPTVC =
                            _frmBoardSignals.countTimeoutPU = _frmBoardSignals.countTimeoutPK = _frmBoardSignals.countTimeoutPTVC = 0;

                        udpPU.received   += _frmBoardSignals.udp_receivedPU;
                        udpPK.received   += _frmBoardSignals.udp_receivedPK;
                        udpPTVC.received += _frmBoardSignals.udp_receivedPTVC;

                        //btnConnect.Text = "Стоп обмен";
                        //btnConnect.BackColor = Color.LightGreen;

                        this.Text        = sTitleMainForm + " | Подключение установлено. " + sVersion;
                        panel1.BackColor = Color.LightGreen;
                    }
                    else
                    {
                        //MessageBox.Show("Ошибка открытия порта!", "DSP Firmware");
                        //btnConnect.Text = "Старт обмен";
                        //btnConnect.BackColor = Color.Transparent;
                        this.Text        = sTitleMainForm + " | Ошибка открытия портов. " + sVersion;
                        panel1.BackColor = Color.Red;

                        udpPU   = null;
                        udpPK   = null;
                        udpPTVC = null;
                    }
                }
                catch
                {
                    if (udpPU != null)
                    {
                        udpPU.Close(); udpPU = null;
                    }
                    if (udpPK != null)
                    {
                        udpPK.Close(); udpPK = null;
                    }
                    if (udpPTVC != null)
                    {
                        udpPTVC.Close(); udpPTVC = null;
                    }
                    this.Text        = sTitleMainForm + " | Ошибка соединения. " + sVersion; //MessageBox.Show(ex.Message + "\n\n\nНе удалось установить соединение.", "UDP Connect");
                    panel1.BackColor = Color.Red;
                }
            }
            else
            {
                try
                {
                    udpPU.Close();
                    udpPK.Close();
                    udpPTVC.Close();

                    this.Text        = sTitleMainForm + " | Подключение не установлено. " + sVersion;
                    panel1.BackColor = Color.Transparent;

                    bCommandBusyPK = bCommandBusyPTVC = bCommandBusyPU = false;

                    udpPU   = null;
                    udpPK   = null;
                    udpPTVC = null;
                }
                catch
                {
                    udpPU            = null;
                    udpPK            = null;
                    udpPTVC          = null;
                    this.Text        = sTitleMainForm + " | Ошибка закрытия соединения. " + sVersion;
                    panel1.BackColor = Color.Red;
                    //MessageBox.Show(ex.Message, "UDPConnect");
                }
            }
        }