void wizardPageAccelTestStep1_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();
            response testResponse = null;

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    Thread.Sleep(10);
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_ACCELEROMETER_TEST);
                    _timeOutTimer.Change(8000, Timeout.Infinite);
                    break;

                case TestParameters.TEST_END:
                    _log.Info("Got test end");

                    CheckAccelerometerResult(e.RawData, TestViewParameters.ACCELEROMETER_X_LONG_EDGE, "accelerometer_X_test1_max", "accelerometer_X_test1_min", _accelerometerStep1XData);
                    CheckAccelerometerResult(e.RawData, TestViewParameters.ACCELEROMETER_Y_LONG_EDGE, "accelerometer_Y_test1_max", "accelerometer_Y_test1_min", _accelerometerStep1YData);
                    CheckAccelerometerResult(e.RawData, TestViewParameters.ACCELEROMETER_Z_LONG_EDGE, "accelerometer_Z_test1_max", "accelerometer_Z_test1_min", _accelerometerStep1ZData);

                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    Thread.Sleep(1000);
                    // Reset this so we can retrigger the run
                    _accelerometerTestStep1Running = false;
                    TimeOutCallback(null);
                    break;

                case TestParameters.TEST_ID_START_ACCELEROMETER_TEST:
                    _accelerometerStep1XData = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7], (char)e.RawData[8], (char)e.RawData[9] });
                    SetTestResponse(_accelerometerStep1XData, TestViewParameters.ACCELEROMETER_X_LONG_EDGE, e.RawData, TestStatus.Unknown);
                    _accelerometerStep1YData = new string(new[] { (char)e.RawData[11], (char)e.RawData[12], (char)e.RawData[13], (char)e.RawData[14], (char)e.RawData[15], (char)e.RawData[16], (char)e.RawData[17], (char)e.RawData[18] });
                    SetTestResponse(_accelerometerStep1YData, TestViewParameters.ACCELEROMETER_Y_LONG_EDGE, e.RawData, TestStatus.Unknown);
                    _accelerometerStep1ZData = new string(new[] { (char)e.RawData[20], (char)e.RawData[21], (char)e.RawData[22], (char)e.RawData[23], (char)e.RawData[24], (char)e.RawData[25], (char)e.RawData[26], (char)e.RawData[27] });
                    SetTestResponse(_accelerometerStep1ZData, TestViewParameters.ACCELEROMETER_Z_LONG_EDGE, e.RawData, TestStatus.Unknown);
                    break;

                default:
                    _log.Info("Unexpected test response");
                    break;
            };
        }
