Exemplo n.º 1
0
        private void SingleReader_Click(object sender, EventArgs e)
        {
            //AllenBradleyNet allenBradleyNet = new AllenBradleyNet("192.168.1.11");

            //OperateResult connect = allenBradleyNet.ConnectServer();
            //if (connect.IsSuccess)
            //{
            //    MessageBox.Show("连接成功!");
            //}
            //else
            //{
            //    MessageBox.Show("连接失败!" + connect.ToMessageShowString());
            //}

            //var tmp= allenBradleyNet.ReadBool("M1");



            //if (tmp.IsSuccess)
            //{
            //    txtRSMeg_Write($"[{DateTime.Now.ToString("HH:mm:ss")}][{txtRSAddress.Text}]{tmp.Content}\r\n");
            //}
            //else
            //{
            //    txtRSMeg_Write($"[{DateTime.Now.ToString("HH:mm:ss")}][Err]{tmp.Message}\r\n");
            //}

            //return;


            if (btnLink.Text != "已链接")
            {
                MessageBox.Show("PLC尚未联机,请联机!");
                return;
            }

            if (string.IsNullOrEmpty(txtRSAddress.Text.Trim()))
            {
                MessageBox.Show("读取地址不能是空");
                return;
            }



            var btn = sender as Button;

            switch (btn.Text.ToUpper())
            {
            case "R-INT16": SingleReader(MyPLC.ReadInt16(txtRSAddress.Text)); break;

            case "R-INT32": SingleReader(MyPLC.ReadInt32(txtRSAddress.Text)); break;

            case "R-INT64": SingleReader(MyPLC.ReadInt64(txtRSAddress.Text)); break;

            case "R-BOOL": SingleReader(MyPLC.ReadBool(txtRSAddress.Text)); break;

            case "R-FLOAT": SingleReader(MyPLC.ReadFloat(txtRSAddress.Text)); break;

            case "R-DOUBLE": SingleReader(MyPLC.ReadDouble(txtRSAddress.Text)); break;

            case "R-STRING": SingleReader(MyPLC.ReadString(txtRSAddress.Text, ushort.Parse(txtWordLength.Text))); break;
            }
        }