コード例 #1
0
        public flap_1()
        {
            InitializeComponent();
            // this.plc = new mcOMRON.OmronPLC(mcOMRON.TransportType.Tcp);

            cnt.ipTextBox.Text   = "192.168.250.1";
            cnt.portTextBox.Text = "9600";
            if (cnt.ipTextBox.Text == "")
            {
                return;
            }
            if (cnt.portTextBox.Text == "")
            {
                return;
            }

            try
            {
                mcOMRON.tcpFINSCommand tcpCommand = ((mcOMRON.tcpFINSCommand)cnt.plc.FinsCommand);
                tcpCommand.SetTCPParams(IPAddress.Parse(cnt.ipTextBox.Text), Convert.ToInt32(cnt.portTextBox.Text));

                if (!cnt.plc.Connect())
                {
                    throw new Exception(cnt.plc.LastError);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connect() error: " + ex.Message);
            }

            cnt.ipTextBox.IsEnabled   = false;
            cnt.portTextBox.IsEnabled = false;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: fr830/scada-old
        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;
        }
コード例 #4
0
        //-------------------------------------------------------------------------------------------------

        /**
         * <summary>
         *  Set Parameter (IP, Port)
         * </summary>
         * <param name="strIp">IP 주소</param>
         * <param name="nPort">Port No.</param>
         * @author    이준호(LEEJOONHO)
         * @date      2020/03/16 15:35
         */
        public bool fn_SetParam(string strIp, int nPort)
        {
            try
            {
                mcOMRON.tcpFINSCommand tcpCommand = ((mcOMRON.tcpFINSCommand) this.FinsCommand);
                tcpCommand.SetTCPParams(IPAddress.Parse(strIp), Convert.ToInt32(nPort));
                return(true);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return(false);
            }
        }
コード例 #5
0
ファイル: TestPLC.cs プロジェクト: mcNets/mcOmron
        /// <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);
            }
        }