Пример #1
0
        public static void WriteMsg(MessageType degree, object obj, string strMsg, string strMark = "", Exception ex = null)
        {
            string strKey = (obj != null ? obj.GetType().FullName : "") + (string.IsNullOrEmpty(strMark) ? "" : "  Mark:" + strMark);

            switch (degree)
            {
            case MessageType.DEBUG:
                logNet.WriteDebug(strKey, strMsg);
                break;

            case MessageType.ERROR:
                logNet.WriteError(strKey, strMsg);
                break;

            case MessageType.FATAL:
                logNet.WriteFatal(strKey, strMsg);
                break;

            case MessageType.INFO:
                logNet.WriteInfo(strKey, strMsg);
                break;

            case MessageType.NONE:
                logNet.WriteDescrition(strMsg);
                break;

            case MessageType.WARN:
                logNet.WriteWarn(strKey, strMsg);
                break;

            case MessageType.EXCEPTION:
                logNet.WriteException(strKey, ex);
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// 界面显示消息,msgType为类别,Info,Alarm
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msgType"></param>
        public void DispProcess(string data, string msgType)
        {
            string tempData = data;

            try
            {
                if (eventDispProcess != null)
                {
                    if (msgType == "Info")
                    {
                        tempData = "[消息]" + DateTime.Now.ToString() + "  " + data + "\n";
                        eventDispProcess(tempData, Color.Black);
                    }
                    else if (msgType == "Alarm")
                    {
                        tempData = "[错误]" + DateTime.Now.ToString() + "  " + data + "\n";
                        eventDispProcess(tempData, Color.Red);
                    }
                    tempData = DateTime.Now.ToString() + "  " + data;
                    logNet.WriteInfo(data);
                }
            }
            catch (Exception ex)
            {
                logNet.WriteWarn(ex.Message + "DispProcess函数处");
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        ILogNet logNetTime = new LogNetDateTime(Application.ResourceAssembly + "\\LogByTime", GenerateMode.ByEveryDay);//按每天
        private void TestButton_Click(object sender, RoutedEventArgs e)
        {
            // 一般日志写入
            logNet.WriteDebug("调试信息");
            logNet.WriteInfo("一般信息");
            logNet.WriteWarn("警告信息");
            logNet.WriteError("错误信息");
            logNet.WriteFatal("致命信息");
            logNet.WriteException(null, new IndexOutOfRangeException());

            // 带有关键字的写入,关键字建议为方法名或是类名,方便分析的时候归类搜索
            logNet.WriteDebug("userButton1_Click", "调试信息");
            logNet.WriteInfo("TestForm", "一般信息");
            logNet.WriteWarn("随便什么", "警告信息");
            logNet.WriteError("userButton1_Click", "错误信息");
            logNet.WriteFatal("userButton1_Click", "致命信息");
            logNet.WriteException("userButton1_Click", new IndexOutOfRangeException());

            // 日志查看器
            using (HslCommunication.LogNet.FormLogNetView form = new HslCommunication.LogNet.FormLogNetView())
            {
                form.ShowDialog();
            }
        }
Пример #4
0
        public static bool Read1()
        {
            bool flag = false;

            try
            {
                #region 写AO1,AO2 这一段要删掉
                if (TestViewModel.Working1)
                {
                    Distance = (short)(Distance + 2);
                    if (Pressure < 650 && !IsMax)
                    {
                        Random random = new Random();
                        Pressure = (short)(Pressure + random.Next(3));
                    }
                    else
                    {
                        Random random = new Random();
                        IsMax    = true;
                        Pressure = (short)(Pressure - random.Next(2, 8));
                    }
                    byte[] buffer = new byte[4];
                    ModbusTcpNet1.ByteTransform.TransByte(Distance).CopyTo(buffer, 0);  //
                    ModbusTcpNet1.ByteTransform.TransByte(Pressure).CopyTo(buffer, 2);
                    OperateResult write = ModbusTcpNet1.Write(addresswrite, buffer);    //要删掉
                    if (write.IsSuccess)
                    {
                        OperateResult <byte[]> result = ModbusTcpNet1.Read(address, ushort.Parse("2"));
                        if (result.IsSuccess)
                        {
                            Global.ConnectStatus1 = true;
                            Global.Point1.x       = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 0);
                            Global.Point1.y       = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 2);
                            flag = true;
                        }
                    }
                    else
                    {
                        // failed
                    }
                }
                #endregion
                //OperateResult<byte[]> result = ModbusTcpNet1.Read(address, ushort.Parse("2"));
                //if (result.IsSuccess)
                //{
                //    Global.ConnectStatus1 = true;
                //    Global.Point1.x = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 0);
                //    Global.Point1.y = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 2);
                //    flag= true;
                //}
            }
            catch
            {
                //设置读写标志为false
                Global.ConnectStatus1 = false;
            }
            Global.ConnectStatus1 = flag;
            if (!Global.ConnectStatus1)
            {
                logNet.WriteWarn("#1压机通讯故障");
                ModbusTcpNet1.ConnectServer();
            }
            Thread.Sleep(2);
            return(flag);
        }
Пример #5
0
        private static void ThreadBackgroundRead1()
        {
            string address = "x=4;72";

            //string addresswrite = "96";//要删掉

            while (true)
            {
                if (!Global.ConnectStatus1)
                {
                    logNet.WriteWarn("#1压机通讯故障");
                    ModbusTcpNet1.ConnectServer();
                }
                try
                {
                    #region 写AO1,AO2 这一段要删掉
                    //if (Global.Working1)
                    //{
                    //    Distance = (short)(Distance + 2);
                    //    if (Pressure < 650 && !IsMax)
                    //    {
                    //        Random random = new Random();
                    //        Pressure = (short)(Pressure +random.Next(3));
                    //    }
                    //    else
                    //    {
                    //        Random random = new Random();
                    //        IsMax = true;
                    //        Pressure = (short)(Pressure -random.Next(2,8));
                    //    }
                    //    byte[] buffer = new byte[4];
                    //    ModbusTcpNet1.ByteTransform.TransByte(Distance).CopyTo(buffer, 0);//
                    //    ModbusTcpNet1.ByteTransform.TransByte(Pressure).CopyTo(buffer, 2);
                    //    OperateResult write = ModbusTcpNet1.Write(addresswrite, buffer);//要删掉
                    //    if (write.IsSuccess)
                    //    {
                    //        OperateResult<byte[]> result = ModbusTcpNet1.Read(address, ushort.Parse("2"));
                    //        if (result.IsSuccess)
                    //        {
                    //            Global.ConnectStatus1 = true;
                    //            Global.Point1.x = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 0);
                    //            Global.Point1.y = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 2);
                    //            Point point = new Point();
                    //            point.x = Global.Point1.x;
                    //            point.y = (short)(Global.Point1.y - 1000);
                    //            CommonMethods.DateTreating1(point);
                    //        }
                    //        else Global.ConnectStatus1 = false;
                    //    }
                    //    else
                    //    {
                    //        // failed
                    //    }
                    //}
                    #endregion
                    OperateResult <byte[]> result = ModbusTcpNet1.Read(address, ushort.Parse("2"));
                    if (result.IsSuccess)
                    {
                        Global.ConnectStatus1 = true;
                        Global.Point1.x       = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 0);
                        Global.Point1.y       = ModbusTcpNet1.ByteTransform.TransInt16(result.Content, 2);
                        Point point = new Point();
                        point.x = Global.Point1.x;
                        point.y = (short)(Global.Point1.y - 1000);
                        CommonMethods.DateTreating1(point);
                    }
                    else
                    {
                        Global.ConnectStatus1 = false;  //这段后面要恢复
                    }
                }
                catch
                {
                    //设置读写标志为false
                    Global.ConnectStatus1 = false;
                }
                Thread.Sleep(5);
            }
        }
Пример #6
0
 public static void WriteWarmLog(string info)
 {
     LogNet.WriteWarn(info);
 }