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(DemoUtils.IpAddressInputWrong);
                return;
            }

            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            siemensFWNet.IpAddress = textBox1.Text;
            siemensFWNet.Port      = port;

            try
            {
                OperateResult connect = siemensFWNet.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;

                    userControlCurve1.ReadWriteNet = siemensFWNet;
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
 public override void DeviceConn(SiemensFetchWriteConfig config)
 {
     siemensFWNet = new SiemensFetchWriteNet();
     if (!System.Net.IPAddress.TryParse(config.IP, out System.Net.IPAddress address))
     {
         throw new Exception("IpAddress input wrong");
     }
     siemensFWNet.IpAddress = config.IP;
     siemensFWNet.Port      = config.Port;
     try
     {
         OperateResult connect = siemensFWNet.ConnectServer();
         if (!connect.IsSuccess)
         {
             throw new Exception("Connect Failed");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        public void ClassTest2( )
        {
            #region Usage2

            // 实例化对象,指定PLC的ip地址和端口号
            SiemensFetchWriteNet siemens = new SiemensFetchWriteNet(" 192.168.1.110", 2000);

            // 连接对象
            OperateResult connect = siemens.ConnectServer( );
            if (!connect.IsSuccess)
            {
                Console.WriteLine("connect failed:" + connect.Message);
                return;
            }

            // 举例读取M100的值
            short D100 = siemens.ReadInt16("M100").Content;

            siemens.ConnectClose( );

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

            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show("端口输入不正确!");
                return;
            }

            siemensFWNet.IpAddress = textBox1.Text;
            siemensFWNet.Port      = port;

            try
            {
                OperateResult connect = siemensFWNet.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);
            }
        }