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


            try
            {
                cipServer = new HslCommunication.Profinet.AllenBradley.AllenBradleyServer( );                                       // 实例化对象
                cipServer.ActiveTimeSpan  = TimeSpan.FromHours(1);
                cipServer.OnDataReceived += BusTcpServer_OnDataReceived;

                cipServer.ServerStart(port);
                cipServer.AddTagValue("A", (short)10);
                cipServer.AddTagValue("A1", (short)1000);
                cipServer.AddTagValue("B", 123);
                cipServer.AddTagValue("C", 123f);
                cipServer.AddTagValue("D", new short[] { 1, 2, 3, 4, 5 });
                cipServer.AddTagValue("E", true);
                cipServer.AddTagValue("F", "12345", 100);
                cipServer.AddTagValue("G", new string[5] {
                    "123", "123456", string.Empty, "abcd", "测试"
                }, 100);
                cipServer.AddTagValue("AB.C", new short[] { 1, 2, 3, 4, 5 });
                cipServer.AddTagValue("M", new uint[] { 12345678, 34567, 567890, 1234567 });

                button1.Enabled  = false;
                panel2.Enabled   = true;
                button11.Enabled = true;
                userControlReadWriteServer1.SetReadWriteServer(cipServer, "A", 1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }


            try
            {
                cipServer = new HslCommunication.Profinet.AllenBradley.AllenBradleyServer( );                       // 实例化对象
                cipServer.OnDataReceived += BusTcpServer_OnDataReceived;

                cipServer.ServerStart(port);
                cipServer.AddTagValue("A", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[2],
                    IsArray    = false,
                    TypeLength = 2
                });
                cipServer.AddTagValue("A1", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[2],
                    IsArray    = false,
                    TypeLength = 2
                });
                cipServer.AddTagValue("B", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[4],
                    IsArray    = false,
                    TypeLength = 4
                });
                cipServer.AddTagValue("C", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[4],
                    IsArray    = false,
                    TypeLength = 4
                });
                cipServer.AddTagValue("D", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[10],
                    IsArray    = true,
                    TypeLength = 2
                });
                cipServer.AddTagValue("E", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[2],
                    IsArray    = false,
                    TypeLength = 2
                });
                cipServer.AddTagValue("F", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[100],
                    IsArray    = false,
                    TypeLength = 1
                });
                cipServer.AddTagValue("G", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[500],
                    IsArray    = true,
                    TypeLength = 100
                });
                cipServer.AddTagValue("AB.C", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[10],
                    IsArray    = true,
                    TypeLength = 2
                });

                button1.Enabled  = false;
                panel2.Enabled   = true;
                button11.Enabled = true;
                userControlReadWriteServer1.SetReadWriteServer(cipServer, "A", 1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }


            try
            {
                cipServer = new HslCommunication.Profinet.AllenBradley.AllenBradleyServer( );                       // 实例化对象
                //s7NetServer.LogNet = new HslCommunication.LogNet.LogNetSingle( "logs.txt" );                  // 配置日志信息
                //s7NetServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile;
                cipServer.OnDataReceived += BusTcpServer_OnDataReceived;

                cipServer.ServerStart(port);
                cipServer.AddTagValue("A", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[2],
                    IsArray    = false,
                    TypeLength = 2
                });
                cipServer.AddTagValue("A1", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[2],
                    IsArray    = false,
                    TypeLength = 2
                });
                cipServer.AddTagValue("B", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[4],
                    IsArray    = false,
                    TypeLength = 4
                });
                cipServer.AddTagValue("C", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[4],
                    IsArray    = false,
                    TypeLength = 4
                });
                cipServer.AddTagValue("D", new HslCommunication.Profinet.AllenBradley.AllenBradleyItemValue( )
                {
                    Buffer     = new byte[10],
                    IsArray    = true,
                    TypeLength = 2
                });

                button1.Enabled  = false;
                panel2.Enabled   = true;
                button4.Enabled  = true;
                button11.Enabled = true;

                timerSecond?.Dispose( );
                timerSecond          = new System.Windows.Forms.Timer( );
                timerSecond.Interval = 1000;
                timerSecond.Tick    += TimerSecond_Tick;
                timerSecond.Start( );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }