diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp index a232edc..a51ba48 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp @@ -112,6 +112,7 @@ LibreVNADriver::LibreVNADriver() { connected = false; skipOwnPacketHandling = false; + isIdle = true; SApoints = 0; hardwareVersion = 0; protocolVersion = 0; @@ -453,6 +454,9 @@ bool LibreVNADriver::setVNA(const DeviceDriver::VNASettings &s, std::function cb) { + isIdle = true; Protocol::PacketInfo p; p.type = Protocol::PacketType::SetIdle; return SendPacket(p, [=](TransmissionResult res) { @@ -608,7 +618,21 @@ bool LibreVNADriver::setExtRef(QString option_in, QString option_out) case Reference::OutFreq::MHZ100: p.reference.ExtRefOuputFreq = 100000000; break; } - return SendPacket(p); + bool ret; + if(isIdle) { + // can switch reference directly + ret = SendPacket(p); + } else { + // switching the reference while a sweep (or any frequency generation is active) + // can result in wrong frequencies when a frequency calibration is applied to + // the internal reference. Stop any activity before switching the reference and + // start it again afterwards + ret = sendWithoutPayload(Protocol::PacketType::SetIdle); + ret &= SendPacket(p); + ret &= SendPacket(lastNonIdlePacket); + } + + return ret; } void LibreVNADriver::registerTypes() diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h index ff9d9cd..36340c9 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h @@ -212,6 +212,9 @@ protected: Synchronization sync; bool syncMaster; + bool isIdle; + Protocol::PacketInfo lastNonIdlePacket; + std::map portStageMapping; // maps from excitedPort (count starts at one) to stage (count starts at zero) // Driver specific settings diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index 58eb4a7..48c43fa 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -1041,7 +1041,7 @@ void VNA::NewDatapoint(DeviceDriver::VNAMeasurement m) markerModel->updateMarkers(); } - if(m_avg.pointNum > 0 && m_avg.pointNum != lastPoint + 1) { + if(m_avg.pointNum > 0 && m_avg.pointNum != (unsigned int) (lastPoint + 1)) { qWarning() << "Got point" << m_avg.pointNum << "but last received point was" << lastPoint << "("<<(m_avg.pointNum-lastPoint-1)<<"missed points)"; } lastPoint = m_avg.pointNum;