FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RFExplorer-for-Python/Examples_USB/RFE_Example_control.py at master · RFExplorer/RFExplorer-for-Python · GitHub
RFExplorer
/
RFExplorer-for-Python
Public
Notifications
You must be signed in to change notification settings
Fork
26
Star
57
Code
Issues
5
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
RFExplorer-for-Python
/
Examples_USB
/
RFE_Example_control.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
114 lines (97 loc) · 4.5 KB
Breadcrumbs
RFExplorer-for-Python
/
Examples_USB
/
RFE_Example_control.py
Copy path
File metadata and controls
114 lines (97 loc) · 4.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#=======================================================================================
#This is an example code for RFExplorer python functionality.
#Contributed by https://github.com/xiaolu1990 - check with author for support
#=======================================================================================
#try:
# while True:
# input_value = input("please enter [G] for next step, [Q] for quit: ")
# if input_value == "G":
# print ("number is", num)
# num += 1
# continue
# # input_value = input("please enter [G] for next step: ")
# elif input_value == "Q":
# break
# else:
# input_value = input("please enter [G] for next step: ")
#except:
# pass
#=======================================================================================
import
numpy
as
np
import
time
from
datetime
import
datetime
import
RFExplorer
def
PrintPeak
(
objAnalazyer
):
"""This function prints the amplitude and frequency peak of the latest received sweep
"""
nIndex
=
objAnalazyer
.
SweepData
.
Count
-
1
objSweepTemp
=
objAnalazyer
.
SweepData
.
GetData
(
nIndex
)
nStep
=
objSweepTemp
.
GetPeakDataPoint
()
#Get index of the peak
fAmplitudeDBM
=
objSweepTemp
.
GetAmplitude_DBM
(
nStep
)
#Get amplitude of the peak
fCenterFreq
=
objSweepTemp
.
GetFrequencyMHZ
(
nStep
)
#Get frequency of the peak
print
(
"Sweep["
+
str
(
nIndex
)
+
"]: Peak: "
+
"{0:.3f}"
.
format
(
fCenterFreq
)
+
"MHz "
+
str
(
fAmplitudeDBM
)
+
"dBm"
)
return
fAmplitudeDBM
#---------------------------------------------------------
# global variables and initialization
#---------------------------------------------------------
SERIALPORT
=
None
#serial port identifier, use None to autodetect
BAUDRATE
=
500000
objRFE
=
RFExplorer
.
RFECommunicator
()
#Initialize object and thread
TOTAL_SECONDS
=
5
#Initialize time span to display activity
#---------------------------------------------------------
# Main processing loop
#---------------------------------------------------------
try
:
#Find and show valid serial ports
objRFE
.
GetConnectedPorts
()
#Connect to available port
if
(
objRFE
.
ConnectPort
(
SERIALPORT
,
BAUDRATE
)):
#Reset the unit to start fresh
objRFE
.
SendCommand
(
"r"
)
#Wait for unit to notify reset completed
while
(
objRFE
.
IsResetEvent
):
pass
#Wait for unit to stabilize
time
.
sleep
(
3
)
#Request RF Explorer configuration
objRFE
.
SendCommand_RequestConfigData
()
#Wait to receive configuration and model details
while
(
objRFE
.
ActiveModel
==
RFExplorer
.
RFE_Common
.
eModel
.
MODEL_NONE
):
objRFE
.
ProcessReceivedString
(
True
)
#Process the received configuration
while
True
:
#create a list for saving the recorded values
sample_value
=
[]
objRFE
.
ResetInternalBuffers
()
input_value
=
input
(
"please enter [G] for next step, [Q] for quit: "
)
if
input_value
==
"G"
:
#If object is an analyzer, we can scan for received sweeps
if
(
objRFE
.
IsAnalyzer
()):
print
(
"Receiving data..."
)
#Process until we complete scan time
nLastDisplayIndex
=
0
startTime
=
datetime
.
now
()
while
((
datetime
.
now
()
-
startTime
).
seconds
<
TOTAL_SECONDS
):
#Process all received data from device
objRFE
.
ProcessReceivedString
(
True
)
#Print data if received new sweep only
if
(
objRFE
.
SweepData
.
Count
>
nLastDisplayIndex
):
peak_value
=
PrintPeak
(
objRFE
)
sample_value
.
append
(
peak_value
)
nLastDisplayIndex
=
objRFE
.
SweepData
.
Count
print
(
"The average values of the sampling values is:"
,
round
(
np
.
mean
(
sample_value
),
2
),
"dBm"
)
else
:
print
(
"Error: Device connected is a Signal Generator.
\n
Please, connect a Spectrum Analyzer"
)
continue
elif
input_value
==
"Q"
:
break
else
:
input_value
=
input
(
"please enter [G] for next step: "
)
else
:
print
(
"Not Connected"
)
except
Exception
as
obEx
:
print
(
"Error: "
+
str
(
obEx
))
#---------------------------------------------------------
# Close object and release resources
#---------------------------------------------------------
#objRFE.Close() #Finish the thread and close port
objRFE
=
None
Back
|
FazBrowse Home
|
New Git URL