Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // 连接
            if (!System.Net.IPAddress.TryParse(textBox1.Text, out System.Net.IPAddress address))
            {
                MessageBox.Show("Ip地址输入不正确!");
                return;
            }

            siemensTcpNet.PLCIpAddress = address;

            try
            {
                OperateResult connect = siemensTcpNet.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show("连接成功!");
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                }
                else
                {
                    MessageBox.Show("连接失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private Timer timerReadPLC;                                 // 读取PLC的定时器

        #endregion


        private void Form1_Load(object sender, EventArgs e)
        {
            siemensTcp = new SiemensTcpNet(SiemensPLCS.S1200)
            {
                PLCIpAddress = System.Net.IPAddress.Parse("192.168.1.195")
            };

            // 连接到PLC
            siemensTcp.ConnectServer();

            timerReadPLC          = new Timer();
            timerReadPLC.Interval = 1000;
            timerReadPLC.Tick    += TimerReadPLC_Tick;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            // 连接
            if (!System.Net.IPAddress.TryParse(textBox1.Text, out System.Net.IPAddress address))
            {
                MessageBox.Show("Ip地址输入不正确!");
                return;
            }

            siemensTcpNet.PLCIpAddress   = address;
            siemensTcpNet.ConnectTimeout = 200;//连接超时200毫秒
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                siemensTcpNet.PortRead  = int.Parse(textBox2.Text);
                siemensTcpNet.PortWrite = int.Parse(textBox2.Text);
            }
            try
            {
                OperateResult connect = siemensTcpNet.ConnectServer();
                if (connect.IsSuccess)
                {
                    Isconnect = true;
                    MessageBox.Show("连接成功!");
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                }
                else
                {
                    Isconnect = false;
                    MessageBox.Show("连接失败!");
                }
            }
            catch (Exception ex)
            {
                Isconnect = false;
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
 private void userButton16_Click(object sender, EventArgs e)
 {
     siemensTcpNet.ConnectServer();
 }