Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            omronCipNet?.ConnectClose( );
            omronCipNet = new OmronConnectedCipNet(textBox1.Text, port);

            omronCipNet.SetPersistentConnection( );

            try
            {
                OperateResult connect = omronCipNet.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlReadWriteOp1.SetReadWriteNet(omronCipNet, "A1", true, 1);
                }
                else
                {
                    MessageBox.Show(StringResources.Language.ConnectedFailed + connect.ToMessageShowString( ));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
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;
            }

            if (!byte.TryParse(textBox15.Text, out byte slot))
            {
                MessageBox.Show(DemoUtils.SlotInputWrong);
                return;
            }

            omronCipNet.IpAddress = textBox1.Text;
            omronCipNet.Port      = port;
            omronCipNet.Slot      = slot;

            try
            {
                OperateResult connect = omronCipNet.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlReadWriteOp1.SetReadWriteNet(omronCipNet, "A1", true);
                }
                else
                {
                    MessageBox.Show(StringResources.Language.ConnectedFailed + connect.ToMessageShowString( ));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }