// Button Connect // Uses the new IP-address from textbox1 and tries to set up a connection. // If it was successful, the timer is initialized and started. private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; try { textBox2.Text = "Trying to connect..."; toolStripLabel1.Text = "connecting"; textBox2.TextAlign = HorizontalAlignment.Left; pictureBox1.Image = Properties.Resources.NE107_DiagnosisPassive; Update(); string tempIpAddress = textBox1.Text; _wtxObj.getConnection.IpAddress = tempIpAddress; // Equal to : ModbusObj.IP_Adress = tempIpAddress; // The connection to the device should be established. _wtxObj.getConnection.Connect(); // Alternative : _wtxObj.Connect(); if (_wtxObj.getConnection.IsConnected) { _wtxObj.RestartTimer(); _ipAddress = tempIpAddress; this.toolStripLabel1.Text = "connected"; RenameButtonGrossNet(); _wtxObj.getConnection.SendingInterval = this._timerInterval; } else { _wtxObj.getConnection.IpAddress = this._ipAddress; _wtxObj.StopTimer(); textBox2.Text = "Connection could not be established!" + Environment.NewLine + "Please check connection or IP-Address."; toolStripLabel1.Text = "disconnected"; toolStripLabel3.Text = "Gross/Net"; } } finally { button1.Enabled = true; } }