private void btnSweepTest_Click(object sender, EventArgs e) { if (!testStarted)//Start test. { //Indicate test has started. btnSweepTest.Text = "Abort Test"; testStarted = true; disableGUI(); //Disable all GUI components. resetData(); //Reset all data. removeListeners(); //Remove action listeners from the charts. //Reset state machine. sweepState = swpState.SWP_IDLE; //Start test. aq.validateDevice(this.btnSweepTest); sweepTimer.setTimer(400, timerTypes.TIMER_SWP_TEST, this.btnSweepTest); } 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()); } } }
private void tbxSendData_KeyDown(object sender, KeyEventArgs e) { string temp; if (e.KeyCode == Keys.Enter) { temp = tbxSendData.Text.ToUpper(); //Send ascii data. if (rbtAscii.Checked) { //Check for special single character cases. if (temp.Length == 1 && (temp[0] == 'A' || temp[0] == 'D' || temp[0] == 'L')) { //Clear console window for clean data. rtbConsoleWindow.Text = ""; } else if (temp.Length == 1 && (temp[0] == 'T' || temp[0] == 'X')) { //Do nothing. } else if (temp.Length == 0) { //Clear window when main menu is presented. rtbConsoleWindow.Text = ""; temp += "\r"; } else { temp += "\r"; } byte[] txArray = new byte[temp.Length]; for (int i = 0; i < temp.Length; i++) { txArray[i] = (byte)temp[i]; } try//Send data to device. { aq.sp.Write(txArray, 0, txArray.Length); } catch (Exception err) { aq.comCloser(); aq.comErrorHandler(err.ToString()); } } //Send binary data. else { //Prepend 0 if even number of characters entered. if (temp.Length % 2 > 0) { temp = "0" + temp; } byte[] bArray = new byte[temp.Length / 2]; byte bTemp1, bTemp2; //Convert text string into byte array. for (int i = 0; i < temp.Length; i += 2) { bTemp1 = (byte)temp[i]; bTemp1 -= 0x30; if (bTemp1 > 9) { bTemp1 -= 0x07; } bTemp1 <<= 4; bTemp2 = (byte)temp[i + 1]; bTemp2 -= 0x30; if (bTemp2 > 9) { bTemp2 -= 0x07; } bTemp1 |= bTemp2; bArray[i / 2] = bTemp1; } consoleUpdater(bArray.Length, bArray, consoleSources.CONSOLE_MANUAL, this.tbxSendData); try//Send data to device. { aq.sp.Write(bArray, 0, bArray.Length); } catch (Exception err) { aq.comCloser(); aq.comErrorHandler(err.ToString()); } } aq.control = tbxSendData; tbxSendData.Clear(); //Stop annoying chime sound after every enter key press. e.Handled = true; e.SuppressKeyPress = true; } }
//Perform tasks when timer expires. private void OnTimedEvent(object source, EventArgs e) { tStatus = timerStatus.TSTATUS_EXPIRED; aqTimer.Enabled = false; byte[] bArray = new byte[8]; switch (tType) { case timerTypes.TIMER_COM_VAL2: //Place device in binary mode and wait. bArray[0] = (byte)'1'; bArray[1] = (byte)' '; bArray[2] = (byte)'B'; bArray[3] = (byte)'\r'; try { aq.sp.Write(bArray, 0, 4); } catch (Exception err) { aqTimer.Stop(); aq.comCloser(); aq.comErrorHandler(err.ToString()); tStatus = timerStatus.TSTATUS_IDLE; } //Set timer to wait for next step in validation process. setTimer(20, timerTypes.TIMER_COM_VAL3, control); break; case timerTypes.TIMER_COM_VAL3: aq.rxState = rxStates.RX_IDLE; aq.aqCon.consoleUpdater(aq.txCount, aq.txData, consoleSources.CONSOLE_TX, control); try //Send configuration data to device. { aq.sp.Write(aq.txData, 0, aq.txCount); } catch (Exception err) { aqTimer.Stop(); aq.comCloser(); aq.comErrorHandler(err.ToString()); tStatus = timerStatus.TSTATUS_IDLE; } //Special case. End if changing to MatLab or ASCII. if (control == aq.btnMatlab || control == aq.btnAscii) { aq.txCount = 0; //Zero out tx count. aq.aqCon.rtbConsoleWindow_Clear(); aq.aqCon.rbtAscii_Checked(true); } else { //Set timer to wait for next step in validation process. setTimer(20, timerTypes.TIMER_COM_VAL4, control); } break; case timerTypes.TIMER_COM_VAL4: aq.rxState = rxStates.RX_GET_SETTINGS; bArray[0] = 0x0A; //Get device settings. try { aq.sp.Write(bArray, 0, 1); } catch (Exception err) { aqTimer.Stop(); aq.comCloser(); aq.comErrorHandler(err.ToString()); tStatus = timerStatus.TSTATUS_IDLE; } //Set timer to wait for next step in validation process. setTimer(100, timerTypes.TIMER_COM_VAL5, control); break; case timerTypes.TIMER_COM_VAL5: aq.rxState = rxStates.RX_IDLE; //Check and make sure the entire settings block has been received. if (aq.rxSettingsCount != AqSettings.SETTINGS_ARRAY_LENGTH) { aq.comCloser(); aq.comErrorHandler("Device Settings Data Incomplete"); break; } //Update the settings in the settings object. aq.aqSettings.doSettings(); //Update the GUI based on the current settings. aq.aqSettings.updateGUI(); aq.txCount = 0; //Zero out tx count. break; case timerTypes.TIMER_DIF_TEST: aq.rxState = rxStates.RX_DIF_TEST; aq.dTestPanel.btnDifTest.Enabled = true; bArray[0] = (byte)'D'; try //Start test. { aq.sp.Write(bArray, 0, 1); } catch (Exception err) { aqTimer.Stop(); aq.comCloser(); aq.comErrorHandler(err.ToString()); tStatus = timerStatus.TSTATUS_IDLE; } break; case timerTypes.TIMER_DIF_ABORT: //Wait to go to idle to avoid garbage in the console buffer. aq.dTestPanel.btnDifTest.Enabled = true; aq.rxState = rxStates.RX_IDLE; break; case timerTypes.TIMER_SWP_TEST: aq.rxState = rxStates.RX_SWP_TEST; aq.sTestPanel.btnSweepTest.Enabled = true; bArray[0] = (byte)'L'; try //Start test. { aq.sp.Write(bArray, 0, 1); } catch (Exception err) { aqTimer.Stop(); aq.comCloser(); aq.comErrorHandler(err.ToString()); tStatus = timerStatus.TSTATUS_IDLE; } break; case timerTypes.TIMER_SWP_ABORT: //Wait to go to idle to avoid garbage in the console buffer. aq.sTestPanel.btnSweepTest.Enabled = true; aq.rxState = rxStates.RX_IDLE; break; default: break; } }