Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            melsec_net?.ConnectClose( );
            melsec_net              = new MelsecFxSerialOverTcp( );
            melsec_net.IpAddress    = textBox1.Text;
            melsec_net.Port         = port;
            melsec_net.IsNewVersion = checkBox1.Checked;
            try
            {
                OperateResult connect = melsec_net.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlReadWriteOp1.SetReadWriteNet(melsec_net, "D100", true);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public override void DeviceConn(MelsecFxSerialOverTcpConfig config)
        {
            MelsecFxSerialOverTcp melsecFx = new MelsecFxSerialOverTcp();

            melsecFx.IpAddress = config.IP;
            melsecFx.Port      = config.Port;
            OperateResult connect = melsecFx.ConnectServer();

            NetworkDevice = melsecFx;
            if (!connect.IsSuccess)
            {
                throw new Exception("Connect Failed");
            }
        }
Пример #3
0
 protected override bool Connect()
 {
     try
     {
         var res = PLC.ConnectServer();
         if (res.IsSuccess)
         {
             LOG.Info($"Connect to [{Owner.ResourceName}.{SourceName}] success.");
         }
         else
         {
             LOG.Warn($"Connect to [{Owner.ResourceName}.{SourceName}] failed.");
         }
         return(Connected);
     }
     catch (Exception ex)
     {
         LOG.Error($"Connect to [{Owner.ResourceName}.{SourceName}] failed. Message [{ex.Message}]");
         return(false);
     }
 }