public override void DeviceConn(OmronHostLinkOverTcpConfig config)
        {
            OmronHostLinkOverTcp omronHost = new OmronHostLinkOverTcp();

            omronHost.IpAddress  = config.IP;
            omronHost.Port       = config.Port;
            omronHost.UnitNumber = config.StationNo;
            omronHost.SID        = config.SID;
            omronHost.DA2        = config.DA2;
            omronHost.SA2        = config.SA2;
            omronHost.ByteTransform.DataFormat = (HslCommunication.Core.DataFormat)config.ByteTransformDataFormat;
            OperateResult connect = omronHost.ConnectServer();

            NetworkDevice = omronHost;
            if (!connect.IsSuccess)
            {
                throw new Exception("Connect Failed");
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox19.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

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

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


            if (!byte.TryParse(textBox16.Text, out byte DA2))
            {
                MessageBox.Show("PLC DA2 input wrong!");
                return;
            }

            if (!byte.TryParse(textBox17.Text, out byte SA2))
            {
                MessageBox.Show("PC SA2 input wrong");
                return;
            }

            omronHostLink?.ConnectClose( );
            omronHostLink           = new OmronHostLinkOverTcp( );
            omronHostLink.IpAddress = textBox20.Text;
            omronHostLink.Port      = port;

            try
            {
                omronHostLink.UnitNumber = Station;
                omronHostLink.SID        = SID;
                omronHostLink.DA2        = DA2;
                omronHostLink.SA2        = SA2;
                omronHostLink.ByteTransform.DataFormat = (HslCommunication.Core.DataFormat)comboBox1.SelectedItem;

                OperateResult connect = omronHostLink.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);

                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;

                    userControlReadWriteOp1.SetReadWriteNet(omronHostLink, "D100", false);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
 public FormOmronHostLinkOverTcp( )
 {
     InitializeComponent( );
     omronHostLink = new OmronHostLinkOverTcp( );
     // omronHostLink.LogNet = new HslCommunication.LogNet.LogNetSingle( "omron.log.txt" );
 }