private void connectButton_Click(object sender, RoutedEventArgs e) { if (ipTextBox.Text == "") { return; } if (portTextBox.Text == "") { return; } try { mcOMRON.tcpFINSCommand tcpCommand = ((mcOMRON.tcpFINSCommand)plc.FinsCommand); tcpCommand.SetTCPParams(IPAddress.Parse(ipTextBox.Text), Convert.ToInt32(portTextBox.Text)); if (!plc.Connect()) { throw new Exception(plc.LastError); } } catch (Exception ex) { MessageBox.Show("Connect() error: " + ex.Message); } ipTextBox.IsEnabled = false; portTextBox.IsEnabled = false; }
private void connectButton_Click(object sender, RoutedEventArgs e) { //if (ipTextBox.Text == "") return; //if (portTextBox.Text == "") return; if (ipTextBox.Text == "" && portTextBox.Text == "") { MessageBox.Show("Сработала заглушка! Соединения утсановлено не было, т.к. отсутствуют IP и PORT.", "Warning!"); } try { mcOMRON.tcpFINSCommand tcpCommand = ((mcOMRON.tcpFINSCommand)plc.FinsCommand); tcpCommand.SetTCPParams(IPAddress.Parse(ipTextBox.Text), Convert.ToInt32(portTextBox.Text)); if (!plc.Connect()) { throw new Exception(plc.LastError); } } catch (Exception ex) { MessageBox.Show("Connect() error: " + ex.Message); } ipTextBox.IsEnabled = false; portTextBox.IsEnabled = false; }
/// <summary> /// try to connect to the plc /// </summary> private void Connect() { if (ip.Text == "") { return; } if (port.Text == "") { return; } try { // set ip:port for command layer, may cast to tcpFINSCommand to set ip and port // mcOMRON.tcpFINSCommand tcpCommand = ((mcOMRON.tcpFINSCommand)plc.FinsCommand); tcpCommand.SetTCPParams(IPAddress.Parse(ip.Text), Convert.ToInt32(port.Text)); // connection // if (!plc.Connect()) { throw new Exception(plc.LastError); } // set UI // bt_connect.Enabled = false; ip.Enabled = false; port.Enabled = false; bt_close.Enabled = true; bt_connection_data_read.Enabled = true; groupDM.Enabled = true; groupDMs.Enabled = true; groupDialogText.Enabled = true; groupCIO.Enabled = true; dialog.Clear(); } catch (Exception ex) { MessageBox.Show("Connect() error: " + ex.Message); } }