private void OnCommandC_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; //Example command new configuration request, requires wait before allowing user to change config again if (m_objRFE != null && m_objRFE.PortConnected) { //ask device to change configuration m_bNewConfigurationReceived = false; m_objRFE.UpdateDeviceConfig(584.800, 587.575, 0f, -120f); //wait for device to reconfigure while (!m_bNewConfigurationReceived) { Thread.Sleep(100); //Wait 100ms Application.DoEvents(); //process events to get new configuration } //ask device to change resolution m_bNewConfigurationReceived = false; m_objRFE.SendCommand_SweepDataPointsEx(5570); //wait for device to reconfigure while (!m_bNewConfigurationReceived) { Thread.Sleep(100); //Wait 100ms Application.DoEvents(); //process events to get new configuration } } Cursor.Current = Cursors.Default; }
private void OnCenterFreqChanged(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { double center = Convert.ToDouble(CenterFreq.Text); m_objRFE.UpdateDeviceConfig(center - freqSpan / 2, center + freqSpan / 2); currentData.Clear(); peakHoldData.Clear(); ScanPlot.Series[0].Points.Clear(); ScanPlot.Series[1].Points.Clear(); ScanPlot.Refresh(); } }
/// <summary> /// During this time process, user can write on the keyboard if it is active and it is checking keyboard. /// If there is any new setting, it will sending it to the device /// If bCountActive is active and g_nTotalFiles, number of files .csv created is equal to 0, then the function ends. /// </summary> /// <param name="nSeconds"></param> /// <param name="bCheckKeyboard"></param> /// <param name="bCountActive"> This means "/count:" is an argument. False by default </param> static void WaitAndProcess(int nSeconds, bool bCheckKeyboard = true, bool bCountActive = false) { bool bRunForever = false; if (nSeconds == -1) { bRunForever = true; } DateTime objTimeStart = DateTime.Now; do { string sDummy; //we do not use the string in this loop //Process all pending messages received from device g_objRFE.ProcessReceivedString(true, out sDummy); if (bCountActive && g_nTotalFiles == 0) { break; } //check if user pressed any key if (bCheckKeyboard && Console.KeyAvailable) { ConsoleKeyInfo cki = new ConsoleKeyInfo(); cki = Console.ReadKey(true); bool bChangeSettings = false; double fStartMHz = g_objRFE.StartFrequencyMHZ; double fSpanMHZ = g_objRFE.CalculateFrequencySpanMHZ(); switch (cki.Key) { case ConsoleKey.Escape: case ConsoleKey.Q: //finish function and therefore end up closing the application Trace.WriteLine("<Q> - Closing the application..."); return; case ConsoleKey.LeftArrow: Trace.WriteLine("<LEFT> - Updating scan to lower frequency..."); Trace.WriteLine("Current configuration - Start:" + g_objRFE.StartFrequencyMHZ.ToString("f3") + "MHZ, Stop: " + g_objRFE.StopFrequencyMHZ.ToString("f3") + "MHz, Span:" + fSpanMHZ.ToString("f3")); //Set new start frequency, keeping same span fStartMHz = fStartMHz - fSpanMHZ; //Check start frequency is in valid device range if (fStartMHz < g_objRFE.MinFreqMHZ) { fStartMHz = g_objRFE.MinFreqMHZ; } bChangeSettings = true; break; case ConsoleKey.RightArrow: Trace.WriteLine("<RIGHT> - Updating scan to higher frequency..."); Trace.WriteLine("Current configuration - Start:" + g_objRFE.StartFrequencyMHZ.ToString("f3") + "MHZ, Stop: " + g_objRFE.StopFrequencyMHZ.ToString("f3") + "MHz, Span:" + fSpanMHZ.ToString("f3")); //Set new start frequency, keeping same span fStartMHz = fStartMHz + fSpanMHZ; //Check start frequency is in valid device range if ((fStartMHz + fSpanMHZ) > g_objRFE.MaxFreqMHZ) { fStartMHz = g_objRFE.MaxFreqMHZ - fSpanMHZ; } bChangeSettings = true; break; default: Trace.WriteLine("Ignored key."); break; } if (bChangeSettings) { //Send new configuration g_fStartMHZ = fStartMHz; //change flag value to recognize when new configuration is already in place g_fStopMHZ = fStartMHz + fSpanMHZ; Trace.WriteLine("New configuration - Start:" + g_fStartMHZ.ToString("f3") + "MHZ, Stop: " + g_fStopMHZ.ToString("f3") + "MHz"); g_bIgnoreSweeps = true; g_objRFE.UpdateDeviceConfig(fStartMHz, g_fStopMHZ, g_objRFE.AmplitudeTopDBM, g_objRFE.AmplitudeBottomDBM); } } } while ((bRunForever || ((DateTime.Now - objTimeStart).TotalSeconds < nSeconds))); //save file before closing, if any. SaveRFEFile(); }
public void Set_Frequency(double f1, double f2) { m_dev.UpdateDeviceConfig(f1, f2); }