Ejemplo 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;
            }

            if (!byte.TryParse(textBox15.Text,out byte station))
            {
                MessageBox.Show( "Station input wrong!" );
                return;
            }

            xGBCnet?.ConnectClose( );
            xGBCnet = new XGBCnetOverTcp( );
            xGBCnet.Station = station;
            xGBCnet.IpAddress = textBox1.Text;
            xGBCnet.Port = port;

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

                    userControlCurve1.ReadWriteNet = xGBCnet;
                }
                else
                {
                    MessageBox.Show( HslCommunication.StringResources.Language.ConnectedFailed );
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show( ex.Message );
            }
        }
Ejemplo n.º 2
0
        public override void DeviceConn(XGBCnetOverTcpConfig config)
        {
            XGBCnetOverTcp xGBCnet = new XGBCnetOverTcp();

            xGBCnet.IpAddress = config.IP;
            xGBCnet.Port      = config.Port;
            xGBCnet.Station   = config.StationNo;
            OperateResult connect = xGBCnet.ConnectServer();

            NetworkDevice = xGBCnet;
            if (!connect.IsSuccess)
            {
                throw new Exception("Connect Failed");
            }
        }