Beispiel #1
0
 public void LoadConfig <T>(ConfigFile <T> config) where T : new()
 {
     try {
         XmlSerializer serializer = new XmlSerializer(typeof(T));
         using (FileStream reader = new FileStream(config.FileXml, FileMode.Open)) {
             config.Data = (T)serializer.Deserialize(reader);
             reader.Close();
         }
     } catch (Exception ex) {
         m_log.TraceError("Using default " + config.Name + " because of failed to load, reason: " + ex.Message);
         config.Data = new T();
         throw new ApplicationException(config.Name + ": loading error");
     }
 }
Beispiel #2
0
 public bool InitOBDDll()
 {
     if (!m_obd.ConnectOBD())
     {
         m_log.TraceError("SH_OBD_Main.ConnectOBD() failed");
         return(false);
     }
     if (!m_obd.SetSupportStatus())
     {
         m_log.TraceError("SH_OBD_Main.SetSupportStatus() failed");
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        private void SetStatistics()
        {
            int[] iQtys = new int[2];
            try {
                iQtys = GetQty();
            } catch (ApplicationException ex) {
                MessageBox.Show(ex.Message, "GetQty() ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } catch (Exception ex) {
                m_log.TraceError(ex.Message);
                MessageBox.Show(ex.Message, "GetQty() ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.lblQTY.Text = iQtys[0].ToString();
            int iToatlPage = iQtys[0] / QtyPerPage + (iQtys[0] % QtyPerPage > 0 ? 1 : 0);

            this.lblTotalPage.Text = "共" + iToatlPage.ToString() + "页";
            this.numUDPage.Maximum = iToatlPage;
            this.numUDPage.Minimum = iToatlPage == 0 ? 0 : 1;
            this.numUDPage.Value   = this.numUDPage.Minimum;
            this.lblRate.Text      = (iQtys[0] != 0 ? (iQtys[1] * 100.0 / iQtys[0]).ToString("F2") : "0") + "%";
        }
Beispiel #4
0
 public bool TCPClientInit(bool bLog = true)
 {
     try {
         m_client       = new TcpClient(m_cfg.Setting.Data.TCPServerIP, m_cfg.Setting.Data.TCPServerPort);
         m_clientStream = m_client.GetStream();
         if (bLog || !m_bLastTestStatus)
         {
             m_log.TraceInfo("TcpClient init success");
         }
         m_bInited = true;
     } catch (Exception ex) {
         if (m_clientStream != null)
         {
             m_clientStream.Close();
         }
         if (m_client != null)
         {
             m_client.Close();
         }
         if (bLog || m_bLastTestStatus)
         {
             m_log.TraceError("TcpClient init error: " + ex.Message);
         }
         m_bInited = false;
     }
     m_bLastTestStatus = m_bInited;
     return(m_bInited);
 }
Beispiel #5
0
 public Main()
 {
     InitializeComponent();
     m_bTesting      = false;
     m_lastHeight    = this.Height;
     m_serialRecvBuf = "";
     m_bLastStatus   = false;
     m_bBlink        = false;
     m_lockObj       = new object();
     m_counterFailed = 0;
     m_bLoop         = false;
     m_OBDInited     = false;
     m_inFinishing   = 0;
     this.Text       = Properties.Resources.MainTitle + " Ver: " + MainFileVersion.AssemblyVersion;
     m_log           = new BaseLib.Logger(".\\log\\Temper", BaseLib.EnumLogLevel.LogLevelAll, true, 100);
     m_log.TraceInfo("==================================================================");
     m_log.TraceInfo("===================== START Ver: " + MainFileVersion.AssemblyVersion + " =====================");
     m_cfg = new Config(m_log);
     try {
         m_cfg.LoadConfigAll();
     } catch (ApplicationException ex) {
         MessageBox.Show(ex.Message.Split(':')[0] + "配置文件读取出错,将会使用默认配置", "初始化错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     m_db     = new BaseLib.Model("TemperSensor", m_cfg, m_log);
     m_tester = new Temper(m_log, m_cfg, m_db);
     m_tester.TCPClientInit();
     if (!m_tester.GetInitStatus())
     {
         MessageBox.Show("无法连接WiFi串口服务器", "初始化错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     if (m_cfg.Setting.Data.ScannerPort.Length > 0)
     {
         m_sp = new BaseLib.SerialPortClass(
             m_cfg.Setting.Data.ScannerPort,
             m_cfg.Setting.Data.ScannerBaud,
             Parity.None,
             8,
             StopBits.One
             );
         try {
             m_sp.OpenPort();
             m_sp.DataReceived += new BaseLib.SerialPortClass.SerialPortDataReceiveEventArgs(SerialDataReceived);
         } catch (Exception ex) {
             m_log.TraceError("Open serial port error: " + ex.Message);
             MessageBox.Show("打开串口扫码枪出错", "初始化错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     m_obdDll                  = new OBDDll(m_log);
     m_timerInterval           = new System.Timers.Timer(m_cfg.Setting.Data.Interval);
     m_timerInterval.Elapsed  += new System.Timers.ElapsedEventHandler(OnTimeInterval);
     m_timerInterval.AutoReset = true;
     m_timerInterval.Enabled   = false;
     m_timerTick               = new System.Timers.Timer(m_cfg.Setting.Data.Interval); // 心跳间隔同采样间隔一致
     m_timerTick.Elapsed      += new System.Timers.ElapsedEventHandler(OnTimeTick);
     m_timerTick.AutoReset     = true;
     m_timerTick.Enabled       = true;
     m_timerBlink              = new System.Timers.Timer(m_cfg.Setting.Data.Interval); // 闪烁间隔同采样间隔一致
     m_timerBlink.Elapsed     += new System.Timers.ElapsedEventHandler(OnTimeBlink);
     m_timerBlink.AutoReset    = true;
     m_timerBlink.Enabled      = true;
 }
Beispiel #6
0
        private void FinishTest()
        {
            m_timerInterval.Enabled = false;
            m_timerTick.Enabled     = true;
            bool   bResult      = false;
            double dAverage1    = 0;
            double dAverage2    = 0;
            double dCount1      = 0;
            double dCount2      = 0;
            double dLastTemper1 = 0;
            double dLastTemper2 = 0;

            if (!m_bLoop)
            {
                switch (m_cfg.Setting.Data.Rule)
                {
                case 0:
                    bResult = m_tester.GetResult0(m_dSetup, out dLastTemper1, out dLastTemper2);
                    m_log.TraceInfo(string.Format("Get the test result: {0}, last: {1}℃/{2}℃", bResult, dLastTemper1.ToString("F2"), dLastTemper2.ToString("F2")));
                    break;

                case 1:
                    bResult = m_tester.GetResult1(m_dSetup, out dAverage1, out dAverage2);
                    m_log.TraceInfo(string.Format("Get the test result: {0}, average: {1}℃/{2}℃", bResult, dAverage1.ToString("F2"), dAverage2.ToString("F2")));
                    break;

                case 2:
                    bResult = m_tester.GetResult2(m_dSetup, out dCount1, out dCount2);
                    if (m_cfg.Setting.Data.SuccessiveValue > 1)
                    {
                        m_log.TraceInfo(string.Format("Get the test result: {0}, count: {1}/{2}", bResult, dCount1.ToString("F0"), dCount2.ToString("F0")));
                    }
                    else
                    {
                        m_log.TraceInfo(string.Format("Get the test result: {0}, percentage: {1}%/{2}%", bResult, dCount1.ToString("F2"), dCount2.ToString("F2")));
                    }
                    break;
                }
            }
            string strTimeStamp = m_tester.GetTimeStamp();

            try {
                m_tester.ExportResultFile(bResult, strTimeStamp);
                m_bBlink = !bResult;
            } catch (Exception ex) {
                m_log.TraceError("ExportResultFile() ERROR: " + ex.Message);
                if (!m_bLoop)
                {
                    MessageBox.Show(ex.Message, "ExportResultFile() ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (!m_bLoop)
            {
                try {
                    m_tester.WriteDB(bResult, strTimeStamp);
                } catch (ApplicationException ex) {
                    MessageBox.Show(ex.Message, "WriteDB() ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } catch (Exception ex) {
                    m_log.TraceError("WriteDB() ERROR: " + ex.Message);
                    MessageBox.Show(ex.Message, "WriteDB() ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (bResult)
                {
                    m_counterFailed = 0;
                }
                else
                {
                    ++m_counterFailed;
                }
                this.Invoke((EventHandler) delegate {
                    if (bResult)
                    {
                        this.lblInfo.ForeColor = Color.Green;
                        this.lblInfo.Text      = "合格";
                    }
                    else
                    {
                        this.lblInfo.ForeColor = Color.Red;
                        this.lblInfo.Text      = "不合格";
                    }
                    switch (m_cfg.Setting.Data.Rule)
                    {
                    case 0:
                        this.lblInfo.Text += ", 当前温度: ";
                        switch (m_cfg.Setting.Data.Temper)
                        {
                        case 0:
                            this.lblInfo.Text += dLastTemper1.ToString("F2") + "℃/" + dLastTemper2.ToString("F2") + "℃";
                            break;

                        case 1:
                            this.lblInfo.Text += dLastTemper1.ToString("F2") + "℃";
                            break;

                        case 2:
                            this.lblInfo.Text += dLastTemper2.ToString("F2") + "℃";
                            break;
                        }
                        break;

                    case 1:
                        this.lblInfo.Text += ", 平均温度: ";
                        switch (m_cfg.Setting.Data.Temper)
                        {
                        case 0:
                            this.lblInfo.Text += dAverage1.ToString("F2") + "℃/" + dAverage2.ToString("F2") + "℃";
                            break;

                        case 1:
                            this.lblInfo.Text += dAverage1.ToString("F2") + "℃";
                            break;

                        case 2:
                            this.lblInfo.Text += dAverage2.ToString("F2") + "℃";
                            break;
                        }
                        break;

                    case 2:
                        this.lblInfo.Text += ", 连续合格温度点";
                        if (m_cfg.Setting.Data.SuccessiveValue > 1)
                        {
                            this.lblInfo.Text += "(" + m_cfg.Setting.Data.SuccessiveValue.ToString("F0") + ")";
                            switch (m_cfg.Setting.Data.Temper)
                            {
                            case 0:
                                this.lblInfo.Text += "个数: " + dCount1.ToString("F0") + "个/" + dCount2.ToString("F0") + "个";
                                break;

                            case 1:
                                this.lblInfo.Text += dCount1.ToString("F0") + "个";
                                break;

                            case 2:
                                this.lblInfo.Text += dCount2.ToString("F0") + "个";
                                break;
                            }
                        }
                        else
                        {
                            this.lblInfo.Text += "(" + (m_cfg.Setting.Data.SuccessiveValue * 100).ToString("F2") + "%)";
                            switch (m_cfg.Setting.Data.Temper)
                            {
                            case 0:
                                this.lblInfo.Text += "占比: " + (dCount1 * 100).ToString("F2") + "%/" + (dCount2 * 100).ToString("F2") + "%";
                                break;

                            case 1:
                                this.lblInfo.Text += (dCount1 * 100).ToString("F2") + "%";
                                break;

                            case 2:
                                this.lblInfo.Text += (dCount2 * 100).ToString("F2") + "%";
                                break;
                            }
                        }
                        break;
                    }
                    if (m_counterFailed >= m_cfg.Setting.Data.TestFailedQty)
                    {
                        m_log.TraceWarning(string.Format("There are {0} NG vehicles", m_counterFailed));
                        this.lblInfo.Text     += ", 已连续" + m_counterFailed.ToString() + "辆车不合格";
                        this.lblInfo.BackColor = Color.Red;
                        this.lblInfo.ForeColor = Color.White;
                    }
                    m_strInfo = this.lblInfo.Text;
                });
            }
            else
            {
                StopLoop(false);
                Task.Factory.StartNew(StartTest);
            }
            m_bTesting = false;
        }