Bases: object
Python class to interact with the MS2760A Anritsu spectrum analyzer.
Functionality implemented retrieves the peak (power and frequency) of the spectrum of the system under test.
The spectrum analyzer also outputs xml files. Developer has to implement a method/s to parse the output of such files if they are used. In the commit history of the github of this project a parser was partially implemented (if the developer wants to check that).
Source code in a2gmeasurements.py
| class myAnritsuSpectrumAnalyzer(object):
"""
Python class to interact with the MS2760A Anritsu spectrum analyzer.
Functionality implemented retrieves the peak (power and frequency) of the spectrum of the system under test.
The spectrum analyzer also outputs xml files. Developer has to implement a method/s to parse the output of such files if they are used. In the commit history of the github of this project a parser was partially implemented (if the developer wants to check that).
"""
def __init__(self, is_debug=True, is_config=True):
"""
Initializes attributes of this class.
Args:
is_debug (bool, optional): print debug messages. Defaults to True.
is_config (bool, optional): true if you want to configure the Spectrum Analyzer. Defaults to True.
"""
self.model = 'MS2760A'
self.is_debug = is_debug
self.is_config = is_config
def spectrum_analyzer_connect(self, HOST='127.0.0.1', PORT=9001):
"""
Creates a socket to connect to the spectrum analyzer.
Args:
HOST (str, optional): ip address of the spectrum analyzer. Defaults to ``127.0.0.1``.
PORT (int, optional): TCP/IP port. Defaults to 9001.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.anritsu_con_socket = s
self.anritsu_con_socket.connect((HOST, PORT))
def retrieve_max_pow(self, method=2):
"""
Retrieves the maximum power and its correspondent frequency of the spectrum of the system under test.
Args:
method (int, optional): how to get the maximum peak and corresponding frequency. This is for developer. It is indisctintive for user. Defaults to 2.
Raises:
Exception: when method is outside of available methods to compute the peak and corresponding frequency.
Returns:
Dictionary (dict): dictionary with self-explanatory keys 'MAG', 'MAG_UNITS', 'FREQ', 'FREQ_UNITS'.
"""
# Read the ID of the Spectrum Analyzer.
if self.is_debug:
self.anritsu_con_socket.send(b"*IDN?\n")
self.anritsu_con_socket.settimeout(20)
rsp = self.anritsu_con_socket.recv(1024)
self.model = rsp.decode()
# Configure the Spectrum Analyzer
if self.is_config:
self.anritsu_con_socket.send(b"SENS:FREQ:START 59.95 GHz\n")
self.anritsu_con_socket.send(b"SENS:FREQ:STOP 60.05 GHz\n")
self.anritsu_con_socket.send(b"BAND:RES 200 KHz\n")
self.anritsu_con_socket.send(b":DISPLAY:POINTCOUNT 101\n")
self.anritsu_con_socket.send(b":CALCulate:MARKer1:STATe 1\n")
# Find the maximum power
# 1. Pause the measurement collection
self.anritsu_con_socket.send(b"INIT:CONT OFF\n")
if method == 1:
# 2.1 Place Marker 1 at maximum peak
self.anritsu_con_socket.send(b":CALCulate:MARKer1:MAXimum\n")
# 2.2 Find the frequency in Hz
self.anritsu_con_socket.send(b":CALCulate:MARKer1:X?\n")
freq = self.anritsu_con_socket.recv(1024)
# 2.3 Find the maximum power in dBm
self.anritsu_con_socket.send(b":CALCulate:MARKer1:Y?\n")
pwr = self.anritsu_con_socket.recv(1024)
elif method == 2:
# 3.1 Find the maximum peak
self.anritsu_con_socket.send(b":CALCulate:PEAK:COUNt 1\n")
# 3.2 Read the frequency and power
self.anritsu_con_socket.send(b":FETCh:PEAK?\n")
rsp = self.anritsu_con_socket.recv(4096)
freq, pwr = rsp.decode().split(',')
else:
raise Exception("Error: Method not supported.")
# 4. Resume the measurement collection
self.anritsu_con_socket.send(b"INIT:CONT ON\n")
#print(f"Max power {float(pwr):.2f} dBm at {float(freq)*1e-9:.3f} GHz")
return {'MAG': float(pwr), 'MAG_UNITS': 'dBm', 'FREQ': float(freq), 'FREQ_UNITS': 'Hz'}
def spectrum_analyzer_close(self):
"""
Closes the socket.
"""
self.anritsu_con_socket.close()
|
__init__(is_debug=True, is_config=True)
Initializes attributes of this class.
Parameters:
| Name |
Type |
Description |
Default |
is_debug |
bool
|
print debug messages. Defaults to True.
|
True
|
is_config |
bool
|
true if you want to configure the Spectrum Analyzer. Defaults to True.
|
True
|
Source code in a2gmeasurements.py
| def __init__(self, is_debug=True, is_config=True):
"""
Initializes attributes of this class.
Args:
is_debug (bool, optional): print debug messages. Defaults to True.
is_config (bool, optional): true if you want to configure the Spectrum Analyzer. Defaults to True.
"""
self.model = 'MS2760A'
self.is_debug = is_debug
self.is_config = is_config
|
retrieve_max_pow(method=2)
Retrieves the maximum power and its correspondent frequency of the spectrum of the system under test.
Parameters:
| Name |
Type |
Description |
Default |
method |
int
|
how to get the maximum peak and corresponding frequency. This is for developer. It is indisctintive for user. Defaults to 2.
|
2
|
Raises:
| Type |
Description |
Exception
|
when method is outside of available methods to compute the peak and corresponding frequency.
|
Returns:
| Name | Type |
Description |
Dictionary |
dict
|
dictionary with self-explanatory keys 'MAG', 'MAG_UNITS', 'FREQ', 'FREQ_UNITS'.
|
Source code in a2gmeasurements.py
| def retrieve_max_pow(self, method=2):
"""
Retrieves the maximum power and its correspondent frequency of the spectrum of the system under test.
Args:
method (int, optional): how to get the maximum peak and corresponding frequency. This is for developer. It is indisctintive for user. Defaults to 2.
Raises:
Exception: when method is outside of available methods to compute the peak and corresponding frequency.
Returns:
Dictionary (dict): dictionary with self-explanatory keys 'MAG', 'MAG_UNITS', 'FREQ', 'FREQ_UNITS'.
"""
# Read the ID of the Spectrum Analyzer.
if self.is_debug:
self.anritsu_con_socket.send(b"*IDN?\n")
self.anritsu_con_socket.settimeout(20)
rsp = self.anritsu_con_socket.recv(1024)
self.model = rsp.decode()
# Configure the Spectrum Analyzer
if self.is_config:
self.anritsu_con_socket.send(b"SENS:FREQ:START 59.95 GHz\n")
self.anritsu_con_socket.send(b"SENS:FREQ:STOP 60.05 GHz\n")
self.anritsu_con_socket.send(b"BAND:RES 200 KHz\n")
self.anritsu_con_socket.send(b":DISPLAY:POINTCOUNT 101\n")
self.anritsu_con_socket.send(b":CALCulate:MARKer1:STATe 1\n")
# Find the maximum power
# 1. Pause the measurement collection
self.anritsu_con_socket.send(b"INIT:CONT OFF\n")
if method == 1:
# 2.1 Place Marker 1 at maximum peak
self.anritsu_con_socket.send(b":CALCulate:MARKer1:MAXimum\n")
# 2.2 Find the frequency in Hz
self.anritsu_con_socket.send(b":CALCulate:MARKer1:X?\n")
freq = self.anritsu_con_socket.recv(1024)
# 2.3 Find the maximum power in dBm
self.anritsu_con_socket.send(b":CALCulate:MARKer1:Y?\n")
pwr = self.anritsu_con_socket.recv(1024)
elif method == 2:
# 3.1 Find the maximum peak
self.anritsu_con_socket.send(b":CALCulate:PEAK:COUNt 1\n")
# 3.2 Read the frequency and power
self.anritsu_con_socket.send(b":FETCh:PEAK?\n")
rsp = self.anritsu_con_socket.recv(4096)
freq, pwr = rsp.decode().split(',')
else:
raise Exception("Error: Method not supported.")
# 4. Resume the measurement collection
self.anritsu_con_socket.send(b"INIT:CONT ON\n")
#print(f"Max power {float(pwr):.2f} dBm at {float(freq)*1e-9:.3f} GHz")
return {'MAG': float(pwr), 'MAG_UNITS': 'dBm', 'FREQ': float(freq), 'FREQ_UNITS': 'Hz'}
|
spectrum_analyzer_close()
Closes the socket.
Source code in a2gmeasurements.py
| def spectrum_analyzer_close(self):
"""
Closes the socket.
"""
self.anritsu_con_socket.close()
|
spectrum_analyzer_connect(HOST='127.0.0.1', PORT=9001)
Creates a socket to connect to the spectrum analyzer.
Parameters:
| Name |
Type |
Description |
Default |
HOST |
str
|
ip address of the spectrum analyzer. Defaults to 127.0.0.1.
|
'127.0.0.1'
|
PORT |
int
|
TCP/IP port. Defaults to 9001.
|
9001
|
Source code in a2gmeasurements.py
| def spectrum_analyzer_connect(self, HOST='127.0.0.1', PORT=9001):
"""
Creates a socket to connect to the spectrum analyzer.
Args:
HOST (str, optional): ip address of the spectrum analyzer. Defaults to ``127.0.0.1``.
PORT (int, optional): TCP/IP port. Defaults to 9001.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.anritsu_con_socket = s
self.anritsu_con_socket.connect((HOST, PORT))
|