예제 #1
0
        /// <summary>
        /// 批量读取PLC位软元件指定地址的Bool数据
        /// </summary>
        /// <param name="startAddr"></param>
        /// <param name="uSize"></param>
        /// <param name="sData"></param>
        /// <returns></returns>
        public bool ReadBool(string startAddr, ushort uSize, ref bool[] sData)
        {
            if (uSize == 0)
            {
                return(false);
            }
            OperateResult <bool[]> read = m_plc.ReadBool(startAddr, uSize);

            IsConnected = read.IsSuccess;
            if (IsConnected)
            {
                sData = read.Content;
            }

            return(IsConnected);
        }
예제 #2
0
파일: Form1.cs 프로젝트: nm-1216/PLCServer
        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;
            }
        }