Skip to content

Commit e1cc4a3

Browse files
committed
Added RFE6GEN_Example_USB.py again
1 parent 4934f66 commit e1cc4a3

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#pylint: disable=trailing-whitespace, line-too-long, bad-whitespace, invalid-name, R0204, C0200
2+
#pylint: disable=superfluous-parens, missing-docstring, broad-except, R0801
3+
#pylint: disable=too-many-lines, too-many-instance-attributes, too-many-statements, too-many-nested-blocks
4+
#pylint: disable=too-many-branches, too-many-public-methods, too-many-locals, too-many-arguments
5+
6+
#=====================================================================================
7+
#This is an example code for RF Explorer RF6GEN Signal Generator python functionality.
8+
#Set frequency and power level to generate a frequency SWEEP and CW signal
9+
#in RFE6GEN Signal Generator.
10+
#In order to avoid USB issues, connect only RF Explorer Signal Generator to run this example.
11+
#It is not suggested to connect RF Explorer Spectrum Analyzer at the same time
12+
#=====================================================================================
13+
14+
import time
15+
import RFExplorer
16+
17+
18+
#---------------------------------------------------------
19+
# global variables and initialization
20+
#---------------------------------------------------------
21+
22+
SERIALPORT = None #serial port data
23+
BAUDRATE = 500000
24+
25+
objRFEGenerator = RFExplorer.RFECommunicator() #Initialize object and thread
26+
27+
#---------------------------------------------------------
28+
# Main processing loop
29+
#---------------------------------------------------------
30+
31+
try:
32+
#Find and show valid serial ports
33+
objRFEGenerator.GetConnectedPorts()
34+
35+
#Connect to available port
36+
if (objRFEGenerator.ConnectPort(SERIALPORT, BAUDRATE)):
37+
#Reset the unit to start fresh
38+
objRFEGenerator.SendCommand("r")
39+
#Wait for unit to notify reset completed
40+
while(objRFEGenerator.IsResetEvent):
41+
pass
42+
#Wait for unit to stabilize
43+
time.sleep(3)
44+
45+
#Request RF Explorer Generator configuration
46+
objRFEGenerator.SendCommand_RequestConfigData()
47+
#Wait to receive configuration and model details
48+
while(objRFEGenerator.ActiveModel == RFExplorer.RFE_Common.eModel.MODEL_NONE):
49+
objRFEGenerator.ProcessReceivedString(True) #Process the received configuration
50+
51+
#If object is a generator, we can continue the example
52+
if (objRFEGenerator.IsGenerator()):
53+
#request internal calibration data, if available
54+
objRFEGenerator.SendCommand("Cq")
55+
objRFE6GENCal = objRFEGenerator.GetRFE6GENCal() #Object to manage the calibration data from generator
56+
while (objRFE6GENCal.GetCalSize() < 0):
57+
objRFEGenerator.ProcessReceivedString(True) #Process the received configuration
58+
59+
#----------- Frequency Sweep Test Section -----------
60+
#Set Sweep Setting
61+
print("# New SWEEP settings...")
62+
objRFEGenerator.RFGenStartFrequencyMHZ = 400
63+
objRFEGenerator.RFGenStopFrequencyMHZ = 450
64+
objRFEGenerator.RFGenSweepSteps = 25
65+
objRFEGenerator.RFGenStepWaitMS = 200
66+
print("SWEEP Settings = Start:" + str(objRFEGenerator.StartFrequencyMHZ) + "MHz" + " - Stop:" + str(objRFEGenerator.StopFrequencyMHZ) + "MHz" +
67+
" - Steps:" + str(objRFEGenerator.RFGenSweepSteps) + " - Delay:" + str(objRFEGenerator.RFGenStepWaitMS) + "ms" + " - Power:" + str(objRFEGenerator.GetSignalGeneratorEstimatedAmplitude(objRFEGenerator.RFGenCWFrequencyMHZ)) + "dBm")
68+
#Start Frequency Sweep
69+
objRFEGenerator.SendCommand_GeneratorSweepFreq()
70+
#wait 5 seconds
71+
time.sleep(5)
72+
#Stop Frequency Sweep
73+
objRFEGenerator.SendCommand_GeneratorRFPowerOFF()
74+
print("Stop SWEEP")
75+
76+
#----------- CW Test Section -----------
77+
#Set CW settings
78+
print("# New CW settings...")
79+
objRFEGenerator.RFGenCWFrequencyMHZ = 500
80+
objRFEGenerator.RFGenHighPowerSwitch = False
81+
objRFEGenerator.RFGenPowerLevel = 3
82+
print("Change CW settings --> Start:" + str(objRFEGenerator.RFGenCWFrequencyMHZ) + "MHz" + " - Power:" + str(objRFEGenerator.GetSignalGeneratorEstimatedAmplitude(objRFEGenerator.RFGenCWFrequencyMHZ)) + "dBm")
83+
#Start CW
84+
objRFEGenerator.SendCommand_GeneratorCW()
85+
time.sleep(5)
86+
#Change CW power
87+
print("# New CW power...")
88+
objRFEGenerator.RFGenPowerLevel = 0
89+
print("Change CW power = Start:" + str(objRFEGenerator.RFGenCWFrequencyMHZ) + "MHz" + " - Power:" + str(objRFEGenerator.GetSignalGeneratorEstimatedAmplitude(objRFEGenerator.RFGenCWFrequencyMHZ)) + "dBm")
90+
#Start new CW
91+
objRFEGenerator.SendCommand_GeneratorCW()
92+
time.sleep(5)
93+
#Change CW Frequency
94+
print("# New CW frequency...")
95+
objRFEGenerator.RFGenCWFrequencyMHZ = 510
96+
print("Change CW frequency = Start:" + str(objRFEGenerator.RFGenCWFrequencyMHZ) + "MHz" + " - Power:" + str(objRFEGenerator.GetSignalGeneratorEstimatedAmplitude(objRFEGenerator.RFGenCWFrequencyMHZ)) + "dBm")
97+
#Start new CW
98+
objRFEGenerator.SendCommand_GeneratorCW()
99+
time.sleep(5)
100+
else:
101+
print("Error: Device connected is a Spectrum Analyzer. \nPlease, connect a Signal Generator")
102+
else:
103+
print("Not Connected")
104+
except Exception as obEx:
105+
print("Error: " + str(obEx))
106+
107+
#---------------------------------------------------------
108+
# Close object and release resources
109+
#---------------------------------------------------------
110+
111+
objRFEGenerator.Close() #Finish the thread and close port
112+
objRFEGenerator = None

0 commit comments

Comments
 (0)