Exemple #1
0
        private bool CalculateAndWriteCoeff()
        {
            try
            {
                bool result = true;

                //减offset
                double[,] matrixX = new double[matrixEachEnADC.GetLength(0), matrixEachEnADC.GetLength(1)];
                for (int i = 0; i < matrixEachEnADC.GetLength(0); i++)
                {
                    string info = "";
                    for (int j = 0; j < matrixEachEnADC.GetLength(1); j++)
                    {
                        info         += matrixEachEnADC[i, j].ToString("f1") + "   ";
                        matrixX[i, j] = matrixEachEnADC[i, j] - matrixOffsetADC[i];
                    }
                    //log matrixSingleEnable and offset
                    Log.SaveLogToTxt("matrixSingleEnable: " + info + "matrixOffset: " + matrixOffsetADC[i]);
                }

                //计算系数
                double[,] coeff = Algorithm.CalculateCoeff(matrixX, 0);

                //log and write coeff to DUT
                result = dut.WriterTxAdcCalibrateMatrix(coeff);
                for (int i = 0; i < coeff.GetLength(0); i++)
                {
                    string info = "";
                    for (int j = 0; j < coeff.GetLength(1); j++)
                    {
                        info += coeff[i, j].ToString("f4") + "   ";
                    }
                    Log.SaveLogToTxt("coeff: " + info);
                }
                Log.SaveLogToTxt("Write coeff to dut sucessfully");

                //write offset to DUT;
                for (int i = 0; i < matrixOffsetADC.GetLength(0); i++)
                {
                    dut.ChangeChannel((i + 1).ToString());
                    result = result && dut.WriterTxAdcBacklightOffset(matrixOffsetADC[i]);
                }
                Log.SaveLogToTxt("Write offset to dut sucessfully");

                return(result);
            }
            catch (InnoExCeption ex)//from driver
            {
                //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace);
                exceptionList.Add(ex);
                return(false);
            }
            catch (Exception error)//from itself
            {
                //one way: deal this exception itself
                InnoExCeption ex = new InnoExCeption(ExceptionDictionary.Code._0x02100, error.StackTrace);
                //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace);
                exceptionList.Add(ex);
                return(false);
                //the other way is: should throw exception, rather than the above three code. see below:
                //throw new InnoExCeption(ExceptionDictionary.Code._0x02100, error.StackTrace);
            }
            finally
            {
                dut.ChangeChannel(GlobalParameters.CurrentChannel.ToString());
            }
        }