1212
1313import time
1414import RFExplorer
15+ from RFExplorer import RFE_Common
16+ import math
1517
1618#---------------------------------------------------------
1719# Helper functions
@@ -22,11 +24,12 @@ def PrintPeak(objAnalazyer):
2224 """
2325 nIndex = objAnalazyer .SweepData .Count - 1
2426 objSweepTemp = objAnalazyer .SweepData .GetData (nIndex )
25- nStep = objSweepTemp .GetPeakStep () #Get index of the peak
27+ nStep = objSweepTemp .GetPeakDataPoint () #Get index of the peak
2628 fAmplitudeDBM = objSweepTemp .GetAmplitude_DBM (nStep ) #Get amplitude of the peak
2729 fCenterFreq = objSweepTemp .GetFrequencyMHZ (nStep ) #Get frequency of the peak
30+ fCenterFreq = math .floor (fCenterFreq * 10 ** 3 ) / 10 ** 3 #truncate to 3 decimals
2831
29- print ("Peak: " + "{0:.3f}" .format (fCenterFreq ) + "MHz " + str (fAmplitudeDBM ) + "dBm" )
32+ print (" Peak: " + "{0:.3f}" .format (fCenterFreq ) + "MHz " + str (fAmplitudeDBM ) + "dBm" )
3033
3134def ControlSettings (objAnalazyer ):
3235 """This functions check user settings
@@ -72,7 +75,12 @@ def ControlSettings(objAnalazyer):
7275
7376objRFE = RFExplorer .RFECommunicator () #Initialize object and thread
7477objRFE .AutoConfigure = False
75- SPAN_SIZE_MHZ = 100 #Initialize settings
78+
79+ #These values can be limited by specific RF Explorer Spectrum Analyzer model.
80+ #Check RFE SA Comparation chart from www.rf-explorer.com\models to know what
81+ #frequency setting are available for your model
82+ #These freq settings will be updated later in SA condition.
83+ SPAN_SIZE_MHZ = 50 #Initialize settings
7684START_SCAN_MHZ = 500
7785STOP_SCAN_MHZ = 900
7886
@@ -86,62 +94,126 @@ def ControlSettings(objAnalazyer):
8694
8795 #Connect to available port
8896 if (objRFE .ConnectPort (SERIALPORT , BAUDRATE )):
97+ print ("Reseting device..." )
8998 #Reset the unit to start fresh
9099 objRFE .SendCommand ("r" )
91100 #Wait for unit to notify reset completed
92101 while (objRFE .IsResetEvent ):
93102 pass
94103 #Wait for unit to stabilize
95- time .sleep (3 )
104+ time .sleep (8 )
96105
97106 #Request RF Explorer configuration
98107 objRFE .SendCommand_RequestConfigData ()
108+
99109 #Wait to receive configuration and model details
100110 while (objRFE .ActiveModel == RFExplorer .RFE_Common .eModel .MODEL_NONE ):
101111 objRFE .ProcessReceivedString (True ) #Process the received configuration
102-
112+
103113 #If object is an analyzer, we can scan for received sweeps
104114 if (objRFE .IsAnalyzer ()):
115+ print ("---- Spectrum Analyzer Example ----" )
116+ #update frequency setting. This was added to be compatible with all RFE SA models
117+ START_SCAN_MHZ = objRFE .MinFreqMHZ
118+ STOP_SCAN_MHZ = START_SCAN_MHZ + 200
119+ #SPAN_SIZE_MHZ = 50 is the minimum span available for RF Explorer SA models
120+
105121 #Control settings
106122 SpanSize , StartFreq , StopFreq = ControlSettings (objRFE )
107123 if (SpanSize and StartFreq and StopFreq ):
108- #set new frequency range
109- objRFE .UpdateDeviceConfig (StartFreq , StopFreq )
110-
111- LastStartFreq = 0
112124 nInd = 0
113- while (StopFreq <= STOP_SCAN_MHZ and StartFreq < StopFreq ):
114- #Process all received data from device
115- while (objRFE .SweepData .Count < 1 ):
116- objRFE .ProcessReceivedString (True )
117-
118- #Print data if received new sweep and a different start frequency
119- if (StartFreq != LastStartFreq ):
120- nInd += 1
121- print ("Freq range[" + str (nInd ) + "]: " + str (StartFreq ) + " - " + str (StopFreq ) + "MHz" )
122- PrintPeak (objRFE )
123- LastFreqStart = StartFreq
124-
125+ while (True ):
126+ #Set new configuration into device
127+ objRFE .UpdateDeviceConfig (StartFreq , StopFreq )
128+
129+ objSweep = None
130+ #Wait for new configuration to arrive (as it will clean up old sweep data)
131+ while (True ):
132+ objRFE .ProcessReceivedString (True );
133+ if (objRFE .SweepData .Count > 0 ):
134+ objSweep = objRFE .SweepData .GetData (objRFE .SweepData .Count - 1 )
135+
136+ nInd += 1
137+ print ("Freq range[" + str (nInd ) + "]: " + str (StartFreq ) + " - " + str (StopFreq ) + "MHz" )
138+ PrintPeak (objRFE )
139+ if (math .fabs (objRFE .StartFrequencyMHZ - StartFreq ) <= 0.001 ):
140+ break
141+
125142 #set new frequency range
126143 StartFreq = StopFreq
127144 StopFreq = StartFreq + SpanSize
128-
129- #Maximum stop/start frequency control
130145 if (StopFreq > STOP_SCAN_MHZ ):
131146 StopFreq = STOP_SCAN_MHZ
132- if (StartFreq < StopFreq ):
133- objRFE .UpdateDeviceConfig (StartFreq , StopFreq )
134-
135- #Wait for new configuration to arrive (as it will clean up old sweep data)
136- objSweep = None
137- while ((objSweep is None ) or objSweep .StartFrequencyMHZ != StartFreq ):
138- objRFE .ProcessReceivedString (True )
139- if (objRFE .SweepData .Count > 0 ):
140- objSweep = objRFE .SweepData .GetData (objRFE .SweepData .Count - 1 )
147+
148+ if (StartFreq >= StopFreq ):
149+ break
141150 else :
142151 print ("Error: settings are wrong.\n Please, change and try again" )
143152 else :
144- print ("Error: Device connected is a Signal Generator. \n Please, connect a Spectrum Analyzer" )
153+ print ("---- Signal Generator Example ----" )
154+ #request internal calibration data, if available
155+ objRFE .SendCommand ("Cq" )
156+ objRFE6GENCal = objRFE .GetRFE6GENCal () #Object to manage the calibration data from generator
157+ while (objRFE6GENCal .GetCalSize () < 0 ):
158+ objRFE .ProcessReceivedString (True ) #Process the received configuration
159+
160+ objRFE .RFGenCWFrequencyMHZ = 500 ;
161+ if (objRFE .ExpansionBoardActive ):
162+ #Amplitude sweep
163+ objRFE .RFGenExpansionPowerDBM = - 40
164+ objRFE .RFGenExpansionPowerStartDBM = - 40
165+ objRFE .RFGenExpansionPowerStepDB = 5
166+ objRFE .RFGenExpansionPowerStopDBM = - 20
167+ objRFE .RFGenStepWaitMS = 500
168+ sStartDBM = str (objRFE .RFGenExpansionPowerStartDBM )
169+ sStopDBM = str (objRFE .RFGenExpansionPowerStopDBM )
170+ sSteps = str (objRFE .RFGenExpansionPowerStepDB )
171+ else :
172+ objRFE .RFGenStartHighPowerSwitch = False
173+ objRFE .RFGenStopHighPowerSwitch = True
174+ objRFE .RFGenStartPowerLevel = 0
175+ objRFE .RFGenStopPowerLevel = 3
176+ objRFE .RFGenSweepSteps = 5
177+ objRFE .RFGenStepWaitMS = 500
178+ arrAmplitudeDBM = objRFE6GENCal .GetEstimatedAmplitudeArray (objRFE .RFGenCWFrequencyMHZ )
179+ sStartDBM = str (arrAmplitudeDBM [0 ]) #min
180+ sStopDBM = str (arrAmplitudeDBM [len (arrAmplitudeDBM ) - 1 ]) #max
181+ sSteps = str (objRFE .RFGenSweepSteps )
182+
183+
184+ print ("Amplitude Sweep Settings = Start:" + sStartDBM + "dBm" + " - Stop:" + sStopDBM + "dBm" +
185+ " - Steps:" + sSteps + " - Delay:" + str (objRFE .RFGenStepWaitMS ) + "ms" + " - CW:" + str (objRFE .RFGenCWFrequencyMHZ ) + "MHz" )
186+
187+ print ("Amplitude sweep ON" )
188+ objRFE .SendCommand_GeneratorSweepAmplitude ()
189+ time .sleep (5 )
190+ objRFE .SendCommand_GeneratorRFPowerOFF ()
191+ print ("Amplitude sweep OFF" )
192+
193+ time .sleep (2 )
194+
195+ #Frequency sweep
196+ if (objRFE .ExpansionBoardActive ):
197+ objRFE .RFGenExpansionPowerDBM = - 40
198+ sPowerDBM = " - Power:" + str (objRFE .RFGenExpansionPowerDBM ) + "dBm"
199+ else :
200+ objRFE .RFGenHighPowerSwitch = False
201+ objRFE .RFGenPowerLevel = 0
202+ sPowerDBM = " - Power:" + str (objRFE .GetSignalGeneratorEstimatedAmplitude (objRFE .RFGenCWFrequencyMHZ )) + "dBm"
203+ objRFE .RFGenStartFrequencyMHZ = 495.0
204+ objRFE .RFGenStopFrequencyMHZ = 505.0
205+ objRFE .RFGenExpansionPowerDBM = - 40.0
206+ objRFE .RFGenSweepSteps = 11
207+ objRFE .RFGenStepWaitMS = 500
208+
209+ print ("Frequency Sweep Settings = Start:" + str (objRFE .StartFrequencyMHZ ) + "MHz" + " - Stop:" + str (objRFE .StopFrequencyMHZ ) + "MHz" +
210+ " - Steps:" + str (objRFE .RFGenSweepSteps ) + " - Delay:" + str (objRFE .RFGenStepWaitMS ) + "ms" + sPowerDBM )
211+
212+ print ("Frequency sweep ON" )
213+ objRFE .SendCommand_GeneratorSweepFreq ()
214+ time .sleep (5 )
215+ objRFE .SendCommand_GeneratorRFPowerOFF ()
216+ print ("Frequency sweep OFF" )
145217 else :
146218 print ("Not Connected" )
147219except Exception as obEx :
0 commit comments