void CollectOffset() { // Waveform is a kind of square waveform for just 1 msec FormattedIO488 io488 = null; ResourceManager rm = null; if (io488 == null) { io488 = new FormattedIO488(); } if (rm == null) { rm = new ResourceManager(); } try { io488.IO = (IMessage)rm.Open("TCPIP0::10.112.39.165::inst0::INSTR", AccessMode.NO_LOCK, 99999, ""); io488.IO.Timeout = 1000; io488.IO.WriteString("*IDN?\n"); string strMessage = io488.ReadString(); if (strMessage.Length > 1) { Log("Scope connection Done."); //bScopeConnected = true; } else { Log("Scope connection Failed!"); bRunThread = false; return; } } catch (Exception ex) { bRunThread = false; Log(ex.Message); return; } io488.IO.WriteString("MEASURE:clear\n"); io488.IO.WriteString("MEASURE:SOURCE CHANNEL2,CHANNEL3\n"); io488.IO.WriteString("MESURE: DEFIN DELTATIME: RISING, 1, MIDDLE, RISING, 1, MIDDLE\n"); io488.IO.WriteString("MEASURE:DELTATIME\n"); FileStream fs; StreamWriter sw; List <string> result = new List <string>(); #region AWG Continuous and VXT2 Continuous // AWG Continuous Mode measurement ctrlParameter.PlaybackMode = ModulationPlaybackMode.Continuous; // : ModulationPlaybackMode.Continuous; ctrlParameter.queueMode = SD_QueueMode.CYCLIC; // SD_QueueMode.ONE_SHOT;// : SD_QueueMode.CYCLIC; ctrlParameter.repeatCycle = 0; //2; //ctrlParameter.repeatCycle = 0; // QueueWaveform first //if (!chkAWGOnlyInit.Checked) int nTotalRepeat = (int)((200 - 80) / 0.01) * 2; int nCurrentPos = 0; TickTime timer = new TickTime(); double elapsedTime = 0; for (double freqToTest = 80; freqToTest < 200; freqToTest += 0.01) { timer.Start(); ctrlParameter.RFSamplingRateInMhz = freqToTest; LoadSquareWaveform(freqToTest); Log("Queue Waveform"); vxt2Hvi.VXT2QueueWaveform(IQData, ctrlParameter); SystemFrequency = freqToTest * 1e6 * ctrlParameter.OSRFactor; SynchronizeFrequency = -999; m3202A.AWGQueueWaveform(SystemFrequency, ref SynchronizeFrequency, awgWave, ctrlParameter); bool bSyncNeeded = true; if (ClockSyncFrequency == -999) { ClockSyncFrequency = SynchronizeFrequency; } else { if (ClockSyncFrequency != SynchronizeFrequency) { bSyncNeeded = true; } else { bSyncNeeded = false; } } // Synchronize Frequency if needed. if (bSyncNeeded) { Log("Sync Module"); ClockSyncFrequency = SynchronizeFrequency; if (SynchronizeFrequency < 0) { Log("Sync Freq is abnormal : " + SynchronizeFrequency.ToString()); return; } SynchronizeModule(); } // Start Playback Log("Start play"); //if (!chkAWGOnlyInit.Checked) vxt2Hvi.PlayWaveform(ctrlParameter); m3202A.PlayWaveform(); // Generate Trigger //Log("Generate PXI0 Trigger"); vxt2Hvi.GenerateTrigger(); vxt2Hvi.Stop(); m3202A.Stop(); m3202A.PlayWaveform(); vxt2Hvi.GenerateTrigger(); //Thread.Sleep(500); // Measure from Scope. Using Existing setting try { Thread.Sleep(50); io488.IO.WriteString("MEASURE:DELTATIME?\n"); string returnStr = io488.ReadString(); //Thread.Sleep(50); Log2((SystemFrequency / 1e6).ToString(".000") + "=" + returnStr, false); result.Add((SystemFrequency / 1e6).ToString(".000") + " : " + Math.Abs(Convert.ToDouble(returnStr)).ToString()); Log((SystemFrequency / 1e6).ToString(".000") + "=" + returnStr, false); } catch (Exception ex) { Log("Scope control Error. Keep working on!! - " + (SystemFrequency / 1e6).ToString(".000")); Log2((SystemFrequency / 1e6).ToString(".000") + "=0.000"); } //break; if (bRunThread == false) { Log("Test Interruped by User.."); return; } nCurrentPos++; elapsedTime = timer.GetElapsedTime(); double EstimatedTimeLeft = elapsedTime / 1e3 * (nTotalRepeat - nCurrentPos); LogStatus(nCurrentPos.ToString() + "/" + nTotalRepeat.ToString() + " : Estimate time left " + EstimatedTimeLeft.ToString(".00") + "Sec"); } fs = new FileStream(".\\VXT2_C_AWG_C.dat", FileMode.Create); sw = new StreamWriter(fs); sw.WriteLine("[AWGClockFrequency Vs Offset]"); sw.WriteLine("//AWG Continuous, VXT2 Continuous"); foreach (string t in result) { sw.WriteLine(t); } sw.Close(); fs.Close(); #endregion #region AWG Single 2 play and VXT2 Continuous // AWG Continuous Mode measurement ctrlParameter.PlaybackMode = ModulationPlaybackMode.Continuous; // : ModulationPlaybackMode.Continuous; ctrlParameter.queueMode = SD_QueueMode.ONE_SHOT; // : SD_QueueMode.CYCLIC; ctrlParameter.repeatCycle = 2; //ctrlParameter.repeatCycle = 0; // QueueWaveform first //if (!chkAWGOnlyInit.Checked) for (double freqToTest = 80; freqToTest < 200; freqToTest += 0.01) { timer.Start(); ctrlParameter.RFSamplingRateInMhz = freqToTest; LoadSquareWaveform(freqToTest); Log("Queue Waveform"); vxt2Hvi.VXT2QueueWaveform(IQData, ctrlParameter); SystemFrequency = freqToTest * 1e6 * ctrlParameter.OSRFactor; SynchronizeFrequency = -999; m3202A.AWGQueueWaveform(SystemFrequency, ref SynchronizeFrequency, awgWave, ctrlParameter); bool bSyncNeeded = true; if (ClockSyncFrequency == -999) { ClockSyncFrequency = SynchronizeFrequency; } else { if (ClockSyncFrequency != SynchronizeFrequency) { bSyncNeeded = true; } else { bSyncNeeded = false; } } // Synchronize Frequency if needed. if (bSyncNeeded) { Log("Sync Module"); ClockSyncFrequency = SynchronizeFrequency; if (SynchronizeFrequency < 0) { Log("Sync Freq is abnormal : " + SynchronizeFrequency.ToString()); return; } SynchronizeModule(); } // Start Playback Log("Start play"); //if (!chkAWGOnlyInit.Checked) vxt2Hvi.PlayWaveform(ctrlParameter); m3202A.PlayWaveform(); // Generate Trigger Log("Generate PXI0 Trigger"); vxt2Hvi.GenerateTrigger(); vxt2Hvi.Stop(); m3202A.Stop(); m3202A.PlayWaveform(); vxt2Hvi.GenerateTrigger(); //Thread.Sleep(500); // Measure from Scope. Using Existing setting try { //io488.IO.WriteString("MEASURE:clear\n"); //io488.IO.WriteString("MEASURE:SOURCE CHANNEL2,CHANNEL3\n"); //io488.IO.WriteString("MESURE: DEFIN DELTATIME: RISING, 1, MIDDLE, RISING, 1, MIDDLE\n"); //io488.IO.WriteString("MEASURE:DELTATIME\n"); Thread.Sleep(50); io488.IO.WriteString("MEASURE:DELTATIME?\n"); string returnStr = io488.ReadString(); //Thread.Sleep(50); Log2((SystemFrequency / 1e6).ToString(".000") + "=" + returnStr, false); result.Add((SystemFrequency / 1e6).ToString(".000") + " : " + Math.Abs(Convert.ToDouble(returnStr)).ToString()); Log((SystemFrequency / 1e6).ToString(".000") + "=" + returnStr, false); } catch (Exception ex) { Log("Scope control Error. Keep working on!! - " + (SystemFrequency / 1e6).ToString(".000")); Log2((SystemFrequency / 1e6).ToString(".000") + "=0.000"); } //break; if (bRunThread == false) { Log("Test Interruped by User.."); return; } nCurrentPos++; elapsedTime = timer.GetElapsedTime(); double EstimatedTimeLeft = elapsedTime / 1e3 * (nTotalRepeat - nCurrentPos); LogStatus(nCurrentPos.ToString() + "/" + nTotalRepeat.ToString() + " : Estimate time left " + EstimatedTimeLeft.ToString(".00") + "Sec"); } fs = new FileStream(".\\VXT2_C_AWG_S2.dat", FileMode.Create); sw = new StreamWriter(fs); sw.WriteLine("[AWGClockFrequency Vs Offset]"); sw.WriteLine("//AWG Single, VXT2 Continuous"); foreach (string t in result) { sw.WriteLine(t); } sw.Close(); fs.Close(); #endregion Log("Test Finised.."); bRunThread = false; }
private void btnStartWaveform_Click(object sender, EventArgs e) { //Log("Remove Event.."); //this.vxt2Hvi.updateLog -= new BaseClass.UpdateLog(Log); //this.m3202A.updateLog -= new BaseClass.UpdateLog(Log); try { TickTime timer = new TickTime(); //vxt2Hvi.Stop(false, false); m3202A.Stop(false); double tLoadWaveformTime; double tSyncTime = 0; double tFirstPlayTime = 0; double tStopTime = 0; double tSecondPlayTime = 0; vxt2Hvi.SetSyncOutputTriggering(ctrlParameter); // Load waveform into Memory. this.btnLoadWaveformIntoMemory_Click(sender, e); ctrlParameter.PlaybackMode = chkVXTSingle.Checked ? ModulationPlaybackMode.Single : ModulationPlaybackMode.Continuous; ctrlParameter.queueMode = chkAWGSingle.Checked ? SD_QueueMode.ONE_SHOT : SD_QueueMode.CYCLIC; if (chkAWGSingle.Checked) { ctrlParameter.repeatCycle = 2; } else { ctrlParameter.repeatCycle = 0; } // QueueWaveform first //Log("Queue Waveform"); //if (!chkAWGOnlyInit.Checked) SystemFrequency = ctrlParameter.RFSamplingRateInMhz * 1e6 * ctrlParameter.OSRFactor; timer.Start(); vxt2Hvi.VXT2QueueWaveform(IQData, ctrlParameter); m3202A.AWGQueueWaveform((ctrlParameter.Use1GhzFixedSamplingRate ? 1e9 : SystemFrequency), ref SynchronizeFrequency, awgWave, ctrlParameter, ctrlParameter.DummyWaveformLength, chkUseDummyWaveform.Checked); tLoadWaveformTime = timer.GetElapsedTime(); timer.Start(); bool bSyncNeeded = true; if (ClockSyncFrequency == -999) { ClockSyncFrequency = SynchronizeFrequency; } else { if (ClockSyncFrequency != SynchronizeFrequency) { bSyncNeeded = true; } else { bSyncNeeded = false; } } //bSyncNeeded = true; // Synchronize Frequency if needed. bSyncNeeded = true; if (bSyncNeeded) { //Log("Sync Module"); ClockSyncFrequency = SynchronizeFrequency; if (SynchronizeFrequency < 0) { Log("Sync Freq is abnormal : " + SynchronizeFrequency.ToString()); return; } SynchronizeModule(); tSyncTime = timer.GetElapsedTime(); } else { m3202A.SynchronizeHVIModule(); tSyncTime = timer.GetElapsedTime(); } // Start Playback //Log("Start play"); timer.Start(); //if (!chkAWGOnlyInit.Checked) vxt2Hvi.PlayWaveform(ctrlParameter); m3202A.PlayWaveform(); // Generate Trigger //Log("Generate PXI0 Trigger"); //Thread.Sleep(100); vxt2Hvi.GenerateTrigger(); if (SynchronizeFrequency == 80e3) { Thread.Sleep(30); //Thread.Sleep(ctrlParameter.SyncDelay); vxt2Hvi.Stop(); m3202A.Stop(true); vxt2Hvi.PlayWaveform(ctrlParameter); m3202A.PlayWaveform(); // Generate Trigger //Log("Generate PXI0 Trigger"); //Thread.Sleep(1000); vxt2Hvi.GenerateTrigger(); Thread.Sleep(30); } tFirstPlayTime = timer.GetElapsedTime(); timer.Start(); if (chkStopStartAfterQueue.Checked) { // Additional code for stability //vxt2Hvi.Stop(true,true); //m3202A.Stop(); //if (SynchronizeFrequency == 80e3) //{ // //Thread.Sleep(30); // vxt2Hvi.Stop(true, true); // vxt2Hvi.PlayWaveform(ctrlParameter); // m3202A.PlayWaveform(); // // Generate Trigger // //Log("Generate PXI0 Trigger"); // //Thread.Sleep(1000); // vxt2Hvi.GenerateTrigger(); //} vxt2Hvi.Stop(true, false); m3202A.Stop(false); tStopTime = timer.GetElapsedTime(); // Start Playback //Log("Start play"); //ctrlParameter.PlaybackMode = chkVXTSingle.Checked ? ModulationPlaybackMode.Single : ModulationPlaybackMode.Continuous; //ctrlParameter.queueMode = chkAWGSingle.Checked ? SD_QueueMode.ONE_SHOT : SD_QueueMode.CYCLIC; //if (!chkAWGOnlyInit.Checked) vxt2Hvi.PlayWaveform(ctrlParameter); m3202A.PlayWaveform(); // Generate Trigger //Log("Generate PXI0 Trigger"); //Thread.Sleep(1000); vxt2Hvi.GenerateTrigger(); tSecondPlayTime = timer.GetElapsedTime(); } Log("Loading Waveform : " + tLoadWaveformTime.ToString() + " mSec"); Log("First Play Time : " + tFirstPlayTime.ToString() + " mSec"); Log("Stop Time : " + tStopTime.ToString() + " mSec"); Log("Second Play Time : " + tSecondPlayTime.ToString() + " mSec"); Log("Total Time Taken : " + (tLoadWaveformTime + tFirstPlayTime + tStopTime + tSecondPlayTime).ToString() + " mSec"); } catch (Exception ex) { Log(ex.Message); } //Log("Connect Event.."); //this.vxt2Hvi.updateLog += new BaseClass.UpdateLog(Log); //this.m3202A.updateLog += new BaseClass.UpdateLog(Log); }