1#!/usr/bin/env python3 2# 3# Copyright 2019 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Python module for Rohde & Schwarz SMBV100 Vector Signal Generator.""" 17 18import numbers 19from acts.controllers import abstract_inst 20 21 22class SMBV100Error(abstract_inst.SocketInstrumentError): 23 """SMBV100 Instrument Error Class.""" 24 25 26class SMBV100(abstract_inst.SocketInstrument): 27 """SMBV100 Class, inherted from abstract_inst SocketInstrument.""" 28 29 def __init__(self, ip_addr, ip_port): 30 """Init method for SMBV100. 31 32 Args: 33 ip_addr: IP Address. 34 Type, str. 35 ip_port: TCPIP Port. 36 Type, str. 37 """ 38 super(SMBV100, self).__init__(ip_addr, ip_port) 39 40 self.idn = '' 41 42 def connect(self): 43 """Init and Connect to SMBV100.""" 44 self._connect_socket() 45 46 self.get_idn() 47 48 infmsg = 'Connected to SMBV100, with ID: {}'.format(self.idn) 49 self._logger.debug(infmsg) 50 51 def close(self): 52 """Close SMBV100.""" 53 self._close_socket() 54 55 self._logger.debug('Closed connection to SMBV100') 56 57 def get_idn(self): 58 """Get the Idenification of SMBV100. 59 60 Returns: 61 SMBV100 Identifier 62 """ 63 self.idn = self._query('*IDN?') 64 65 return self.idn 66 67 def preset(self): 68 """Preset SMBV100 to default status.""" 69 self._send('*RST') 70 71 self._logger.debug('Preset SMBV100') 72 73 def set_rfout_state(self, state): 74 """set SMBV100 RF output state. 75 76 Args: 77 state: RF output state. 78 Type, str. Option, ON/OFF. 79 80 Raises: 81 SMBV100Error: raise when state is not ON/OFF. 82 """ 83 84 if state not in ['ON', 'OFF']: 85 raise SMBV100Error(error='"state" input must be "ON" or "OFF"', 86 command='set_rfout') 87 88 self._send(':OUTP ' + state) 89 90 infmsg = 'set SMBV100 RF output to "{}"'.format(state) 91 self._logger.debug(infmsg) 92 93 def set_rfout_freq(self, freq): 94 """set SMBV100 RF output frequency. 95 96 Args: 97 freq: RF output frequency. 98 Type, num. 99 100 Raises: 101 SMBV100Error: raise when 'freq' is not numerical value. 102 """ 103 104 if not isinstance(freq, numbers.Number): 105 raise SMBV100Error(error='"freq" input must be numerical value', 106 command='set_rfoutfreq') 107 108 self._send(':SOUR:FREQ:CW ' + str(freq)) 109 110 infmsg = 'set SMBV100 RF output frequency to {} Hz'.format(freq) 111 self._logger.debug(infmsg) 112 113 def get_rfout_freq(self): 114 """get SMBV100 RF output frequency. 115 116 Return: 117 freq: RF output frequency. 118 Type, num. 119 """ 120 resp = self._query(':SOUR:FREQ:CW?') 121 122 freq = float(resp.split(';')[0]) 123 124 infmsg = 'get SMBV100 RF output frequency as {} Hz'.format(freq) 125 self._logger.debug(infmsg) 126 127 return freq 128 129 def set_rfout_level(self, level): 130 """set SMBV100 RF output level. 131 132 Args: 133 level: RF Level. 134 Type, num. 135 136 Raises: 137 SMBV100Error: raise when 'level' is not numerical value. 138 """ 139 140 if not isinstance(level, numbers.Number): 141 raise SMBV100Error(error='"level" input must be numerical value', 142 command='set_rflevel') 143 144 self._send(':SOUR:POW:LEV:IMM:AMPL ' + str(level)) 145 146 infmsg = 'set SMBV100 RF level to {} dBm'.format(level) 147 self._logger.debug(infmsg) 148 149 def get_rfout_level(self): 150 """get SMBV100 RF out level. 151 152 Return: 153 level: RF Level. 154 Type, num. 155 """ 156 resp = self._query(':SOUR:POW:LEV:IMM:AMPL?') 157 158 level = float(resp.split(';')[0]) 159 160 infmsg = 'get SMBV100 RF level as {} dBm'.format(level) 161 self._logger.debug(infmsg) 162 163 return level 164