Пример #1
0
        public void Connection()
        {
            try
            {
                fastEnet.IpAddress = IP;
                fastEnet.Port      = Port;
                fastEnet.SlotNo    = 3;

                try
                {
                    OperateResult connect = fastEnet.ConnectServer();
                    if (connect.IsSuccess)
                    {
                        IsConnected = true;
                    }
                }
                catch (Exception ex)
                {
                    EventscadaException?.Invoke(this.GetType().Name, ex.Message);
                }
            }
            catch (SocketException ex)
            {
                IsConnected = false;
                EventscadaException?.Invoke(this.GetType().Name, ex.Message);
            }
        }
Пример #2
0
        public bool Connection()
        {
            if (!System.Net.IPAddress.TryParse(IP, out System.Net.IPAddress address))
            {
                EventscadaException?.Invoke(GetType().Name, DemoUtils.IpAddressInputWrong);
                return(false);
            }

            if (!int.TryParse($"{Port}", out int port))
            {
                EventscadaException?.Invoke(GetType().Name, DemoUtils.PortInputWrong);
                return(false);
            }

            if (!byte.TryParse($"{slotNo}", out byte slot))
            {
                EventscadaException?.Invoke(GetType().Name, DemoUtils.SlotInputWrong);
                return(false);
            }

            fastEnet = new XGBFastEnet();
            try
            {
                fastEnet.IpAddress  = IP;
                fastEnet.Port       = Port;
                fastEnet.SlotNo     = slotNo;
                fastEnet.SetCpuType = CpuType;
                try
                {
                    OperateResult connect = fastEnet.ConnectServer();
                    if (connect.IsSuccess)
                    {
                        EventscadaException?.Invoke(GetType().Name, StringResources.Language.ConnectedSuccess);
                        IsConnected = true;
                    }
                    else
                    {
                        EventscadaException?.Invoke(GetType().Name, StringResources.Language.ConnectedFailed);
                    }
                    return(IsConnected);
                }
                catch (Exception ex)
                {
                    EventscadaException?.Invoke(GetType().Name, ex.Message);
                    return(IsConnected);
                }
            }
            catch (SocketException ex)
            {
                IsConnected = false;
                EventscadaException?.Invoke(GetType().Name, ex.Message);
                return(IsConnected);
            }
        }
Пример #3
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(textBox12.Text, out byte slot))
            {
                MessageBox.Show(DemoUtils.SlotInputWrong);
                return;
            }

            fastEnet.IpAddress  = textBox1.Text;
            fastEnet.Port       = port;
            fastEnet.SlotNo     = slot;
            fastEnet.SetCpuType = cboxModel.Text;
            fastEnet.CompanyID  = cboxCompanyID.Text;

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

                    userControlReadWriteOp1.SetReadWriteNet(fastEnet, "MB100", true);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        public override void DeviceConn(XGBFastEnetConfig config)
        {
            XGBFastEnet fastEnet = new XGBFastEnet();

            fastEnet.IpAddress  = config.IP;
            fastEnet.Port       = config.Port;
            fastEnet.SlotNo     = config.SlotNo;
            fastEnet.SetCpuType = config.CpuType;
            fastEnet.CompanyID  = config.CompanyID;
            OperateResult connect = fastEnet.ConnectServer();

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