示例#1
0
        private void btnDifTest_Click(object sender, EventArgs e)
        {
            if (!testStarted)//Start test.
            {
                //Indicate test has started.
                btnDifTest.Text = "Abort Test";
                testStarted     = true;

                disableGUI();      //Disable all GUI components.
                resetData();       //Reset all data.
                removeListeners(); //Remove action listeners from the charts.

                //Reset state machine.
                difState = difPulseState.DIF_IDLE;

                //Start test.
                aq.validateDevice(this.btnDifTest);
                difTimer.setTimer(400, timerTypes.TIMER_DIF_TEST, this.btnDifTest);
            }

            else//Abort the current test.
            {
                //Send abort message to device.
                byte[] bArray = new byte[8];
                bArray[0] = (byte)'X';

                try
                {
                    aq.sp.Write(bArray, 0, 1);
                }
                catch (Exception err)
                {
                    aq.comCloser();
                    aq.comErrorHandler(err.ToString());
                }
            }
        }
示例#2
0
        /************************************RX State Machine Functions*************************************/
        public void difTestStateMachine(byte[] bArray, int arraySize)
        {
            UInt16 tempWord;

            //Add incomming data to raw data array.
            for (int i = 0; i < arraySize; i++)
            {
                incommingData.Add(bArray[i]);
            }

            //Update index value.
            totalIndex += arraySize;

            //Populate the word list.
            while (wordBuildingIndex < totalIndex - 1)
            {
                tempWord  = (UInt16)(incommingData[wordBuildingIndex++] << 8);
                tempWord |= (UInt16)(incommingData[wordBuildingIndex++]);
                wordData.Add(tempWord);
            }

            int    gain = aq.aqSettings.tiaGain;
            double gainResistance;

            //compute gain resistance for y-axis current.
            if (gain == 1)
            {
                gainResistance = 100.0;
            }
            else if (gain == 2)
            {
                gainResistance = 1000.0;
            }
            else if (gain == 3)
            {
                gainResistance = 5100.0;
            }
            else if (gain == 4)
            {
                gainResistance = 10000.0;
            }
            else if (gain == 5)
            {
                gainResistance = 51000.0;
            }
            else
            {
                gainResistance = 100000.0;
            }

            while (thisWordIndex < wordData.Count)
            {
                tempWord = wordData[thisWordIndex++];

                switch (difState)
                {
                /*****************************************Idle******************************************/

                case difPulseState.DIF_IDLE:
                    if (tempWord == START_DEP)    //Prepare for deposition.
                    {
                        prepDepChart();
                        difState = difPulseState.DIF_DEP;    //Move to deposition state.
                    }
                    else if (tempWord == START_QUIET)
                    {
                        prepQuietChart();
                        difState = difPulseState.DIF_QUIET;    //Move to quiet time state.
                    }
                    else if (tempWord == START_DIF_PRE)
                    {
                        prepRawChart();
                        prepDifChart();
                        difState = difPulseState.DIF_PRE_COUNT;    //Move to differential pulse state.
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT; //Already handled by above function.
                    }
                    else                                    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                /**************************************Deposition***************************************/

                case difPulseState.DIF_DEP:
                    if (tempWord == END_BLOCK)   //End of deposition.  Move on.
                    {
                        difState = difPulseState.DIF_DEP_END;
                    }
                    else if (tempWord == ABORT)   //Already handled by above function.
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT;
                    }
                    else if (tempWord < ADC_MAX_VALUE)
                    {
                        //Convert data to current and add to list;
                        ds.depAdd(new DataPoint(thisDepTime, (tempWord - 2047) * I_CONSTANT / gainResistance));
                        thisDepTime += depDT;
                    }
                    else    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                case difPulseState.DIF_DEP_END:
                    updateTimer.Enabled = false;

                    if (tempWord == START_QUIET)
                    {
                        prepQuietChart();
                        difState = difPulseState.DIF_QUIET;    //Move to quiet time state.
                    }
                    else if (tempWord == START_DIF_PRE)
                    {
                        prepRawChart();
                        prepDifChart();
                        difState = difPulseState.DIF_PRE_COUNT;    //Move to differential pulse state.
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT; //Already handled by above function.
                    }
                    else                                    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                /*****************************************Quiet*****************************************/

                case difPulseState.DIF_QUIET:
                    if (tempWord == END_BLOCK)    //End of quiet time.  Move on.
                    {
                        difState = difPulseState.DIF_QUIET_END;
                    }
                    else if (tempWord == ABORT)    //Already handled by above function.
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT;
                    }
                    else if (tempWord < ADC_MAX_VALUE)
                    {
                        //Convert data to current and add to list;
                        ds.quietAdd(new DataPoint(thisQuietTime, (tempWord - 2047) * I_CONSTANT / gainResistance));
                        thisQuietTime += quietDT;
                    }
                    else    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                case difPulseState.DIF_QUIET_END:
                    updateTimer.Enabled = false;

                    if (tempWord == START_DIF_PRE)
                    {
                        prepRawChart();
                        prepDifChart();
                        difState = difPulseState.DIF_PRE_COUNT;    //Move to differential pulse state.
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT; //Already handled by above function.
                    }
                    else                                    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                /***************************************Pre-pulse***************************************/

                case difPulseState.DIF_PRE_COUNT:
                    preCount++;
                    preData.Add(new PulseClass());    //Add new element to pre-pulse data list.
                    difState = difPulseState.DIF_PRE;
                    break;

                case difPulseState.DIF_PRE:
                    if (tempWord == END_BLOCK)
                    {
                        difState = difPulseState.DIF_PRE_END;
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT;    //Already handled by above function.
                    }
                    else if (tempWord < ADC_MAX_VALUE)
                    {
                        //Add pre-pulse data to list.
                        preData[preCount - 1].data.Add((tempWord - 2047) * I_CONSTANT / gainResistance);
                        ds.rawAdd(new DataPoint(ds.rawCount(), tempWord));
                    }
                    else    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                case difPulseState.DIF_PRE_END:
                    if (tempWord == START_DIF_PULSE)
                    {
                        difState = difPulseState.DIF_PULSE_COUNT;
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT; //Already handled by above function.
                    }
                    else                                    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                /**************************************Pulse***************************************/

                case difPulseState.DIF_PULSE_COUNT:
                    pulseCount++;
                    pulseData.Add(new PulseClass());    //Add new element to pulse data list.
                    difState = difPulseState.DIF_PULSE;
                    break;

                case difPulseState.DIF_PULSE:
                    if (tempWord == END_BLOCK)
                    {
                        UInt16 sampWindow = aq.aqSettings.difSampWinWidth;

                        //Get lengths of the pre-pulse and pulse segments
                        int preDataLength   = preData[preData.Count - 1].data.Count;
                        int pulseDataLength = pulseData[pulseData.Count - 1].data.Count;

                        double preAverage   = 0;
                        double pulseAverage = 0;

                        int preIndex   = preData.Count - 1;         //This pre-pulse data set.
                        int pulseIndex = pulseData.Count - 1;       //This pulse data set.

                        int thisPreDataPointer   = preData[preIndex].data.Count - 1;
                        int thisPulseDataPointer = pulseData[pulseIndex].data.Count - 1;

                        //Pull the data from the arrays and average it.
                        for (int i = 0; i < aq.aqSettings.difSampWinWidth; i++)
                        {
                            preAverage   += preData[preIndex].data[thisPreDataPointer - i];
                            pulseAverage += pulseData[pulseIndex].data[thisPulseDataPointer - i];
                        }

                        preAverage   /= aq.aqSettings.difSampWinWidth;
                        pulseAverage /= aq.aqSettings.difSampWinWidth;

                        //Find the difference between them.
                        double pulseDifference = pulseAverage - preAverage;

                        //Save the value in the IV curve list.
                        ds.ivAddSub(0, new DataPoint(thisDifVoltage, pulseDifference));
                        thisDifVoltage += difDV;

                        difState = difPulseState.DIF_PULSE_END;
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT;    //Already handled by above function.
                    }
                    else if (tempWord < ADC_MAX_VALUE)
                    {
                        //Add pulse data to list.
                        pulseData[pulseCount - 1].data.Add((tempWord - 2047) * I_CONSTANT / gainResistance);
                        ds.rawAdd(new DataPoint(ds.rawCount(), tempWord));
                    }
                    else    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                case difPulseState.DIF_PULSE_END:
                    if (tempWord == START_DIF_PRE)
                    {
                        difState = difPulseState.DIF_PRE_COUNT;
                    }
                    else if (tempWord == END_TEST)
                    {
                        //Add test type.
                        ds.typeSet("DFP");

                        //Add test name.  Current date and time.  User can change later.
                        ds.nameSet(DateTime.Now.ToString());

                        //Add settings info.
                        ds.settings.arraySet(aq.aqSettings.settingsArray);
                        ds.settings.setByArray(aq.aqSettings.settingsArray);

                        Thread.Sleep(300);    //Give charts time to update.

                        BeginInvoke((MethodInvoker) delegate
                        {
                            //Copy data to top of data tree.
                            aq.dataTree.insertAtIndex(ds, 0);

                            //Set graphing markers in tree view for first data set.
                            aq.dataTree.treeGraphFirstItem();

                            //Causes the graphs to be updated based on the tree view graph markers.
                            aq.dataTree.updateGraphs();

                            enableGUI();    //Give control back to the user.
                            addListeners();
                            resetTestButton();
                            aq.wfHelper.dataLoaded = true;
                        });

                        updateTimer.Enabled = false;
                        difState            = difPulseState.DIF_COMP;
                        aq.rxState          = rxStates.RX_IDLE;
                    }
                    else if (tempWord == ABORT)
                    {
                        doAbort();
                        difState = difPulseState.DIF_ABORT; //Already handled by above function.
                    }
                    else                                    //Error state.
                    {
                        doError();
                        difState = difPulseState.DIF_ERR;    //Already handled above.
                    }
                    break;

                /**************************************End States***************************************/

                case difPulseState.DIF_COMP:
                    difState = difPulseState.DIF_IDLE;    //Shouldn't get here.
                    break;

                case difPulseState.DIF_ABORT:
                    difState = difPulseState.DIF_IDLE;    //Shouldn't get here.
                    break;

                case difPulseState.DIF_ERR:    //Nothing to do.  Already handled.
                default:
                    difState = difPulseState.DIF_IDLE;
                    break;
                }
            }
        }