예제 #1
0
        public bool GetInfo(bool checkPingSuccess, PlcCompany plcCompany, bool isRead, string address, int value, out int output, out string msg)
        {
            output = -1;
            msg    = string.Empty;

            try
            {
                if (plcCompany == PlcCompany.Mitsubishi)
                {
                    if (checkPingSuccess)
                    {
                        if (!IsPingSuccess)
                        {
                            IsAlive = false;
                            msg     = "无法连接到 " + IP;
                            return(false);
                        }
                    }

                    if (isRead)//读
                    {
                        OperateResult <int> result = melsec_net.ReadIntFromPLC(address);
                        if (result.IsSuccess)
                        {
                            output  = result.Content;
                            IsAlive = true;
                            return(true);
                        }
                        else
                        {
                            msg     = string.Format("从{0}中读取数据出现错误,代码:{1}", address, result.ErrorCode);
                            IsAlive = false;
                            return(false);
                        }
                    }
                    else//写
                    {
                        OperateResult result = melsec_net.WriteIntoPLC(address, value);
                        if (result.IsSuccess)
                        {
                            IsAlive = true;
                            return(true);
                        }
                        else
                        {
                            msg     = string.Format("{0} 中写入 {1} 出现错误,代码:{2}", address, value, result.ErrorCode);
                            IsAlive = false;
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }

            IsAlive = false;
            return(false);
        }
예제 #2
0
        private void userButton22_Click(object sender, EventArgs e)
        {
            bool   M100         = melsec_net.ReadBoolFromPLC("M100").Content;        // 读取M100是否通,十进制地址
            bool   X1A0         = melsec_net.ReadBoolFromPLC("X1A0").Content;        // 读取X1A0是否通,十六进制地址
            bool   Y1A0         = melsec_net.ReadBoolFromPLC("Y1A0").Content;        // 读取Y1A0是否通,十六进制地址
            bool   B1A0         = melsec_net.ReadBoolFromPLC("B1A0").Content;        // 读取B1A0是否通,十六进制地址
            short  short_D1000  = melsec_net.ReadShortFromPLC("D1000").Content;      // 读取D1000的short值  ,W3C0,R3C0 效果是一样的
            ushort ushort_D1000 = melsec_net.ReadUShortFromPLC("D1000").Content;     // 读取D1000的ushort值
            int    int_D1000    = melsec_net.ReadIntFromPLC("D1000").Content;        // 读取D1000-D1001组成的int数据
            uint   uint_D1000   = melsec_net.ReadUIntFromPLC("D1000").Content;       // 读取D1000-D1001组成的uint数据
            float  float_D1000  = melsec_net.ReadFloatFromPLC("D1000").Content;      // 读取D1000-D1001组成的float数据
            long   long_D1000   = melsec_net.ReadLongFromPLC("D1000").Content;       // 读取D1000-D1003组成的long数据
            double double_D1000 = melsec_net.ReadDoubleFromPLC("D1000").Content;     // 读取D1000-D1003组成的double数据
            string str_D1000    = melsec_net.ReadStringFromPLC("D1000", 10).Content; // 读取D1000-D1009组成的条码数据



            melsec_net.WriteIntoPLC("M100", true);                        // 写入M100为通
            melsec_net.WriteIntoPLC("Y1A0", true);                        // 写入Y1A0为通
            melsec_net.WriteIntoPLC("X1A0", true);                        // 写入X1A0为通
            melsec_net.WriteIntoPLC("B1A0", true);                        // 写入B1A0为通
            melsec_net.WriteIntoPLC("D1000", (short)1234);                // 写入D1000  short值  ,W3C0,R3C0 效果是一样的
            melsec_net.WriteIntoPLC("D1000", (ushort)45678);              // 写入D1000  ushort值
            melsec_net.WriteIntoPLC("D1000", 1234566);                    // 写入D1000  int值
            melsec_net.WriteIntoPLC("D1000", (uint)1234566);              // 写入D1000  uint值
            melsec_net.WriteIntoPLC("D1000", 123.456f);                   // 写入D1000  float值
            melsec_net.WriteIntoPLC("D1000", 123.456d);                   // 写入D1000  double值
            melsec_net.WriteIntoPLC("D1000", 123456661235123534L);        // 写入D1000  long值
            melsec_net.WriteAsciiStringIntoPLC("D1000", "K123456789");    // 写入D1000  string值
        }
예제 #3
0
 private void button_read_int_Click(object sender, EventArgs e)
 {
     // 读取int变量
     readResultRender(melsec_net.ReadIntFromPLC(textBox3.Text), textBox3.Text, textBox4);
 }