示例#2
0
        static void _byteSTreamHandler_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            if (e.ResponseId == TestParameters.PARSE_ERROR)
            {
                Console.WriteLine("Got a parse error");
            }
            else if (e.ResponseId == TestParameters.TEST_ID_BEGIN_TEST)
            {
                Console.WriteLine("Got begin test command");

            }
            else if (e.ResponseId == TestParameters.TEST_END)
            {
                Console.WriteLine("Got test end response");

            }
            else if (e.ResponseId == TestParameters.TEST_ID_BUTTON_TEST)
            {
                switch (e.RawData[2])
                {
                    case 1:
                        Console.WriteLine("Key 1/6");
                        break;
                    case 2:
                        Console.WriteLine("Key ENT");
                        break;
                    case 4:
                        Console.WriteLine("Key 5/0");
                        break;
                    case 8:
                        Console.WriteLine("Key 4/9");
                        break;
                    case 16:
                        Console.WriteLine("Key 3/8");
                        break;
                    case 32:
                        Console.WriteLine("Key 2/7");
                        break;
                    default:
                        Console.WriteLine("Invalid key code");
                        break;
                }
            }
            else
            {
                Console.WriteLine("Response id is {0}", (int)e.ResponseId);
            }
        }
        void wizardPageProgramPCB_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    Thread.Sleep(10);
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;
                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");
                    Thread.Sleep(100);

                    // Program the unit with the test ID
                    byte[] testNodeId = ASCIIEncoding.ASCII.GetBytes(ConfigurationManager.AppSettings["test_node_id"]);

                    byte[] commandProgramNodeID = TestParameters.REQUEST_SET_NODE_ID;

                    commandProgramNodeID[2] = testNodeId[0];
                    commandProgramNodeID[3] = testNodeId[1];
                    commandProgramNodeID[4] = testNodeId[2];

                    CommunicationManager.Instance.SendCommand(commandProgramNodeID);
                    break;

                case TestParameters.TESTJIG_RUN_CUR:
                    _log.Info("Got run current command");
                    var result = (int)e.RawData[2];
                    // Multiply by conversion factor to get current in mV
                    double current = result * 0.294117647;
                    var currentData = string.Format("{0}", current.ToString("F"));

                    double runCurrentMax = double.Parse(ConfigurationManager.AppSettings["run_current_max"]);
                    double runCurrentMin = double.Parse(ConfigurationManager.AppSettings["run_current_min"]);

                    if(current <= runCurrentMax && current >= runCurrentMin)
                        SetTestResponse(currentData, TestViewParameters.RUN_CURRENT, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(currentData, TestViewParameters.RUN_CURRENT, e.RawData, TestStatus.Fail);

                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_SLEEP);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SLEEP_CUR);
                    break;

                case TestParameters.TESTJIG_SLEEP_CUR:

                    var sleepCurrentResponse = (int)e.RawData[2];

                    double sleepCurrent = sleepCurrentResponse * (129.4 / 1000);

                    var sleepCurrentData = string.Format("{0}", sleepCurrent.ToString("F"));

                    double sleepCurrentMax = double.Parse(ConfigurationManager.AppSettings["sleep_current_max"]);
                    double sleepCurrentMin = double.Parse(ConfigurationManager.AppSettings["sleep_current_min"]);

                    if (sleepCurrent <= sleepCurrentMax && sleepCurrent >= sleepCurrentMin)
                        SetTestResponse(sleepCurrentData, TestViewParameters.SLEEP_CURRENT, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(sleepCurrentData, TestViewParameters.SLEEP_CURRENT, e.RawData, TestStatus.Fail);

                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_SLEEP:

                    var sleepResponse = (int)e.RawData[2];

                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_SET_NODE_ID:

                    // Now request the node id back
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_NODE_ID);

                    break;

                case TestParameters.TEST_ID_NODE_ID:

                    // Value should be the same as what was set initially
                    string nodeId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();

                    int nodeIdForTest = int.Parse(ConfigurationManager.AppSettings["test_node_id"]);
                    int actualNodeId = int.Parse(nodeId);

                    if (nodeIdForTest == actualNodeId)
                        SetTestResponse(nodeId, TestViewParameters.NODE_ID, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(nodeId, TestViewParameters.NODE_ID, e.RawData, TestStatus.Fail);

                    // Now do the same for the hub Id
                    // Program the unit with the test ID
                    byte[] testHubId = ASCIIEncoding.ASCII.GetBytes(ConfigurationManager.AppSettings["test_hub_id"]);

                    byte[] commandProgramHubID = TestParameters.REQUEST_SET_HUB_ID;

                    commandProgramHubID[2] = testHubId[0];
                    commandProgramHubID[3] = testHubId[1];

                    CommunicationManager.Instance.SendCommand(commandProgramHubID);

                    break;

                case TestParameters.TEST_ID_SET_HUB_ID:
                    // Now request the hub id back
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_HUB_ID);
                    break;

                case TestParameters.TEST_ID_HUB_ID:

                    // Value should be the same as what was set initially
                    string hubId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();

                    int hubIdForTest = int.Parse(ConfigurationManager.AppSettings["test_node_id"]);
                    int actualHubId = int.Parse(hubId);

                    if (hubIdForTest == actualHubId)
                        SetTestResponse(hubId, TestViewParameters.HUB_ID, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(hubId, TestViewParameters.HUB_ID, e.RawData, TestStatus.Fail);

                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    Thread.Sleep(300);
                    TimeOutCallback(null);
                    break;

                case TestParameters.TEST_END:
                    _log.Info("Got test end");

                    break;
                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }
        void wizardPageResultsStatus_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();
            byte[] rawData;

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");

                    _extHeaderTestStage = 0;
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_EXT_TEST);
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_DAC1);

                    break;

                case TestParameters.TEST_ID_EXT:
                    _log.Info("ext");
                    if (_extHeaderTestStage == 0)
                    {
                        _extHeaderTestStage = 1;
                        byte[] requestExtSk5Test = TestParameters.REQUEST_EXT_TEST;
                        requestExtSk5Test[2] = 1; // Set the mode to 1
                        CommunicationManager.Instance.SendCommand(requestExtSk5Test);
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_DAC1);
                    }
                    else if (_extHeaderTestStage == 1)
                    {
                        _extHeaderTestStage = 2;
                        byte[] requestExtSkTest = TestParameters.REQUEST_EXT_TEST;
                        requestExtSkTest[2] = 2; // Set the mode to 2
                        CommunicationManager.Instance.SendCommand(requestExtSkTest);
                        Thread.Sleep(10);
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_DAC2);
                    }
                    else if (_extHeaderTestStage == 2)
                    {
                        _extHeaderTestStage = 3;
                        byte[] requestExtSkTest = TestParameters.REQUEST_EXT_TEST;
                        requestExtSkTest[2] = 3; // Set the mode to 3
                        CommunicationManager.Instance.SendCommand(requestExtSkTest);
                        Thread.Sleep(10);
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_DAC2);
                    }
                    else if (_extHeaderTestStage == 3)
                    {
                        _extHeaderTestStage = 4;
                        byte[] requestExtSkTest = TestParameters.REQUEST_EXT_TEST;
                        requestExtSkTest[2] = 4; // Set the mode to 4. This triggers the TEST_ID_RESPONSE_EXT_SK3_ADC
                        CommunicationManager.Instance.SendCommand(requestExtSkTest);
                    }
                    else
                    {
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_VSUPPLY_DUT);
                    }

                    break;

                case TestParameters.TESTJIG_DAC1:
                    _log.Info("dac1");

                    if (_extHeaderTestStage == 0)
                    {
                        var expectedSk5Test1 = int.Parse(ConfigurationManager.AppSettings["ext_sk5_test1"]);
                        int modeZeroResult = e.RawData[2];
                        if (modeZeroResult > (expectedSk5Test1 - 20) && modeZeroResult < (expectedSk5Test1 + 20))
                            SetTestResponse(modeZeroResult.ToString(), TestViewParameters.EXT_SK5_TEST1, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(modeZeroResult.ToString(), TestViewParameters.EXT_SK5_TEST1, e.RawData, TestStatus.Fail);
                    }

                    if (_extHeaderTestStage == 1)
                    {
                        int modeOneResult = e.RawData[2];
                        var expectedSk5Test2 = int.Parse(ConfigurationManager.AppSettings["ext_sk5_test2"]);
                        if (modeOneResult > (expectedSk5Test2 - 20) && modeOneResult < (expectedSk5Test2 + 20))
                            SetTestResponse(modeOneResult.ToString(), TestViewParameters.EXT_SK5_TEST2, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(modeOneResult.ToString(), TestViewParameters.EXT_SK5_TEST2, e.RawData, TestStatus.Fail);
                    }

                    break;

                case TestParameters.TESTJIG_DAC2:
                    _log.Info("dac2");

                    if (_extHeaderTestStage == 2)
                    {
                        int modeTwoResult = e.RawData[2];
                        var expectedSk5Test1 = int.Parse(ConfigurationManager.AppSettings["ext_sk3_test1"]);
                        if (modeTwoResult > (expectedSk5Test1 - 20) && modeTwoResult < (expectedSk5Test1 + 20))
                            SetTestResponse(modeTwoResult.ToString(), TestViewParameters.EXT_SK3_TEST1, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(modeTwoResult.ToString(), TestViewParameters.EXT_SK3_TEST1, e.RawData, TestStatus.Fail);
                    }

                    if (_extHeaderTestStage == 3)
                    {
                        int modeThreeResult = e.RawData[2];
                        var expectedSk5Test2 = int.Parse(ConfigurationManager.AppSettings["ext_sk3_test2"]);
                        if (modeThreeResult > (expectedSk5Test2 - 20) && modeThreeResult < (expectedSk5Test2 + 20))
                            SetTestResponse(modeThreeResult.ToString(), TestViewParameters.EXT_SK3_TEST2, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(modeThreeResult.ToString(), TestViewParameters.EXT_SK3_TEST2, e.RawData, TestStatus.Fail);
                    }

                    break;

                case TestParameters.TEST_ID_RESPONSE_EXT_SK3_ADC:

                    string adcChannel8Data = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5] });
                    int adcChannel8 = Convert.ToInt32(adcChannel8Data, 16);
                    string adcChannel9Data = new string(new[] { (char)e.RawData[6], (char)e.RawData[7], (char)e.RawData[8], (char)e.RawData[9] });
                    int adcChannel9 = Convert.ToInt32(adcChannel9Data, 16);
                    string adcChannel10Data = new string(new[] { (char)e.RawData[10], (char)e.RawData[11], (char)e.RawData[12], (char)e.RawData[13] });
                    int adcChannel10 = Convert.ToInt32(adcChannel10Data, 16);

                    var expectedAdc8 = int.Parse(ConfigurationManager.AppSettings["ext_sk3_adc_channel8"]);
                    var expectedAdc9 = int.Parse(ConfigurationManager.AppSettings["ext_sk3_adc_channel9"]);
                    var expectedAdc10 = int.Parse(ConfigurationManager.AppSettings["ext_sk3_adc_channel10"]);

                    string data = adcChannel8.ToString() + "/" + adcChannel9.ToString() + "/" + adcChannel10.ToString();

                    if (adcChannel8 > (expectedAdc8 - 20) && adcChannel8 < (expectedAdc8 + 20))
                        SetTestResponse(adcChannel8.ToString(), TestViewParameters.EXT_SK3_TEST_ADC8, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(adcChannel8.ToString(), TestViewParameters.EXT_SK3_TEST_ADC9, e.RawData, TestStatus.Fail);

                     if (adcChannel9 > (expectedAdc9 - 20) && adcChannel9 < (expectedAdc9 + 20))
                         SetTestResponse(adcChannel9.ToString(), TestViewParameters.EXT_SK3_TEST_ADC9, e.RawData, TestStatus.Pass);
                    else
                         SetTestResponse(adcChannel9.ToString(), TestViewParameters.EXT_SK3_TEST_ADC9, e.RawData, TestStatus.Fail);

                    if (adcChannel10 > (expectedAdc10 - 20) && adcChannel10 < (expectedAdc10 + 20))
                        SetTestResponse(adcChannel10.ToString(), TestViewParameters.EXT_SK3_TEST_ADC10, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(adcChannel10.ToString(), TestViewParameters.EXT_SK3_TEST_ADC10, e.RawData, TestStatus.Fail);

                    break;

                case TestParameters.TESTJIG_VSUPPLY_DUT:

                    var result = (int)e.RawData[2];
                    _testJigVoltage = result * 0.02588;
                    var voltageSupplyData = string.Format("{0}", _testJigVoltage.ToString("F"));
                    SetTestResponse(voltageSupplyData, TestViewParameters.VOLTAGE_SUPPLY, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BATTERY_LEVEL);
                    break;

                case TestParameters.TEST_ID_BATTERY_LEVEL:

                    string batLevelData = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7], (char)e.RawData[8] });
                    int batLevel10mV = int.Parse(batLevelData);

                    double batteryLevel = batLevel10mV / 10.0;

                    double voltageDiffernce = double.Parse(ConfigurationManager.AppSettings["voltage_difference"]);

                    if (batteryLevel < (_testJigVoltage + voltageDiffernce) && batteryLevel > (_testJigVoltage - voltageDiffernce))
                        SetTestResponse(string.Format("{0:0.00}", batteryLevel), TestViewParameters.BATTERY_VOLTAGE, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(string.Format("{0:0.00}", batteryLevel), TestViewParameters.BATTERY_VOLTAGE, e.RawData, TestStatus.Fail);

                    _log.Info("Got battery level result");
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_TEMPERATURE_LEVEL);
                    break;

                case TestParameters.TEST_ID_TEMPERATURE_LEVEL:
                    rawData = e.RawData.Skip(2).Take(4).ToArray();
                    string temperatureData = new string(new[] { (char)rawData[2], (char)rawData[3] });
                    int temperature = Convert.ToInt32(temperatureData, 16);

                    _log.Info("Got temperature level");

                    double temperatureMax = double.Parse(ConfigurationManager.AppSettings["temperature_max"]);
                    double temperatureMin = double.Parse(ConfigurationManager.AppSettings["temperature_min"]);

                    if (temperature >= temperatureMin && temperature <= temperatureMax)
                        SetTestResponse(string.Format("{0:0.0}", temperature), TestViewParameters.TEMPERATURE_READING, e.RawData, TestStatus.Pass);
                    else
                        SetTestResponse(string.Format("{0:0.0}", temperature), TestViewParameters.TEMPERATURE_READING, e.RawData, TestStatus.Pass);

                    AllowResultsPageToMoveNext();
                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    TimeOutCallback(null);
                    break;

                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }
        void wizardPagePiezo_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();
            response testResponse = null;

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    Thread.Sleep(10);
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_PIEZO_TEST);
                    //Task.Run(() =>
                    //{
                    //    int count = 0;
                    //    while (count < 10)
                    //    {
                            // Send the command to the test jig to activate the piezo...
                            CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SET_PIEZO);
                           // count++;
                            //Thread.Sleep(300);
                    //    }
                    //});
                    break;
                case TestParameters.TEST_END:
                    _log.Info("Got test end");

                    if (!_gotPiezoTestResult && _piezoTestRetries < 3)
                    {
                        _piezoTestRetries++;
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_PIEZO_TEST);
                        // Send the command to the test jig to activate the piezo...
                        Thread.Sleep(100);
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SET_PIEZO);
                    }
                    else if (!_gotReedTestResult && _reedTestRetries < 3)
                    {
                        _reedTestRetries++;
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_REED_SWITCH_TEST);
                        // Send the command to the test jig to pull the reed switch low
                        Thread.Sleep(100);
                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SET_REED);
                    }
                    else
                    {
                        RequestSetRTC();
                    }
                    break;

                case TestParameters.TEST_ID_START_PIEZO_TEST:

                    _gotPiezoTestResult = true;
                    SetTestResponse("PASS", TestViewParameters.PIEZO_TEST, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_REED_SWITCH_TEST);
                    // Send the command to the test jig to pull the reed switch low
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SET_REED);
                    break;

                case TestParameters.TEST_ID_REED_SWITCH_TEST:

                    // Next test...
                    SetTestResponse("PASS", TestViewParameters.REED_TEST, e.RawData, TestStatus.Pass);
                    RequestSetRTC();
                    break;

                case TestParameters.TEST_ID_SET_RTC_VALUE:

                    _rtcDateTimeString =_rtcDateTime.ToString("dd/MM/yy HH:mm:ss");
                    SetTestResponse(_rtcDateTimeString, TestViewParameters.RTC_SET, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_RTC_VALUE);
                    break;

                case TestParameters.TEST_ID_RTC_VALUE:
                    var temperatureResponseValue = new string(new []{(char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4],
                                                             (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7],
                                                             (char)e.RawData[8], (char)e.RawData[9], (char)e.RawData[10],
                                                             (char)e.RawData[11], (char)e.RawData[12], (char)e.RawData[13],
                                                             (char)e.RawData[14], (char)e.RawData[15], (char)e.RawData[16],
                                                             (char)e.RawData[17], (char)e.RawData[18]});

                    var temperatureResponse = TestStatus.Unknown;

                    if(_rtcDateTimeString.CompareTo(temperatureResponseValue) == 0)
                        temperatureResponse = TestStatus.Pass;
                    else
                        temperatureResponse = TestStatus.Fail;

                    SetTestResponse(temperatureResponseValue, TestViewParameters.RTC_GET, e.RawData, temperatureResponse);
                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    Thread.Sleep(2000);
                    TimeOutCallback(null);
                    break;
                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }
        void wizardPageKeyPress_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            if (e.ResponseId == TestParameters.PARSE_ERROR)
            {
                _log.Info("Got a parse error");

                CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
            }
            else if (e.ResponseId == TestParameters.TEST_ID_BEGIN_TEST)
            {
                _log.Info("Got begin test command");
                Console.WriteLine("Sending keypress test command");

                byte[] commandBytes = TestParameters.REQUEST_START_BUTTON_TEST;
                commandBytes[2] = 10; // Give 15 seconds to complete the test
                commandBytes[3] = (byte)KEY_5_0; // The final key in the sequence that indicates the test should stop
                CommunicationManager.Instance.SendCommand(commandBytes);
                Thread.Sleep(100);
                CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BUTTON_PRESS_SEQ);
            }
            //else if (e.ResponseId == TestParameters.TEST_ID_BUTTONS_INITIALISED)
            //{
            // Send the command to the test jig to begin testing
            //    Thread.Sleep(100);
            //    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BUTTON_PRESS_SEQ);
            //}
            else if (e.ResponseId == TestParameters.TEST_END)
            {
                _log.Info("Detected end of test");

                if (_activeKey == KEY_END_TEST)
                {
                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    _flashColourTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    Thread.Sleep(2000);
                    CheckFinalKeyResponse(TestViewParameters.KEY_1_6);
                    CheckFinalKeyResponse(TestViewParameters.KEY_2_7);
                    CheckFinalKeyResponse(TestViewParameters.KEY_3_8);
                    CheckFinalKeyResponse(TestViewParameters.KEY_4_9);
                    CheckFinalKeyResponse(TestViewParameters.KEY_5_0);
                    CheckFinalKeyResponse(TestViewParameters.KEY_ENT);

                    this.BeginInvoke(new MethodInvoker(delegate
                    {
                        wizardPageKeyPress.AllowNext = true;
                        wizardPageKeyPress.AllowBack = true;

                        if (gotKEY_1_6 && gotKEY_2_7 && gotKEY_3_8 && gotKEY_4_9 && gotKEY_5_0 && gotKEY_ENT)
                            stepWizardControl1.NextPage();
                    }));

                }
            }
            else if (e.ResponseId == TestParameters.TEST_ID_BUTTON_TEST)
            {
                var currentKey = _activeKey;

                Console.WriteLine("Pressed key was {0}", e.RawData[2]);

                switch (e.RawData[2])
                {
                    case KEY_1_6:
                        if (!gotKEY_1_6)
                        {
                            gotKEY_1_6 = true;
                            _log.Info("Key 1/6");

                            RecordKeyResponse(TestViewParameters.KEY_1_6, e.RawData);
                            _activeKey = KEY_2_7;
                        }
                        break;
                    case KEY_ENT:
                        if (!gotKEY_ENT)
                        {
                            gotKEY_ENT = true;
                            _log.Info("Key ENT");

                            RecordKeyResponse(TestViewParameters.KEY_ENT, e.RawData);
                            _activeKey = KEY_1_6;
                        }
                        break;
                    case KEY_5_0:
                        if (!gotKEY_5_0)
                        {
                            gotKEY_5_0 = true;
                            _log.Info("Key 5/0");
                            RecordKeyResponse(TestViewParameters.KEY_5_0, e.RawData);
                            _activeKey = KEY_END_TEST;
                        }
                        break;
                    case KEY_4_9:
                        if (!gotKEY_4_9)
                        {
                            gotKEY_4_9 = true;
                            _log.Info("Key 4/9");
                            RecordKeyResponse(TestViewParameters.KEY_4_9, e.RawData);
                            _activeKey = KEY_5_0;
                        }
                        break;
                    case KEY_3_8:
                        if (!gotKEY_3_8)
                        {
                            gotKEY_3_8 = true;
                            _log.Info("Key 3/8");
                            RecordKeyResponse(TestViewParameters.KEY_3_8, e.RawData);
                            _activeKey = KEY_4_9;
                        }
                        break;
                    case KEY_2_7:
                        if (!gotKEY_2_7)
                        {
                            gotKEY_2_7 = true;
                            _log.Info("Key 2/7");
                            RecordKeyResponse(TestViewParameters.KEY_2_7, e.RawData);
                            _activeKey = KEY_3_8;
                        }
                        break;
                    default:
                        _log.Info("Invalid key code");
                        break;
                }
                SetKeyColour(Color.YellowGreen, currentKey);

            }
            else
            {
                _log.InfoFormat("Response id is {0}", (int)e.ResponseId);
            }
        }
        void wizardPageTransceiver_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();
            byte[] rawData;
            response testResponse = null;

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_GET_BGRSSI_VALUE);
                    break;

                case TestParameters.TEST_ID_GET_BGRSSI_VALUE:

                    if (_rssiStage == 0)
                    {
                        string initialRssi = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7], (char)e.RawData[8] }).Trim();

                        int bkgrRssi = int.Parse(initialRssi.Trim());

                        int bkgrRssiMax = int.Parse(ConfigurationManager.AppSettings["rssi_bkgr_max"]);
                        int bkgrRssiMin = int.Parse(ConfigurationManager.AppSettings["rssi_bkgr_min"]);

                        if(bkgrRssi >= bkgrRssiMax && bkgrRssi <= bkgrRssiMin)
                            SetTestResponse(initialRssi, TestViewParameters.RF_BGR_RSSI, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(initialRssi, TestViewParameters.RF_BGR_RSSI, e.RawData, TestStatus.Fail);

                        CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_CAPTURE_HUB);
                    }
                    else
                    {
                        string ackRssiData = new string(new[] { (char)e.RawData[9], (char)e.RawData[10], (char)e.RawData[11], (char)e.RawData[12], (char)e.RawData[13], (char)e.RawData[14], (char)e.RawData[15] }).Trim();

                        var ackRssi = int.Parse(ackRssiData.Trim());

                        int ackRssiMax = int.Parse(ConfigurationManager.AppSettings["rssi_ack_max"]);
                        int ackRssiMin = int.Parse(ConfigurationManager.AppSettings["rssi_ack_min"]);

                        if (ackRssi >= ackRssiMax && ackRssi <= ackRssiMin)
                            SetTestResponse(ackRssiData, TestViewParameters.RF_ACK_RSSI, e.RawData, TestStatus.Pass);
                        else
                            SetTestResponse(ackRssiData, TestViewParameters.RF_ACK_RSSI, e.RawData, TestStatus.Fail);

                    }
                    break;

                case TestParameters.TEST_ID_CAPTURE_HUB:

                    _rssiStage = 1;

                    string hubAck = new string(new[]
                    {
                        (char)e.RawData[2],(char)e.RawData[3],(char)e.RawData[4],(char)e.RawData[5],(char)e.RawData[6],
                        (char)e.RawData[7],(char)e.RawData[8],(char)e.RawData[9],(char)e.RawData[10],(char)e.RawData[11],
                        (char)e.RawData[12],(char)e.RawData[13],(char)e.RawData[14],(char)e.RawData[15],(char)e.RawData[16],
                        (char)e.RawData[17],(char)e.RawData[18],(char)e.RawData[19],(char)e.RawData[20],(char)e.RawData[21],
                        (char)e.RawData[22],(char)e.RawData[23]
                    }).Trim();

                    SetTestResponse(hubAck, TestViewParameters.RF_HUB_ACK, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_GET_BGRSSI_VALUE);
                    break;

                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }
        void wizardPageProgramForRelease_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_NODE_ID);
                    break;

                case TestParameters.TEST_ID_NODE_ID:
                    _nodeId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();
                    SetTestResponse(_nodeId, TestViewParameters.RELEASE_NODE_ID, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_HUB_ID);
                    break;

                case TestParameters.TEST_ID_HUB_ID:
                    string hubId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();
                    SetTestResponse(hubId, TestViewParameters.RELEASE_HUB_ID, e.RawData, TestStatus.Pass);
                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);

                    // The process is complete - mark the test
                    ProcessControl.Instance.MarkCurrentRunComplete();

                    TimeOutCallback(false);
                    break;

                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }
        void wizardPageLEDTest_ProcessResponseEventHandler(object sender, ByteStreamHandler.ProcessResponseEventArgs e)
        {
            var testRun = ProcessControl.Instance.GetCurrentTestRun();
            byte[] rawData;

            switch (e.ResponseId)
            {
                case TestParameters.PARSE_ERROR:
                    _log.Info("Got a parse error");
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_BEGIN_TEST);
                    break;

                case TestParameters.TEST_ID_BEGIN_TEST:
                    _log.Info("Got begin test command");

                    string firmwareVersion = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7], (char)e.RawData[8], (char)e.RawData[9], (char)e.RawData[10], (char)e.RawData[11], (char)e.RawData[12], (char)e.RawData[13], (char)e.RawData[14], (char)e.RawData[15], (char)e.RawData[16]}).Trim();
                    firmwareVersion = firmwareVersion.Replace("\0", "");

                    SetTestResponse(firmwareVersion, TestViewParameters.FIRMWARE_VERSION, e.RawData, TestStatus.Pass);

                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_NODE_ID);
                    break;

                case TestParameters.TEST_ID_NODE_ID:
                    string nodeId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();
                    SetTestResponse(nodeId, TestViewParameters.NODE_ID, e.RawData, TestStatus.Pass);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_HUB_ID);
                    break;

                case TestParameters.TEST_ID_HUB_ID:
                    string hubId = new string(new[] { (char)e.RawData[2], (char)e.RawData[3], (char)e.RawData[4], (char)e.RawData[5], (char)e.RawData[6], (char)e.RawData[7] }).Trim();
                    SetTestResponse(hubId, TestViewParameters.HUB_ID, e.RawData, TestStatus.Pass);

                    _altColour = false;
                    _activeLEDBtn = 0;
                    _flashLedBtnTimer.Change(0, 500);

                    _detectedGreenLED = false;
                    _requestingGreenLED = true;
                    _requestingRedLED = false;

                    // Need to do this or the LEDs dont work ???? Ask RS about the test jig
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SHUTDOWN_DUT);
                    //Thread.Sleep(200);
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_PWR_DUT);
                    //Thread.Sleep(2000);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_FLASH_GREEN_LED);
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_LED_STATUS);
                    break;

                case TestParameters.TESTJIG_LED_STATUS:

                    _log.Info("Got LED status");

                    int ledGreenStatus = e.RawData[2];
                    int ledRedStatus = e.RawData[3];

                    if (_requestingGreenLED)
                    {
                        _detectedGreenLED = ledGreenStatus == 0;
                    }

                    if (_requestingRedLED)
                    {
                        _detectedRedLED = ledRedStatus == 0;
                    }

                    break;

                case TestParameters.TEST_ID_START_FLASH_GREEN_LED:
                    _flashLedBtnTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    _altColour = true;
                    FlashLEDBtnCallback(null);

                    if (_detectedGreenLED)
                    {
                        pictureBoxLED1.Image = ESLTestProcess.Properties.Resources.tick;
                        SetTestResponse("PASS", TestViewParameters.LED_GREEN_FLASH, e.RawData, TestStatus.Pass);
                    }
                    else
                    {
                        pictureBoxLED1.Image = ESLTestProcess.Properties.Resources.cross;
                        SetTestResponse("FAIL", TestViewParameters.LED_GREEN_FLASH, e.RawData, TestStatus.Fail);
                    }

                    _altColour = false;
                    _activeLEDBtn = 1;
                    _flashLedBtnTimer.Change(0, 500);

                    _detectedRedLED = false;
                    _requestingGreenLED = false;
                    _requestingRedLED = true;

                    // Need to do this or the LEDs dont work ???? Ask RS about the test jig
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_SHUTDOWN_DUT);
                    //Thread.Sleep(200);
                    //CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_PWR_DUT);
                    //Thread.Sleep(2000);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_START_FLASH_RED_LED);
                    Thread.Sleep(100);
                    CommunicationManager.Instance.SendCommand(TestParameters.REQUEST_LED_STATUS);
                    break;

                case TestParameters.TEST_ID_START_FLASH_RED_LED:
                    _flashLedBtnTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    _altColour = true;
                    FlashLEDBtnCallback(null);
                    pictureBoxLED2.Image = ESLTestProcess.Properties.Resources.tick;

                    _flashLedBtnTimer.Change(Timeout.Infinite, Timeout.Infinite);

                    if (_detectedRedLED)
                    {
                        pictureBoxLED2.Image = ESLTestProcess.Properties.Resources.tick;
                        SetTestResponse("PASS", TestViewParameters.LED_RED_FLASH, e.RawData, TestStatus.Pass);
                    }
                    else
                    {
                        pictureBoxLED2.Image = ESLTestProcess.Properties.Resources.cross;
                        SetTestResponse("FAIL", TestViewParameters.LED_RED_FLASH, e.RawData, TestStatus.Fail);
                    }

                    AllowResultsPageToMoveNext();
                    _timeOutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    TimeOutCallback(null);
                    break;

                default:
                    _log.Info("Unexpected test response");
                    break;
            }
        }