/// <summary> /// compare calibrations /// </summary> /// <param name="testCal">calibration to compare</param> /// <returns>true if testCal has different value than this</returns> public bool Different(Calibration testCal) { // must differ if test doesn't exist if (testCal == null) { return(true); } // get two binarys and compare, ignore CRC and .Note differences byte[] testBinary = testCal.ConvertToBinary(); byte[] thisBinary = this.ConvertToBinary(); bool differ = false; for (int i = 0; i < thisBinary.Length - 2; i++) { if (testBinary[i] != thisBinary[i]) { differ = true; } } return(differ); }
public static Calibration Read(string fileName) { XmlSerializer sr = new XmlSerializer(typeof(Calibration)); FileStream fs = null; try { fs = File.OpenRead(fileName); Calibration cal = (Calibration)sr.Deserialize(fs); cal.ReCalculateCRC(); // spreadsheet does not produce CRC, so always recalc return(cal); } catch (Exception) { throw new ApplicationException("Calibration file read error " + fileName); } finally { if (fs != null) { fs.Close(); } } }
//-------------------------------------------------------------------- public Assay ReCalcResults() { Calibration newCal = this.cal.Clone() as Calibration; // no need to recal LC3 results, since they were done on PC in first place if (Source == Analyzer.LeadCare3) { return((Assay)this.Clone()); } // create new assay, set calibration,zero result Assay recalc = (Assay)this.Clone(); recalc.cal = newCal.Clone() as Calibration; recalc.Result = 0; recalc.SWCValue = 0; // only recalc if we have raw data if (recalc.ForwardADC == null || recalc.ReverseADC == null || recalc.StepCount == 0) { return(recalc); } // intermediate data tables for filtering short[] avgForwardTable = new short[recalc.StepCount]; short[] avgReverseTable = new short[recalc.StepCount]; short[] rawDiffTable = new short[recalc.StepCount]; // first fill with raw ADC reads for (int step = 0; step < recalc.StepCount; step++) { if (Source == Analyzer.LeadCare3) { avgForwardTable[step] = ConvertLc3AdcReading(ForwardADC[step]); avgReverseTable[step] = ConvertLc3AdcReading(ReverseADC[step]); } else { avgForwardTable[step] = ForwardADC[step]; avgReverseTable[step] = ReverseADC[step]; } } TestAgainstCurrentLimit(recalc, avgForwardTable, avgReverseTable); // apply boxcar filter to averaged reads to get final forward & reverse tables Filter(recalc.ForwardTable, avgForwardTable, BoxcarFilter); Filter(recalc.ReverseTable, avgReverseTable, BoxcarFilter); // get difference table with ADC overflow flagging and then filter with FFT GetDifferenceCurve(recalc, rawDiffTable); Filter(recalc.DifferenceTable, rawDiffTable, FFTfilter); // fill raw corrected table and apply baseline correction for (int i = 0; i < recalc.StepCount; i++) { recalc.CorrectedTable[i] = recalc.DifferenceTable[i]; } recalc.BCiterations = 0; for (int i = 0; i < 3; i++) { if (BaselineCorrection(recalc)) { ++recalc.BCiterations; } } // integrate to get square wave capacitance recalc.SWCValue = 0; for (int i = recalc.LowerMinimum; i <= recalc.UpperMinimum; i++) { if (recalc.CorrectedTable[i] > 0) { recalc.SWCValue += (uint)recalc.CorrectedTable[i]; } } // final correction and conversion TemperatureCorrection(recalc); TranslateBLL(recalc); if (recalc.Error == 0) { recalc.Result = recalc.BLLCorrected; } // debug test for calculation bool recalcOK = true; try { for (int step = 0; step < recalc.StepCount; step++) { if (recalc.ForwardTable[step] != this.ForwardTable[step]) { recalcOK = false; } if (recalc.ReverseTable[step] != this.ReverseTable[step]) { recalcOK = false; } if (recalc.DifferenceTable[step] != this.DifferenceTable[step]) { recalcOK = false; } if (recalc.CorrectedTable[step] != this.CorrectedTable[step]) { recalcOK = false; } } if (recalc.SWCValue != this.SWCValue) { recalcOK = false; } if (recalc.TempCorrected != this.TempCorrected) { recalcOK = false; } if (recalc.SWCscaled != this.SWCscaled) { recalcOK = false; } if (recalc.BLLCorrected != this.BLLCorrected) { recalcOK = false; } } catch (Exception) { recalcOK = false; } if (recalcOK) { } return(recalc); }