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

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

            return(IsConnected);
        }
示例#2
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;
            }
        }