/*
Using the TestResultsReader.dll:

- Add a reference to the DLL so that it is loaded.
- In the class file add a 'using TestResultsReader' declaration.

- Declare a new test results loader.
TestResults tr = new TestResults();

- Use the loader to open a result (.RES) file and its corresponding CAD file (don't forget to unload it when you are done).
LegacyResultsFile loadedResultsFile = (LegacyResultsFile)tr.load("C:\\5DX\\RES\\MYRES.RES");

if(resFile.IsOpen) will check if the RES file opened successfully.

if(resFile.IsRptCadFileOpen) will check if the CAD file opened successfully.

To get the joint defect results:

    ArrayList jointResults = resFile.JointResults;

    foreach(Object ojr in jointResults)
    {
        JointResults jtRes = (JointResults)ojr;

        if(jtRes.Defective)
        {
            foreach(Object om in jtRes.Measurements)
            {
                Measurement jntMeas = (Measurement)om;
		        string info = jtRes.ComponentResults.Name + "," + 
                            jtRes.JointName + "," + 
                            jtRes.Subtype.ToString() + "," + 
                            jntMeas.SliceNumber + "," +
                            String.Format("{0:0.00}", jntMeas.Value) + "," + 
                            jntMeas.MeasurementUnit + "\n", jntMeas.Value);
            }
        }
    }

- Unload the result file and corresponding cad file.
tr.unload(resFile);

You are done.

 
If you need to pull a specific characteristic and measurement.

ArrayList jointResults = resFile.JointResults;
String selectFamily = "FPGullwing";
String selectCharacteristic = "Open";
String selectMeasurement = "Open Signal Diag";
short iSliceNumber = 0xFF; // 255 is all slices
short iSubtype = 0xFF; // 255 is all subtypes
Hashtable listPts = new Hashtable(5);
double i = 0.0;
double sum = 0.0;
double initializer = 100000;
double lowestPass = initializer;
double highestPass = -initializer;
double lowestFail = initializer;
double highestFail = -initializer;

// PointPairList is a class for containing the data collected.
foreach(Object ojr in jointResults)
{
    JointResults jtRes = (JointResults)ojr;

    if(jtRes.Defective || bGraphAllResults)
    {
        if(iSubtype == 0xFF || (jtRes.Subtype == iSubtype))
        {
            foreach(Object om in jtRes.Measurements)
            {
                Measurement jntMeas = (Measurement)om;

                if(selectFamily != jntMeas.FamilyName)
                    break;

                if(jntMeas.CharacteristicName.ToUpper() == selectCharacteristic.ToUpper() && jntMeas.MeasurementName.ToUpper() == selectMeasurement.ToUpper())
                {
                    if(iSliceNumber == 0xFF || (jntMeas.SliceNumber == iSliceNumber))
                    {
                        string dataLabel = String.Format("{0:0.00}", jntMeas.Value) + ", " + jtRes.ComponentResults.Name + " pin " + jtRes.JointName + ", " +
                            "Slice " + jntMeas.SliceNumber.ToString() + ", " + 
                            (jntMeas.Defective ? "Measurement Failed" : "Measurement Passed");

                        double z = (jtRes.Defective ? 0.0 : 1.0); // Show where the defective joints are.

                        if(listPts.ContainsKey(jntMeas.SliceNumber))
                        {
                            ((PointPairList)listPts[jntMeas.SliceNumber]).Add(i++, (double)jntMeas.Value, z, dataLabel);
                        }
                        else
                        {
                            PointPairList pp = new PointPairList();
                            pp.Add(i++, (double)jntMeas.Value, z, dataLabel);
                            listPts.Add(jntMeas.SliceNumber, pp);
                        }

                        if(!bMeasUnitSet)
                        {
                            bMeasUnitSet = true;
                            selectUnits = jntMeas.MeasurementUnit;
                        }

                        // Find the passing range.
                        if(!jtRes.Defective) //jntMeas.Defective) // This is a defective measurement but not a defective joint.
                        {
                            if(jntMeas.Value < lowestPass)
                                lowestPass = jntMeas.Value;

                            if(jntMeas.Value > highestPass)
                                highestPass = jntMeas.Value;
                        }
                        else
                        {
                            // Find the failing range.
                            if(jntMeas.Value < lowestFail)
                                lowestFail = jntMeas.Value;

                            if(jntMeas.Value > highestFail)
                                highestFail = jntMeas.Value;
                        }

                        sum += (double)jntMeas.Value;

                        //if(iSliceNumber != 0xFF)
                            //break; // Stop after only 1 slice: bad idea since short fails can have more than one value per pin.
                    }
                }
            }
        }
    }
}
*/