From 7b040ee12841e721953a1f737297586135c0c110 Mon Sep 17 00:00:00 2001 From: mclim-rsa25545 Date: Sun, 7 Jul 2024 21:03:25 -0700 Subject: [PATCH] 2024.07.07 refactoring for flake8 --- .flake8 | 86 ++----- rssd/examples/OSP_Debug.py | 60 ++--- rssd/examples/PNA_LockPower.py | 46 ++-- rssd/examples/RCT/CMP_NR5G_EVM.py | 88 +++---- rssd/examples/RCT/CMP_VSG_Arb_5GNR_Sweep.py | 71 +++-- rssd/examples/RCT/CMW_GPRF_Loopback.py | 45 ++-- rssd/examples/VSG_SCPIWaveform.py | 48 ++-- rssd/examples/VST_5GNR_50PUCCH_FSW.py | 24 +- rssd/examples/VST_5GNR_50PUCCH_SMW.py | 23 +- rssd/examples/VST_5GNR_RxSettings.py | 45 ++-- rssd/examples/VST_LTE_EVM.py | 59 ++--- rssd/examples/VST_NR5G_CA_Config.py | 25 +- rssd/examples/VST_NR5G_CA_EVM_Single.py | 14 +- rssd/examples/VST_NR5G_EVM.py | 72 +++--- rssd/examples/VST_NR5G_K144_Read.py | 21 +- rssd/examples/VST_NR5G_K144_Set.py | 40 +-- rssd/examples/VST_Sweep.py | 32 +-- rssd/examples/VST_WLAN_All.py | 76 +++--- rssd/examples/VST_WLAN_EVM.py | 50 ++-- rssd/examples/misc/00_IDN.py | 52 ++-- rssd/examples/misc/FSW_cal.py | 27 +- rssd/examples/misc/RSATE_GUI.py | 152 +++++------ rssd/examples/misc/Simple_Socket.py | 4 +- rssd/examples/misc/Simple_Socket_FSW.py | 2 +- .../misc/Simple_Socket_SCPI_Player.py | 19 +- rssd/examples/misc/Simple_Socket_SMWy.py | 12 +- rssd/examples/misc/Simple_VISA.py | 14 +- rssd/examples/misc/VISA_SCPI_Player.py | 14 +- rssd/examples/misc/XMLParse.py | 33 ++- rssd/examples/misc/parseRSI.py | 61 ++--- rssd/examples/misc/pythonBasics.py | 4 +- rssd/examples/misc/syst_dfpr_parse.py | 10 +- rssd/examples/misc/timeTest.py | 14 +- rssd/instrument.py | 44 ++-- rssd/iqdata.py | 120 ++++----- rssd/test/FileIO.py | 30 +-- rssd/yaVISA.py | 122 ++++----- rssd/yaVISA_GUI.py | 242 +++++++++--------- rssd/yaVISA_socket.py | 102 ++++---- test/test_HW_OTA_ATS1000.py | 2 +- 40 files changed, 918 insertions(+), 1087 deletions(-) diff --git a/.flake8 b/.flake8 index f9edf52..f43318e 100644 --- a/.flake8 +++ b/.flake8 @@ -6,71 +6,25 @@ [flake8] # Disabled: -# C0103 Variable name "CF" doesn't conform to snake_case naming styl -# C0114 Missing module docstring -# C0115 Missing class docstring -# C0116 Missing function or method docstring -# C0301 Line too long -# C0303: Trailing whitespace -# C0321 More than one statement on a single line -# C0325 Unnecessary parens after 'if' keyword (superfluous-parens) -# C0326 Exactly one space required around assignment -# C0411 Import order -# C0413 Import should be placed at the top -# E0102 class already defined line -# E116 unexpected indentation (comment) VSCODE comments -# E127 continuation line over-indented for visual indent -# E203 whitespace before ':' -# E221 multiple spaces before operator -# E222 multiple spaces after operator -# E226 missing whitespace around arithmetic operator -# E225 missing whitespace around operator -# E241 multiple spaces after ',' -# E251 unexpected spaces around keyword / parameter equals -# E266 too many leading '#' for block comment -# E271 multiple spaces after keyword -# E272 multiple spaces bfore keyword -# E305 expected 2 blank lines after class or function definition, found 1 -# E401 Import Error -# E502 the backslash is redundant between brackets -# E0611 no-name-in-module -# E701 multiple statements on one line (colon) -# E704 multiple statements on one line (def) -# E1101 Instance of '' has no 'Init' member -# F541 f-string is missing placeholders -# R0801 Similar lines in 3 files -# R0902 too-many-instance-attributes -# R0903 too-few-public-methods -# W0612 Unused variable -# W0621 Redefining name '' from outer scope -# W0702 No exception type(s) specified (bare-except) -# W1309 Using an f-string that does not have any interpolated variables -# -### Work On Later -# R0201 Method could be a function -# R0205 Class 'FileIO' inherits from object -# R0904 Too many public methods (%s/%s) -# R1714 Consider merging these comparisons with "in" to -# W0201 Attribute %r defined outside __init__ -# W0235 Useless super delegation in method '__init__' -# W293 blank line contains whitespace -# E115 expected an indented block (comment) -# E228 missing whitespace around modulo operator -# E231 missing whitespace after ',' -# E262 inline comment should start with '# ' -# E265 block comment should start with '# ' -# E402 module level import not at top of file -# E501 line too long (100 > 79 characters) -# E502 the backslash is redundant between brackets -# E722 do not use bare 'except' -# F401 '' imported but unused -# F841 local variable 'y' is assigned to but never used -ignore=C103, C114, C115, C116, C301, C303, C321, C325, C326, C411, C413, - E102, E116, E127, E203, E221, E222, E225, E226, E241, E251, E266, E271, E272, E302, E305, E401, E502, E611, E701, E704, E731, - F541, - R801, R902, R0903, - W621, W702, W1309, W612, W201, W235, W291, - R201, R205, R904, R1714, R1725, - E115, E228, E231, E265, E262, E402, E501, E502, E722, F401, F841, W293 +# E116 unexpected indentation (comment) +# E203 whitespace before ':' +# E221 multiple spaces before operator +# E228 missing whitespace around modulo operator +# E241 multiple spaces after ',' +# E261 at least two spaces before inline comment +# E271 multipe spaces after keyword +# E272 Multiple spaces before keyword +# E302 expected 2 blank lines, found 1 +# E305 expected 2 blank lines after class or function definition, found 1 +# E402 module level import not at top of file +# E501 line too long (85 > 79 characters) +# E502 the backslash is redundant between brackets +# E701 multiple statements on one line(colon) +# E722 do no use bare 'except' +# E731 do not assign a lambda expression, use a def +# F541 f-string is missing placeholders +# F841 local variable 'DataFile' is assigned to but never used + +ignore= E116, E203, E221, E228, E241, E261, E271, E272, E302, E305, E402, E501, E502, E701, E722, E731, F541, F841 diff --git a/rssd/examples/OSP_Debug.py b/rssd/examples/OSP_Debug.py index e92de65..774294b 100644 --- a/rssd/examples/OSP_Debug.py +++ b/rssd/examples/OSP_Debug.py @@ -1,43 +1,43 @@ ######################################################################## -### Rohde & Schwarz Automation for demonstration use. +# ## Rohde & Schwarz Automation for demonstration use. ### -### Purpose: OSP Switch Matrix Example -### Author: mclim -### Date: 2018.09.09 -### -### Rack3 Switch Configuration -### ================================================================ -### K10:A11-01:A11-P0 K50:A11-55:A11-P10-K1 K70:A11-49:A11-P09-K1 -### K11:A11-14:A11-P0 K51:A11-56:A11-P10-K2 K71:A11-67:A11-P12 -### K12:A11-26:A11-P0 K52:A11-43:A11-P08-K1 K72:A11-50:A11-P09-K2 -### K13:A11-15:A11-P0 K53:A11-44:A11-P08-K2 K73:A11-61:A11-P11 -### K14:A11-27:A11-P0 K74:A12-49:A12-P09 -### K15:A11-13:A11-P0 K75:A12-37:A12-P07-K1 -### K16:A11-25:A11-P0 K76:A12-67:A12-P12 -### K17:A11-02:A11-P0 K77:A12-55:A12-P10 -### K18:A11-03:A11-P0 K78:A12-61:A12-P11 +# ## Purpose: OSP Switch Matrix Example +# ## Author: mclim +# ## Date: 2018.09.09 ### +# ## Rack3 Switch Configuration +# ## ================================================================ +# ## K10:A11-01:A11-P0 K50:A11-55:A11-P10-K1 K70:A11-49:A11-P09-K1 +# ## K11:A11-14:A11-P0 K51:A11-56:A11-P10-K2 K71:A11-67:A11-P12 +# ## K12:A11-26:A11-P0 K52:A11-43:A11-P08-K1 K72:A11-50:A11-P09-K2 +# ## K13:A11-15:A11-P0 K53:A11-44:A11-P08-K2 K73:A11-61:A11-P11 +# ## K14:A11-27:A11-P0 K74:A12-49:A12-P09 +# ## K15:A11-13:A11-P0 K75:A12-37:A12-P07-K1 +# ## K16:A11-25:A11-P0 K76:A12-67:A12-P12 +# ## K17:A11-02:A11-P0 K77:A12-55:A12-P10 +# ## K18:A11-03:A11-P0 K78:A12-61:A12-P11 + ######################################################################## -### User Entry +# ## User Entry ######################################################################## -OSP_IP = '192.168.1.150' #IP Address -RF1ThruSA = [[12,67,3],[12,49,1],[11,61,1],[11,67,2],[11,49,1]] #K76(RF1)-K74-K73(Thru)K71-K70 -RF1HP5GSA = [[12,67,3],[12,49,1],[11,61,2],[11,67,1],[11,49,1]] #K76(RF1)-K74-K73(HP5G)K71-K70 -RF1LNASA = [[12,67,3],[12,49,1],[11,61,5],[11,67,3],[11,49,1]] #K76(RF1)-K74-K73(LNA)K71-K70 -IFHtoSA = [[11,43,0],[11,56,0],[11,55,1],[11,67,5],[11,49,1]] #K52-K51-K50(Thru)K71-K70 -IFHtoSA = [[11,43,0],[11,56,0],[11,55,0],[11,67,6],[11,49,1]] #K52-K51-K50(HP5G)K71-K70 -IFVtoSA = [[11,44,0],[11,56,1],[11,55,1],[11,67,5],[11,49,1]] #K53-K51-K50(Thru)K71-K70 -RF21Noise = [[12,37,0],[12,49,2],[11,61,4]] #K75-K74-K73 -RF1toRF21 = [[12,67,3],[12,49,1],[11,61,1],[12,37,0]] #K76(RF1)-K74-K73-75(RF21) +OSP_IP = '192.168.1.150' # IP Address +RF1ThruSA = [[12, 67, 3], [12, 49, 1], [11, 61, 1], [11, 67, 2], [11, 49, 1]] # K76(RF1)-K74-K73(Thru)K71-K70 +RF1HP5GSA = [[12, 67, 3], [12, 49, 1], [11, 61, 2], [11, 67, 1], [11, 49, 1]] # K76(RF1)-K74-K73(HP5G)K71-K70 +RF1LNASA = [[12, 67, 3], [12, 49, 1], [11, 61, 5], [11, 67, 3], [11, 49, 1]] # K76(RF1)-K74-K73(LNA)K71-K70 +IFHtoSA = [[11, 43, 0], [11, 56, 0], [11, 55, 1], [11, 67, 5], [11, 49, 1]] # K52-K51-K50(Thru)K71-K70 +IFHtoSA = [[11, 43, 0], [11, 56, 0], [11, 55, 0], [11, 67, 6], [11, 49, 1]] # K52-K51-K50(HP5G)K71-K70 +IFVtoSA = [[11, 44, 0], [11, 56, 1], [11, 55, 1], [11, 67, 5], [11, 49, 1]] # K53-K51-K50(Thru)K71-K70 +RF21Noise = [[12, 37, 0], [12, 49, 2], [11, 61, 4]] # K75-K74-K73 +RF1toRF21 = [[12, 67, 3], [12, 49, 1], [11, 61, 1], [12, 37, 0]] # K76(RF1)-K74-K73-75(RF21) Path = RF1ThruSA ######################################################################## -### Code Start +# ## Code Start ######################################################################## from rssd.OSP.Common import OSP Rack3 = OSP() Rack3.jav_openvisa('TCPIP0::192.168.1.150::INSTR') -#Rack3.Set_SW(11,49,0) +# Rack3.Set_SW(11, 49, 0) for sw in Path: - Rack3.Set_SW(sw[0],sw[1],sw[2]) -Rack3.jav_ClrErr() #Clear Errors + Rack3.Set_SW(sw[0], sw[1], sw[2]) +Rack3.jav_ClrErr() # Clear Errors diff --git a/rssd/examples/PNA_LockPower.py b/rssd/examples/PNA_LockPower.py index 4a79d32..30d9b8e 100644 --- a/rssd/examples/PNA_LockPower.py +++ b/rssd/examples/PNA_LockPower.py @@ -1,72 +1,62 @@ -########################################################## -### Rohde & Schwarz Automation for demonstration use. -### -### Title : Timing SCPI Commands Example -### Author : mclim -### Date : 2018.05.24 -### -########################################################## -### User Entry -########################################################## SMW_IP = '192.168.1.114' FSWP_IP = '192.168.1.108' -FreqArry = range(int(39.8e9),int(43e9),int(100e6)) -pwrArry = range(-20,-13,1) #Power Array +FreqArry = range(int(39.8e9), int(43e9), int(100e6)) +pwrArry = range(-20, -13, 1) # Power Array numMeas = 1 ########################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ########################################################## # import time -# from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 -from rssd.VSG.Common import VSG #pylint: disable=E0611,E0401 -from rssd.PNA.Common import PNA #pylint: disable=E0611,E0401 +# from datetime import datetime # pylint: disable=E0611, E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611, E0401 +from rssd.VSG.Common import VSG # pylint: disable=E0611, E0401 +from rssd.PNA.Common import PNA # pylint: disable=E0611, E0401 OFile = FileIO().makeFile(__file__) ########################################################## -### Code Start +# ## Code Start ########################################################## SMW = VSG().jav_Open(SMW_IP, OFile) FSWP = PNA().jav_Open(FSWP_IP, OFile) ########################################################## -### Measure Time +# ## Measure Time ########################################################## -Header = 'Iter,SetFreq,SMFPwr,FSWPFreq,FSWPPwr,LockStatus,PN1,PN2,PN3,PN4' +Header = 'Iter, SetFreq, SMFPwr, FSWPFreq, FSWPPwr, LockStatus, PN1, PN2, PN3, PN4' OFile.write(Header) FSWP.Set_SweepCont(0) SMW.Set_RFPwr(-50) SMW.Set_RFState(1) -for i in range(numMeas): #Loop: Measurements - for freq in FreqArry: #Loop: Frequency +for i in range(numMeas): # Loop: Measurements + for freq in FreqArry: # Loop: Frequency SMW.Set_Freq(freq) # FSWP.Set_Freq(freq) lockHist = [] - lockPerf = [2,0,0,0] - for pwr in pwrArry: #Loop: Power + lockPerf = [2, 0, 0, 0] + for pwr in pwrArry: # Loop: Power SMW.Set_RFPwr(pwr) FSWP.Set_InitImm() FSWP.Set_InitImm() # SMW.delay(2) lock = FSWP.Get_FreqLock() mkr = [] - for m in range(1,5): + for m in range(1, 5): mkr.append(FSWP.Get_Mkr_Y(m)) # mkr[m-1] = FSWP.Get_Mkr_Y(m) ffrq = FSWP.Get_Freq() fpwr = FSWP.Get_Power() - OutStr = f'{i},{freq},{pwr:.2f},{ffrq},{fpwr},{lock},{mkr}' + OutStr = f'{i}, {freq}, {pwr:.2f}, {ffrq}, {fpwr}, {lock}, {mkr}' OFile.write(OutStr) lockHist.append(int(lock)) - if (lockHist[-4:] == [2,0,0,0]): + if (lockHist[-4:] == [2, 0, 0, 0]): break ########################################################## -### Cleanup Automation +# ## Cleanup Automation ########################################################## SMW.jav_Close() FSWP.jav_Close() diff --git a/rssd/examples/RCT/CMP_NR5G_EVM.py b/rssd/examples/RCT/CMP_NR5G_EVM.py index 3e3ef5e..84a9255 100644 --- a/rssd/examples/RCT/CMP_NR5G_EVM.py +++ b/rssd/examples/RCT/CMP_NR5G_EVM.py @@ -1,27 +1,27 @@ ######################################################################## -### Rohde & Schwarz Automation for demonstration use. +# ## Rohde & Schwarz Automation for demonstration use. ### -### Purpose: CMP200A Example -### Author: mclim -### Date: 2019.09.09 +# ## Purpose: CMP200A Example +# ## Author: mclim +# ## Date: 2019.09.09 ######################################################################## -### User Entry +# ## User Entry ######################################################################## -CMP_IP = '192.168.1.160' #IP Address -SMW_IP = '192.168.1.114' #IP Address +CMP_IP = '192.168.1.160' # IP Address +SMW_IP = '192.168.1.114' # IP Address FreqArry = [24e9, 26e9, 28e9, 31e9, 37.50e9, 38.5e9, 44.0e9] -pwrArry = range(-50,8,2) #Power Array -# modArry = ['QAM64'] #QPSK; QAM16; QAM64; QAM256; -waveparam = [[100,120,66,'QAM64']] #ChBW, SubSp, RB +pwrArry = range(-50, 8, 2) # Power Array +# modArry = ['QAM64'] # QPSK; QAM16; QAM64; QAM256; +waveparam = [[100, 120, 66, 'QAM64']] # ChBW, SubSp, RB numMeas = 1 ######################################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ######################################################################## import math -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.RCT.NR5G_K import RCT #pylint: disable=E0611,E0401 -from rssd.VSG.NR5G_K144 import VSG #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611, E0401 +from rssd.RCT.NR5G_K import RCT # pylint: disable=E0611, E0401 +from rssd.VSG.NR5G_K144 import VSG # pylint: disable=E0611, E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611, E0401 OFile = FileIO().makeFile(__file__) class vari: @@ -34,15 +34,15 @@ def __init__(self): NR5G = vari() ######################################################################## -### Code Start +# ## Code Start ######################################################################## CMP = RCT() SMW = VSG() -CMP.jav_Open(CMP_IP,OFile) -SMW.jav_Open(SMW_IP,OFile) +CMP.jav_Open(CMP_IP, OFile) +SMW.jav_Open(SMW_IP, OFile) CMP.query('*IDN?') -CMP.write('ROUT:NRMM:MEAS:SCEN:SAL RF1C,RX1') +CMP.write('ROUT:NRMM:MEAS:SCEN:SAL RF1C, RX1') CMP.Set_5GNR_Freq(28000) CMP.Set_5GNR_ExpPwr(0) CMP.Set_5GNR_UserMargin(11.5) @@ -50,18 +50,18 @@ def __init__(self): CMP.Set_5GNR_MixerOff(0) CMP.Set_5GNR_BWP_SubSpace(120) CMP.Set_5GNR_ChannelBW(100) -CMP.Set_5GNR_PhaseComp('OFF',2.8e10) +CMP.Set_5GNR_PhaseComp('OFF', 2.8e10) CMP.Set_5GNR_Periodicity(1) -CMP.write('CONF:NRMM:MEAS:ULDL:PATT S120K,0,0,8,0') +CMP.write('CONF:NRMM:MEAS:ULDL:PATT S120K, 0, 0, 8, 0') CMP.write('CONF:NRMM:MEAS:PLC 3') -CMP.write('CONF:NRMM:MEAS:BWP BWP0,S120,NORM,MAX,0') -CMP.write('CONF:NRMM:MEAS:BWP:PUSC:DFTP BWP0,OFF') -CMP.write('CONF:NRMM:MEAS:ALL:PUSC A,14,0,66,0,Q64') +CMP.write('CONF:NRMM:MEAS:BWP BWP0, S120, NORM, MAX, 0') +CMP.write('CONF:NRMM:MEAS:BWP:PUSC:DFTP BWP0, OFF') +CMP.write('CONF:NRMM:MEAS:ALL:PUSC A, 14, 0, 66, 0, Q64') CMP.write('CONF:NRMM:MEAS:TAP 3') -CMP.write('CONF:NRMM:MEAS:BWP:PUSC:DMTA BWP0,1,0,1') -CMP.write('CONF:NRMM:MEAS:CC:ALL:PUSC:ADD 1,1,0.0,0') +CMP.write('CONF:NRMM:MEAS:BWP:PUSC:DMTA BWP0, 1, 0, 1') +CMP.write('CONF:NRMM:MEAS:CC:ALL:PUSC:ADD 1, 1, 0.0, 0') CMP.write('TRIG:NRMM:MEAS:MEV:SOUR "Free Run (Fast Sync)"') -CMP.write('CONF:NRMM:MEAS:MEV:RES:ALL ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON') +CMP.write('CONF:NRMM:MEAS:MEV:RES:ALL ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON') CMP.write('CONF:NRMM:MEAS:MEV:REP SING') CMP.write('CONF:NRMM:MEAS:MEV:SCON NONE') CMP.write('CONF:NRMM:MEAS:MEV:MMOD NORM') @@ -72,39 +72,39 @@ def __init__(self): CMP.write('CONF:NRMM:MEAS:MEV:SCO:SPEC:ACLR 1') ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String -Header = 'Iter,Model,Freq,EVM,TxPwr,PeakPwr,FreqErr,EVMdB,ChBW,UL-TP,SubSp,Mod,SMWPwr,ExpPwr,UserMargin,ExtAttn,MixerLevel,StepTime' +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String +Header = 'Iter, Model, Freq, EVM, TxPwr, PeakPwr, FreqErr, EVMdB, ChBW, UL-TP, SubSp, Mod, SMWPwr, ExpPwr, UserMargin, ExtAttn, MixerLevel, StepTime' OFile.write(Header) -for i in range(numMeas): #Loop: Repeatability - for param in waveparam: #Loop: Waveform Parameters +for i in range(numMeas): # Loop: Repeatability + for param in waveparam: # Loop: Waveform Parameters NR5G.NR_ChBW = param[0] NR5G.NR_SubSp = param[1] NR5G.NR_RB = param[2] NR5G.NR_Mod = param[3] CMP.Init_5GNR() - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency print(f'Freq:{freq:.0f} RFBW:{NR5G.NR_ChBW} SubC:{NR5G.NR_SubSp} Mod:{NR5G.NR_Mod}') SMW.Set_Freq(freq) - CMP.Set_5GNR_Freq(freq/1e6) + CMP.Set_5GNR_Freq(freq / 1e6) print(Header) - for pwr in pwrArry: #Loop: Power + for pwr in pwrArry: # Loop: Power SMW.Set_RFPwr(pwr) CMP.Set_5GNR_ExpPwr(pwr) - tick = datetime.now() #Tick + tick = datetime.now() # Tick evm = CMP.Get_5GNR_EVM() attn = CMP.Get_AmpSettings() try: - evmdB = 20 * math.log10(float(evm[0])/100) + evmdB = 20 * math.log10(float(evm[0]) / 100) except: evmdB = -9999 - s = datetime.now() - tick #Total test time - OutStr = f'{i},{CMP.Model},{freq:.0f},{evm},{evmdB:.3f},{NR5G.NR_ChBW},{NR5G.NR_TF},{NR5G.NR_SubSp},{NR5G.NR_Mod},{pwr:3d},{attn},{s.seconds:3d}.{s.microseconds:06d}' + s = datetime.now() - tick # Total test time + OutStr = f'{i}, {CMP.Model}, {freq:.0f}, {evm}, {evmdB:.3f}, {NR5G.NR_ChBW}, {NR5G.NR_TF}, {NR5G.NR_SubSp}, {NR5G.NR_Mod}, {pwr:3d}, {attn}, {s.seconds:3d}.{s.microseconds:06d}' OFile.write(OutStr) - #end PwrLoop - #end FreqLoop - #end ParamLoop -#end repeatabilityLoop -CMP.jav_ClrErr() #Clear Errors + # end PwrLoop + # end FreqLoop + # end ParamLoop +# end repeatabilityLoop +CMP.jav_ClrErr() # Clear Errors diff --git a/rssd/examples/RCT/CMP_VSG_Arb_5GNR_Sweep.py b/rssd/examples/RCT/CMP_VSG_Arb_5GNR_Sweep.py index 0367227..2fac2ae 100644 --- a/rssd/examples/RCT/CMP_VSG_Arb_5GNR_Sweep.py +++ b/rssd/examples/RCT/CMP_VSG_Arb_5GNR_Sweep.py @@ -1,29 +1,20 @@ -######################################################################## -### Rohde & Schwarz Automation for demonstration use. -### -### Purpose: CMP200A Example -### Author: mclim -### Date: 2019.09.09 -######################################################################## -### User Entry -######################################################################## -CMP_IP = '192.168.1.160' #IP Address -FSW_IP = '192.168.1.109' #IP Address -FreqArry = [6e9,10e9,14e9,20e9] -FreqArry = [24.5e9,26e9,28e9,31e9] -FreqArry = [37.5e9,38.5e9,40e9,43.4e9] -pwrArry = range(-50,8,2) #Power Array -# modArry = ['QAM64'] #QPSK; QAM16; QAM64; QAM256; -waveparam = [[100,60,132,'QPSK']] #ChBW, SubSp, RB, Modulation +CMP_IP = '192.168.1.160' # IP Address +FSW_IP = '192.168.1.109' # IP Address +FreqArry = [6e9, 10e9, 14e9, 20e9] +FreqArry = [24.5e9, 26e9, 28e9, 31e9] +FreqArry = [37.5e9, 38.5e9, 40e9, 43.4e9] +pwrArry = range(-50, 8, 2) # Power Array +# modArry = ['QAM64'] # QPSK; QAM16; QAM64; QAM256; +waveparam = [[100, 60, 132, 'QPSK']] # ChBW, SubSp, RB, Modulation numMeas = 1 ######################################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ######################################################################## # import math -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.RCT.GPRF import RCT #pylint: disable=E0611,E0401 -from rssd.VSA.NR5G_K144 import VSA #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611, E0401 +from rssd.RCT.GPRF import RCT # pylint: disable=E0611, E0401 +from rssd.VSA.NR5G_K144 import VSA # pylint: disable=E0611, E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611, E0401 OFile = FileIO().makeFile(__file__) OFile.write("") @@ -37,47 +28,47 @@ def __init__(self): NR5G = vari() ######################################################################## -### Code Start +# ## Code Start ######################################################################## CMP = RCT() FSW = VSA() -CMP.jav_Open(CMP_IP,OFile) -FSW.jav_Open(FSW_IP,OFile) +CMP.jav_Open(CMP_IP, OFile) +FSW.jav_Open(FSW_IP, OFile) CMP.query('*IDN?') FSW.write(':UNIT:EVM DB') FSW.Set_SweepCont(0) ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String -Header = 'Iter,Model,Freq,EVM,ChBW,UL-TP,SubSp,Mod,SMWPwr,Attn,Preamp,RefLvl,StepTime' +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String +Header = 'Iter, Model, Freq, EVM, ChBW, UL-TP, SubSp, Mod, SMWPwr, Attn, Preamp, RefLvl, StepTime' OFile.write(Header) -for i in range(numMeas): #Loop: Repeatability - for param in waveparam: #Loop: Waveform Parameters +for i in range(numMeas): # Loop: Repeatability + for param in waveparam: # Loop: Waveform Parameters NR5G.NR_ChBW = param[0] NR5G.NR_SubSp = param[1] NR5G.NR_RB = param[2] NR5G.NR_Mod = param[3] CMP.Init_Gen() - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency print(f'Freq:{freq:.0f} RFBW:{NR5G.NR_ChBW} SubC:{NR5G.NR_SubSp} Mod:{NR5G.NR_Mod}') FSW.Set_Freq(freq) CMP.Set_Gen_Freq(freq) print(Header) - for pwr in pwrArry: #Loop: Power + for pwr in pwrArry: # Loop: Power FSW.Set_Autolevel() CMP.Set_Gen_RFPwr(pwr) - tick = datetime.now() #Tick + tick = datetime.now() # Tick FSW.Set_InitImm() evm = FSW.Get_5GNR_EVM() attn = FSW.Get_AmpSettings() - s = datetime.now() - tick #Total test time - OutStr = f'{i},{CMP.Model},{freq:.0f},{evm},{NR5G.NR_ChBW},{NR5G.NR_TF},{NR5G.NR_SubSp},{NR5G.NR_Mod},{pwr:3d},{attn},{s.seconds:3d}.{s.microseconds:06d}' + s = datetime.now() - tick # Total test time + OutStr = f'{i}, {CMP.Model}, {freq:.0f}, {evm}, {NR5G.NR_ChBW}, {NR5G.NR_TF}, {NR5G.NR_SubSp}, {NR5G.NR_Mod}, {pwr:3d}, {attn}, {s.seconds:3d}.{s.microseconds:06d}' OFile.write(OutStr) - #end PwrLoop - #end FreqLoop - #end ParamLoop -#end repeatabilityLoop -CMP.jav_ClrErr() #Clear Errors + # end PwrLoop + # end FreqLoop + # end ParamLoop +# end repeatabilityLoop +CMP.jav_ClrErr() # Clear Errors diff --git a/rssd/examples/RCT/CMW_GPRF_Loopback.py b/rssd/examples/RCT/CMW_GPRF_Loopback.py index c7bd516..a0ca37e 100644 --- a/rssd/examples/RCT/CMW_GPRF_Loopback.py +++ b/rssd/examples/RCT/CMW_GPRF_Loopback.py @@ -1,24 +1,15 @@ -########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Purpose: Demonstrate CMW100 Gen Purpose RF Loopback -### Author: mclim -### Date: 2018.05.31 -########################################################## -### User Entry -########################################################## import os -# import tkMessageBox BaseDir = os.path.dirname(os.path.realpath(__file__)) -OutFile = BaseDir + __file__ -InpFile = BaseDir + __file__ + ".csv" +OutFile = BaseDir + __file__ +InpFile = BaseDir + __file__ + ".csv" -visa = '127.0.0.1' #Get local machine name +visa = '127.0.0.1' # Get local machine name repeat = 1 -ports = [1,2,3,4,5,6,7,8] +ports = [1, 2, 3, 4, 5, 6, 7, 8] ########################################################## -### Function Definition +# ## Function Definition ########################################################## def CMW_Set(freq, pwr): CMW.Set_Gen_RFPwr(pwr) @@ -30,7 +21,7 @@ def CMW_Set(freq, pwr): CMW.Set_VSA_RefLevl(pwr) ########################################################## -### Code Start +# ## Code Start ########################################################## from datetime import datetime from rssd.FileIO import FileIO @@ -45,15 +36,15 @@ def CMW_Set(freq, pwr): CMW.jav_Open("127.0.0.1") for port in ports: - CMW.Set_Sys_TxPortLoss(port,0) - CMW.Set_Sys_RxPortLoss(port,0) + CMW.Set_Sys_TxPortLoss(port, 0) + CMW.Set_Sys_RxPortLoss(port, 0) CMW.Init_VSG() -OFile.write('\nDate,Iter,Freq,Pwr,MPwr,Port,Time,Diff') -for r in range(0,repeat): #Repeatability Loop +OFile.write('\nDate, Iter, Freq, Pwr, MPwr, Port, Time, Diff') +for r in range(0, repeat): # Repeatability Loop print("Loop%d"%r) - for cond in IArry: #Condition Loop - for i in [2]: #Port Loop + for cond in IArry: # Condition Loop + for i in [2]: # Port Loop freq = float(cond[0]) pwr = float(cond[1]) CMW.Set_Gen_PortON(i) @@ -67,12 +58,12 @@ def CMW_Set(freq, pwr): CMW.Set_VSA_RefLevl(pwr) tock = datetime.now() MPwr = CMW.Get_ChPwr()[1] - OutStr = '%d,%d,%.3f,%.3f,%d,%s,%f'%(r,freq,pwr,MPwr,i,tock-tick,pwr-MPwr) + OutStr = '%d, %d, %.3f, %.3f, %d, %s, %f'%(r, freq, pwr, MPwr, i, tock - tick, pwr - MPwr) OFile.write(OutStr) - #CMW.Set_Gen_PortOFF(i) - #exit() - #end port loop - #end condition loop -#end repeatability loop + # CMW.Set_Gen_PortOFF(i) + # exit() + # end port loop + # end condition loop +# end repeatability loop CMW.jav_ClrErr() CMW.jav_Close() diff --git a/rssd/examples/VSG_SCPIWaveform.py b/rssd/examples/VSG_SCPIWaveform.py index fbf787c..2fc14b5 100644 --- a/rssd/examples/VSG_SCPIWaveform.py +++ b/rssd/examples/VSG_SCPIWaveform.py @@ -1,44 +1,36 @@ """IQ --> SCPI --> SMW""" SMW_IP = '192.168.1.114' -############################################################################### -### Code Overhead: Import and create objects -############################################################################### import numpy as np from rssd.VSG.Common import VSG -SMW = VSG().jav_Open(SMW_IP) #Create SMW Object +SMW = VSG().jav_Open(SMW_IP) # Create SMW Object -############################################################################### -### Code Start -############################################################################### -### :MMEM:DATA:UNPR "NVWFM://var//user//",# -### wave.wv : Name of *.wv to be created -### numSize : Number of bytes in string -### NumBytes: Number of bytes to follow -### Each I (or Q) value is two bytes -### I(2 bytes) + Q(2bytes) = 4 bytes/IQ pair -### NumBytes = NumIQPair * 4 -### -IData = [0.1,0.2,0.3] -QData = [0.4,0.5,0.6] +""":MMEM:DATA:UNPR "NVWFM://var//user//",# + wave.wv : Name of *.wv to be created + numSize : Number of bytes in string + NumBytes: Number of bytes to follow + Each I (or Q) value is two bytes + I(2 bytes) + Q(2bytes) = 4 bytes/IQ pair + NumBytes = NumIQPair * 4 +""" -### ASCII -scpi = ':MMEM:DATA:UNPR "NVWFM://var//user//test.wv",#' # Define file & number of bytes -iqsize= str(len(IData)*4) # Calculate bytes of IQ data -scpi = scpi + str(len(iqsize)) + iqsize # Calculate length of iqsize string +IData = [0.1, 0.2, 0.3] +QData = [0.4, 0.5, 0.6] -### Binary: IQ data --> Binary format -iqdata= np.vstack((IData,QData)).reshape((-1,),order='F') # Combine I&Q Data -bits = np.array(iqdata*32767, dtype='>i2') # Convert to big-endian 2byte int +# -- ASCII +scpi = ':MMEM:DATA:UNPR "NVWFM://var//user//test.wv",#' # Define file & number of bytes +iqsize = str(len(IData) * 4) # Calculate bytes of IQ data +scpi = scpi + str(len(iqsize)) + iqsize # Calculate length of iqsize string -### ASCII + Binary +# -- Binary: IQ data --> Binary format +iqdata = np.vstack((IData, QData)).reshape((-1,), order='F') # Combine I&Q Data +bits = np.array(iqdata * 32767, dtype='>i2') # Convert to big-endian 2byte int + +# -- ASCII + Binary cmd = bytes(scpi, 'utf-8') + bits.tostring() # Add ASCII + Bin SMW.K2.write_raw(cmd) SMW.write('SOUR1:BB:ARB:WAV:CLOC "/var/user/test.wv",1.234E6') # Set Fs/Clk Rate SMW.write('BB:ARB:WAV:SEL "/var/user/test.wv"') # Select Arb File print(SMW.query('SYST:ERR?')) -############################################################################### -### Close Nicely -############################################################################### SMW.jav_Close() diff --git a/rssd/examples/VST_5GNR_50PUCCH_FSW.py b/rssd/examples/VST_5GNR_50PUCCH_FSW.py index aaeabca..56c40ad 100644 --- a/rssd/examples/VST_5GNR_50PUCCH_FSW.py +++ b/rssd/examples/VST_5GNR_50PUCCH_FSW.py @@ -1,20 +1,10 @@ -############################################################################### -### Rohde & Schwarz Automation for demonstration use. -#pylint: disable=E0611,E0401 -############################################################################### FSW_IP = '192.168.58.109' -############################################################################### -### Overhead -############################################################################### from rssd.VSA.NR5G_K144 import VSA -FSW = VSA().jav_Open(FSW_IP) #Create FSW Object +FSW = VSA().jav_Open(FSW_IP) # Create FSW Object FSW.debug = 0 -############################################################################### -### Code Start -############################################################################### FSW.Set_Freq(3.5e9) FSW.Init_5GNR() FSW.Set_5GNR_FrameCount('OFF') @@ -26,8 +16,8 @@ FSW.write(f'CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:UCCC 50') # PUCCH Allocation FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:CSL 1') # User configurable slots, rest copy -for ch in range(0,44): - ## Frame Configuration +for ch in range(0, 44): + # Frame Configuration FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:FORM 0') # Format FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:RBC 1') # Number of RB FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:RBOF {ch}') # RB Offset @@ -35,22 +25,22 @@ FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:SOFF 12') # Symbol Offset # FSW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:REP SLOT') # Repitition - ## PUCCH Setting + # PUCCH Setting FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:ISFH ON') # Intra Slot Freq Hop FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:HID NID') # Hop ID type FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:NID {ch * 2}') # Hop ID num FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:SHPR {272-ch}') # 2nd Hop PBR FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:ICSH 6') # Initial Cyclic Shift -for ch in range(44,50): - ## Frame Configuration +for ch in range(44, 50): + # Frame Configuration FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:FORM 2') # Format FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:RBC 1') # Number of RB FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:RBOF {ch}') # RB Offset FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:SCO 2') # Number of Symbol FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:SOFF 0') # Symbol Offset - ## PUCCH Setting + # PUCCH Setting # FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:ISFH OFF') # Intra Slot Freq Hop # FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:HID NID') # Hop ID type # FSW.write(f':CONF:NR5G:UL:CC1:FRAM1:BWP0:SLOT0:PUCC{ch}:DMRS:NID {ch * 2}') # Hop ID num diff --git a/rssd/examples/VST_5GNR_50PUCCH_SMW.py b/rssd/examples/VST_5GNR_50PUCCH_SMW.py index 77023db..7497579 100644 --- a/rssd/examples/VST_5GNR_50PUCCH_SMW.py +++ b/rssd/examples/VST_5GNR_50PUCCH_SMW.py @@ -1,20 +1,13 @@ -############################################################################### -### Rohde & Schwarz Automation for demonstration use. -#pylint: disable=E0611,E0401 -############################################################################### SMW_IP = '192.168.58.114' freqArry = [28e9] -############################################################################### -### Overhead -############################################################################### from rssd.VSG.NR5G_K144 import VSG -SMW = VSG().jav_Open(SMW_IP) #Create SMW Object +SMW = VSG().jav_Open(SMW_IP) # Create SMW Object SMW.debug = 0 ############################################################################### -### Code Start +# ## Code Start ############################################################################### SMW.Set_Freq(3.5e9) SMW.Set_5GNR_BBState('OFF') @@ -25,8 +18,8 @@ SMW.Set_5GNR_ChannelBW(100) SMW.Set_5GNR_BWP_Users(50) -for ch in range(0,44): - ## Frame Configuration +for ch in range(0, 44): + # Frame Configuration SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:NALL 1') # Add User SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:CONT PUCC') # Select PUCCH SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:FMT F0') # Format @@ -36,15 +29,15 @@ SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:SYM 12') # Symbol offset SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:REP SLOT') # Repitition - ## PUCCH Setting + # PUCCH Setting SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:ISFH 1') # Intra Slot Freq Hop SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:HOP {ch * 2}') # Hop ID SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:SHOP {272-ch}') # 2nd Hop PBR SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:FS:CYCS 6') # Initial Cyclic Shift RBSize = 1 -for ch in range(44,50): - ## Frame Configuration +for ch in range(44, 50): + # Frame Configuration SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:NALL 1') # Add User SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:CONT PUCC') # Select PUCCH SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:FMT F2') # Format @@ -54,7 +47,7 @@ SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:SYM 0') # Symbol offset SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:REP SLOT') # Repitition - ## PUCCH Setting + # PUCCH Setting SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:ISFH 1') # Intra Slot Freq Hop # SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:HOP {ch * 2}') # Hop ID SMW.write(f':SOUR1:BB:NR5G:SCH:CELL0:SUBF0:USER{ch}:BWP0:ALL0:PUCC:SHOP {272-ch}') # 2nd Hop PBR diff --git a/rssd/examples/VST_5GNR_RxSettings.py b/rssd/examples/VST_5GNR_RxSettings.py index 86d8973..2fc57ca 100644 --- a/rssd/examples/VST_5GNR_RxSettings.py +++ b/rssd/examples/VST_5GNR_RxSettings.py @@ -1,18 +1,11 @@ -############################################################################### -### Rohde & Schwarz Automation for demonstration use. -### Capture EVM based on SMW *.nr5G & FSW *.allocation files -#pylint: disable=E0611,E0401 -############################################################################### +# pylint: disable=E0611,E0401 SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' UserDir = '2020.07.30-Autolevel' freqArry = [28e9] -pwrArry = range(-50,10,2) #Power Array +pwrArry = range(-50, 10, 2) # Power Array comment = '-Autolevel' -############################################################################### -### Overhead -############################################################################### from rssd.VSG.NR5G_K144 import VSG from rssd.VSA.NR5G_K144 import VSA from rssd.FileIO import FileIO @@ -20,26 +13,26 @@ OFile = FileIO().makeFile(__file__) TMR = timer() -SMW = VSG().jav_Open(SMW_IP,OFile) #Create SMW Object +SMW = VSG().jav_Open(SMW_IP, OFile) # Create SMW Object SMW.debug = 0 -FSW = VSA().jav_Open(FSW_IP,OFile) #Create FSW Object +FSW = VSA().jav_Open(FSW_IP, OFile) # Create FSW Object FSW.debug = 0 class dataClass(): def __init__(self): -# self.Direction = 'UL' -# self.CellID = 1 -# # self.FreqRng = 'HIGH' -# self.ChBW = 100 -# self.TF = 'ON' -# self.SubSp = 120 -# self.RB = 60 -# self.RBO = 0 -# self.Ch_RB = 60 -# self.Ch_RBO = 0 -# self.Mod = 'QPSK' + # self.Direction = 'UL' + # self.CellID = 1 + # # self.FreqRng = 'HIGH' + # self.ChBW = 100 + # self.TF = 'ON' + # self.SubSp = 120 + # self.RB = 60 + # self.RBO = 0 + # self.Ch_RB = 60 + # self.Ch_RBO = 0 + # self.Mod = 'QPSK' self.Rx = '' -# self.pwr = -100 + # self.pwr = -100 def NR5G_Rx_Init(): """Start 5GNR Measurement Channel""" @@ -71,7 +64,7 @@ def NR5G_Rx_Get_EVM(): return EVM ############################################################################### -### Code Start +# ## Code Start ############################################################################### LoopParam = 'State,Model,SMW_Fre,SMW_Pwr' # WaveParam = 'ChBW,SubSp,RB,Mod,TF' @@ -81,7 +74,7 @@ def NR5G_Rx_Get_EVM(): Header = f'{LoopParam},{AttnParam},{EVMParam},{TimeParam}' OFile.write(Header) -### Instr Init +# ## Instr Init NR5G = dataClass() SMW.Set_OS_Dir(UserDir) SMW.Set_5GNR_BBState(1) @@ -110,7 +103,7 @@ def NR5G_Rx_Get_EVM(): EVM = NR5G_Rx_Get_EVM() TMR.tick() - ### Log Data + # ## Log Data LoopParam = f'{saveState},{NR5G.Rx},{freq},{pwr:3d}' AttnParam = FSW.Get_Params_Amp() TimeParam = TMR.Get_Params_Time() diff --git a/rssd/examples/VST_LTE_EVM.py b/rssd/examples/VST_LTE_EVM.py index dc2abe9..ec829a6 100644 --- a/rssd/examples/VST_LTE_EVM.py +++ b/rssd/examples/VST_LTE_EVM.py @@ -1,46 +1,35 @@ -########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Title : Timing SCPI Commands Example -### Author : mclim -### Date : 2018.05.24 -########################################################## -### User Entry -########################################################## SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' FreqArry = [6e9] -pwrArry = range(-50,8,1) +pwrArry = range(-50, 8, 1) LTE_Dir = 'UL' -waveparam =[[20,100], - [20,66]] +waveparam = [[20, 100], + [20, 66]] subFArry = [1] -modArry = ['QPSK', 'QAM64'] #QPSK; QAM16; QAM64; QAM256 +modArry = ['QPSK', 'QAM64'] # QPSK; QAM16; QAM64; QAM256 numMeas = 1 -AutoLvl = 0 #0:AutoRef 1:AutoLevel +AutoLvl = 0 # 0:AutoRef 1:AutoLevel SCFDMA = 'OFF' -########################################################## -### Code Overhead: Import and create objects -########################################################## -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 -from rssd.VST.LTE import VST #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611,E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611,E0401 +from rssd.VST.LTE import VST # pylint: disable=E0611,E0401 # import time # import ctypes # An included library with Python install OFile = FileIO().makeFile(__file__) ########################################################## -### Code Start +# ## Code Start ########################################################## -LTE = VST().jav_Open(SMW_IP,FSW_IP,OFile) +LTE = VST().jav_Open(SMW_IP, FSW_IP, OFile) LTE.LTE_TF = SCFDMA LTE.LTE_Dir = LTE_Dir LTE.Freq = FreqArry[0] ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String Header = 'Iter,Model,Freq,K144Crest,K144Pwr,EVM,ChBW,SCFDMA,RB,Mod,SMWPwr,SubFram,Attn,Preamp,RefLvl,AutoLvl,AlTime,CrestF,P10_00,P01_00,P00_10,P00_01,CmdTime,TotTime' OFile.write(Header) @@ -56,22 +45,22 @@ LTE.FSW.Set_AttnAuto() LTE.FSW.Set_SweepCont(0) -for i in range(numMeas): #Loop: Measurements - for mod in modArry: #Loop: Modulation - for param in waveparam: #Loop: Subcarrier +for i in range(numMeas): # Loop: Measurements + for mod in modArry: # Loop: Modulation + for param in waveparam: # Loop: Subcarrier LTE.LTE_ChBW = param[0] LTE.LTE_Mod = mod LTE.LTE_RB = param[1] - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency LTE.Freq = FreqArry[0] - LTE.Set_LTE_All() #[[[Make Waveform]]] + LTE.Set_LTE_All() # [[[Make Waveform]]] LTE.FSW.Init_CCDF() LTE.FSW.Set_InitImm() ccdf = LTE.FSW.Get_CCDF() print(f'Freq:{freq} RFBW:{LTE.LTE_ChBW} SubC:{LTE.LTE_RB} Mod:{LTE.LTE_Mod}') print(Header) - #ctypes.windll.user32.MessageBoxW(0, "Verify", "Please Verify Waveform", 1) - for pwr in pwrArry: #Loop: Power + # ctypes.windll.user32.MessageBoxW(0, "Verify", "Please Verify Waveform", 1) + for pwr in pwrArry: # Loop: Power LTE.SMW.Set_RFPwr(pwr) tickA = datetime.now() if AutoLvl == 1: @@ -80,8 +69,8 @@ else: LTE.FSW.Set_LTE_AutoRef() ALTime = datetime.now() - tickA - for subFram in subFArry: #Loop: Subframe - LTE.FSW.Set_LTE_SweepTime((subFram)*1.1e-3) + for subFram in subFArry: # Loop: Subframe + LTE.FSW.Set_LTE_SweepTime((subFram) * 1.1e-3) LTE.FSW.Set_LTE_SubFrameCount(subFram) tick = datetime.now() LTE.FSW.Init_LTE() @@ -89,12 +78,12 @@ LTE.FSW.Set_InitImm() EVM = LTE.FSW.Get_LTE_EVMParams() Attn = LTE.FSW.Get_AmpSettings() - d = datetime.now() - tick #Measurement only - t = datetime.now() - tickA #Autolevel + Measurement + d = datetime.now() - tick # Measurement only + t = datetime.now() - tickA # Autolevel + Measurement OutStr = f'{i},{LTE.FSW.Model},{freq},{EVM},{LTE.LTE_ChBW},{LTE.LTE_TF},{LTE.LTE_RB},{LTE.LTE_Mod},{pwr:3d},{subFram},{Attn},{AutoLvl},{ALTime.seconds:3d}.{ALTime.microseconds:06d},cf:{ccdf},{d.seconds:3d}.{d.microseconds:06d},{t.seconds:3d}.{t.microseconds:06d}' OFile.write(OutStr) ########################################################## -### Cleanup Automation +# ## Cleanup Automation ########################################################## LTE.jav_Close() diff --git a/rssd/examples/VST_NR5G_CA_Config.py b/rssd/examples/VST_NR5G_CA_Config.py index 2ac3540..733c6e3 100644 --- a/rssd/examples/VST_NR5G_CA_Config.py +++ b/rssd/examples/VST_NR5G_CA_Config.py @@ -1,9 +1,6 @@ """5G NR FSW/SMW Carrier Aggregation Setup Example""" -############################################################################### -### User Entry -############################################################################### -#pylint: disable=E0401 -#pylint: disable=E0611 +# pylint: disable=E0401 +# pylint: disable=E0611 # SMW_IP = '172.24.225.230' SMW_IP = '192.168.58.114' FSW_IP = '192.168.58.109' @@ -14,21 +11,17 @@ NR_Dir = 'UL' CCSpace = 99.96e6 modu = 'QPSK' -CCStart = (1 - NumCC) * (CCSpace/2) +CCStart = (1 - NumCC) * (CCSpace / 2) -############################################################################### -### Code Overhead: Import and create objects -############################################################################### import timeit from rssd.VSG.NR5G_K144 import VSG from rssd.VSA.NR5G_K144 import VSA -# from rssd.FileIO import FileIO -if VSG_ON: SMW = VSG().jav_Open(SMW_IP) #Create SMW Object -FSW = VSA().jav_Open(FSW_IP) #Create FSW Object +if VSG_ON: SMW = VSG().jav_Open(SMW_IP) # Create SMW Object +FSW = VSA().jav_Open(FSW_IP) # Create FSW Object ############################################################################### -### Code Start +# ## Code Start ############################################################################### if VSG_ON: SMW.Get_SysC_All() @@ -59,8 +52,8 @@ SMW.Set_5GNR_TransPrecoding('ON') # SMW.Set_5GNR_PhaseCompensate_Freq(Freq_CC) SMW.Set_5GNR_BWP_Ch_Modulation(modu) - FSW.cc = i+1 - FSW.Set_5GNR_CC_Offset(i+1,i*CCSpace) + FSW.cc = i + 1 + FSW.Set_5GNR_CC_Offset(i + 1, i * CCSpace) FSW.Set_5GNR_TransPrecoding('ON') FSW.Set_5GNR_PhaseCompensate('OFF') FSW.Set_5GNR_PhaseCompensate_Freq(Freq_CC) @@ -75,6 +68,6 @@ FSW.Set_Autolevel() ############################################################################### -### Close Nicely +# ## Close Nicely ############################################################################### if VSG_ON: SMW.jav_Close() diff --git a/rssd/examples/VST_NR5G_CA_EVM_Single.py b/rssd/examples/VST_NR5G_CA_EVM_Single.py index a31d173..dfd4e10 100644 --- a/rssd/examples/VST_NR5G_CA_EVM_Single.py +++ b/rssd/examples/VST_NR5G_CA_EVM_Single.py @@ -1,16 +1,10 @@ """5G NR Carrier Aggregation FSW/SMW Example""" -############################################################################### -### User Entry -############################################################################### SMW_IP = '192.168.58.114' FSW_IP = '192.168.58.109' NR_Dir = 'UL' VSG_ON = 0 NumCC = 8 -############################################################################### -### Code Overhead: Import and create objects -############################################################################### import os import logging from rssd.VSG.NR5G_K144 import VSG @@ -20,10 +14,10 @@ filename=os.path.splitext(__file__)[0] + '.csv', filemode='w', \ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') ############################################################################### -### Code Start +# ## Code Start ############################################################################### pwr = 100 -if VSG_ON: +if VSG_ON: SMW = VSG().jav_Open(SMW_IP) # Create SMW Object SMW.Set_5GNR_Direction(NR_Dir) @@ -31,7 +25,7 @@ FSW.Set_5GNR_Direction(NR_Dir) ############################################################################### -### Measure Time +# ## Measure Time ############################################################################### LoopParam = f'Model,CurrFreq,pwr,CC,NumCC' header = f'{LoopParam},{FSW.Get_Params_Amp(1)},{FSW.Get_5GNR_Params_EVM(1)}' @@ -39,7 +33,7 @@ evm_arry = [] FSW.Set_InitImm() for CC in range(NumCC): # LOOP: CC - FSW.cc = CC+1 + FSW.cc = CC + 1 CurrFreq = FSW.Get_5GNR_CC_Freq() LoopParam = f'{FSW.Model},{CurrFreq/1e9:9.6f},{pwr:3d},{FSW.cc},{NumCC}' AttnParam = FSW.Get_Params_Amp() diff --git a/rssd/examples/VST_NR5G_EVM.py b/rssd/examples/VST_NR5G_EVM.py index 8b298be..c11a446 100644 --- a/rssd/examples/VST_NR5G_EVM.py +++ b/rssd/examples/VST_NR5G_EVM.py @@ -1,51 +1,41 @@ -########################################################## -### Rohde & Schwarz Automation for demonstration use. -### -### Title : Timing SCPI Commands Example -### Author : mclim -### Date : 2018.05.24 -### -########################################################## -### User Entry -########################################################## SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' FreqArry = [26.55e9, 28.6e9, 29.45e9, 37.05e9, 38.5e9, 39.95e9] -pwrArry = range(-50,8,2) #Power Array +pwrArry = range(-50, 8, 2) # Power Array NR_Dir = 'UL' -waveparam = [[100,60,128]] #ChBW, SubSp, RB - # [100,120,66]] #ChBW, SubSp, RB - # [200,60,264], #ChBW, SubSp, RB - # [200,120,132], #ChBW, SubSp, RB - # [400,120,264]] #ChBW, SubSp, RB +waveparam = [[100, 60, 128]] # ChBW,SubSp, RB + # [100,120,66]] # ChBW,SubSp, RB + # [200,60,264], # ChBW,SubSp, RB + # [200,120,132], # ChBW,SubSp, RB + # [400,120,264]] # ChBW,SubSp, RB subFArry = [1] -modArry = ['QPSK','QAM64'] #QPSK; QAM16; QAM64; QAM256; PITB +modArry = ['QPSK', 'QAM64'] # QPSK; QAM16; QAM64; QAM256; PITB numMeas = 1 -AutoLvl = 1 #0:AutoEVM 1:AutoLevel +AutoLvl = 1 # 0:AutoEVM 1:AutoLevel DFT_S_OFDM = 'ON' ########################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ########################################################## # import time -# import ctypes # An included library with Python install -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 -from rssd.VST.NR5G_K144 import VST #pylint: disable=E0611,E0401 +# import ctypes # An included library with Python install +from datetime import datetime # pylint: disable=E0611,E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611,E0401 +from rssd.VST.NR5G_K144 import VST # pylint: disable=E0611,E0401 OFile = FileIO().makeFile(__file__) ########################################################## -### Code Start +# ## Code Start ########################################################## -NR5G = VST().jav_Open(SMW_IP,FSW_IP,OFile) +NR5G = VST().jav_Open(SMW_IP, FSW_IP, OFile) NR5G.NR_TF = DFT_S_OFDM NR5G.NR_Dir = NR_Dir NR5G.Freq = FreqArry[0] ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String Header = 'Iter,Model,Freq,K144Crest,K144Pwr,EVM,ChBW,Waveform,SubSp,Mod,SMWPwr,SubFram,Attn,Preamp,RefLvl,AutoLvl,AlTime,CrestF,P10_00,P01_00,P00_10,P00_01,CmdTime,StepTime' OFile.write(Header) @@ -62,47 +52,47 @@ # NR5G.FSW.Set_AttnAuto() NR5G.FSW.Set_SweepCont(0) -for i in range(numMeas): #Loop: Measurements - for mod in modArry: #Loop: Modulation - for param in waveparam: #Loop: Waveform Parameters +for i in range(numMeas): # Loop: Measurements + for mod in modArry: # Loop: Modulation + for param in waveparam: # Loop: Waveform Parameters NR5G.NR_ChBW = param[0] NR5G.NR_SubSp = param[1] NR5G.NR_RB = param[2] NR5G.NR_Mod = mod - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency NR5G.Freq = freq - NR5G.Set_5GNR_All() #[[[Make Waveform]]] + NR5G.Set_5GNR_All() # [[[Make Waveform]]] # NR5G.FSW.Init_CCDF() # NR5G.FSW.Set_InitImm() # ccdf = NR5G.FSW.Get_CCDF() ccdf = ',,,,' print(f'Freq:{freq:.0f} RFBW:{NR5G.NR_ChBW} SubC:{NR5G.NR_SubSp} Mod:{NR5G.NR_Mod}') print(Header) - #ctypes.windll.user32.MessageBoxW(0, "Verify", "Please Verify Waveform", 1) - for pwr in pwrArry: #Loop: Power + # ctypes.windll.user32.MessageBoxW(0, "Verify", "Please Verify Waveform", 1) + for pwr in pwrArry: # Loop: Power NR5G.FSW.Init_5GNR() NR5G.SMW.Set_RFPwr(pwr) - tickA = datetime.now() #TickA + tickA = datetime.now() # TickA if AutoLvl == 1: NR5G.FSW.Set_Autolevel() else: NR5G.FSW.Set_5GNR_AutoEVM() ALTime = datetime.now() - tickA - for subFram in subFArry: #Loop: Subframe - NR5G.FSW.Set_SweepTime((subFram)*1.1e-3) + for subFram in subFArry: # Loop: Subframe + NR5G.FSW.Set_SweepTime((subFram) * 1.1e-3) NR5G.FSW.Set_5GNR_SubFrameCount(subFram) - tick = datetime.now() #Tick + tick = datetime.now() # Tick NR5G.FSW.Init_5GNR() NR5G.FSW.Set_SweepCont(0) NR5G.FSW.Set_InitImm() EVM = NR5G.FSW.Get_5GNR_EVMParams() Attn = NR5G.FSW.Get_AmpSettings() - d = datetime.now() - tick #Measurement only test time - s = datetime.now() - tickA #Total test time + d = datetime.now() - tick # Measurement only test time + s = datetime.now() - tickA # Total test time OutStr = f'{i},{NR5G.FSW.Model},{freq:.0f},{EVM},{NR5G.NR_ChBW},{NR5G.NR_TF},{NR5G.NR_SubSp},{NR5G.NR_Mod},{pwr:3d},{subFram},{Attn},{AutoLvl},{ALTime.seconds:3d}.{ALTime.microseconds:06d},cf:{ccdf},{d.seconds:3d}.{d.microseconds:06d},{s.seconds:3d}.{s.microseconds:06d}' OFile.write(OutStr) ########################################################## -### Cleanup Automation +# ## Cleanup Automation ########################################################## NR5G.jav_Close() diff --git a/rssd/examples/VST_NR5G_K144_Read.py b/rssd/examples/VST_NR5G_K144_Read.py index f8aa38d..6c987ac 100644 --- a/rssd/examples/VST_NR5G_K144_Read.py +++ b/rssd/examples/VST_NR5G_K144_Read.py @@ -1,23 +1,10 @@ -########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Purpose: FSW/SMW 5G NR Demo -### Author: mclim -### Date: 2018.09.10 -### Descrip: FSW 3.20-18.7.1.0 Beta -### SMW 4.30 SP2 -########################################################## -### User Entry -########################################################## -SMW_IP = '192.168.58.114' #IP Address -FSW_IP = '192.168.58.109' #IP Address +from rssd.VST.NR5G_K144 import VST # pylint: disable=E0611,E0401 -########################################################## -### Code Start -########################################################## -from rssd.VST.NR5G_K144 import VST #pylint: disable=E0611,E0401 +SMW_IP = '192.168.58.114' # IP Address +FSW_IP = '192.168.58.109' # IP Address if __name__ == "__main__": - NR5G = VST().jav_Open(SMW_IP,FSW_IP) + NR5G = VST().jav_Open(SMW_IP, FSW_IP) NR5G.NR_CC = 1 NR5G.Get_5GNR_All_print() NR5G.jav_Clear() diff --git a/rssd/examples/VST_NR5G_K144_Set.py b/rssd/examples/VST_NR5G_K144_Set.py index 6435794..1361065 100644 --- a/rssd/examples/VST_NR5G_K144_Set.py +++ b/rssd/examples/VST_NR5G_K144_Set.py @@ -1,35 +1,35 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Purpose: FSW/SMW 5G NR Demo -### Author : mclim -### Date : 2018.07.05 -### Descrip: FSW 3.20-18.7.1.0 Beta -### SMW 4.30 SP2 +# ## Rohde & Schwarz Automation for demonstration use. +# ## Purpose: FSW/SMW 5G NR Demo +# ## Author : mclim +# ## Date : 2018.07.05 +# ## Descrip: FSW 3.20-18.7.1.0 Beta +# ## SMW 4.30 SP2 ########################################################## -### User Entry +# ## User Entry ########################################################## SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' ########################################################## -### Code Start +# ## Code Start ########################################################## -from rssd.VST.NR5G_K144 import VST #pylint: disable=E0611,E0401 +from rssd.VST.NR5G_K144 import VST # pylint: disable=E0611,E0401 -def NR5G_SetSettings(FSW,SMW): #pylint: disable=W0613 +def NR5G_SetSettings(FSW, SMW): # pylint: disable=W0613 pass if __name__ == "__main__": - NR5G = VST().jav_Open(SMW_IP,FSW_IP) - NR5G.Freq = 19e9 - NR5G.SWM_Out = 0 - NR5G.NR_Dir = 'DL' - NR5G.NR_Deploy= 'HIGH' #LOW:MIDD:HIGH - NR5G.NR_ChBW = 200 #MHz - NR5G.NR_SubSp = 120 #kHz - NR5G.NR_RB = 66 #RB - NR5G.NR_RBO = 0 #RB Offset - NR5G.NR_Mod = 'QAM64' #QPSK; QAM16; QAM64; QAM256; PITB + NR5G = VST().jav_Open(SMW_IP, FSW_IP) + NR5G.Freq = 19e9 + NR5G.SWM_Out = 0 + NR5G.NR_Dir = 'DL' + NR5G.NR_Deploy = 'HIGH' # LOW:MIDD:HIGH + NR5G.NR_ChBW = 200 # MHz + NR5G.NR_SubSp = 120 # kHz + NR5G.NR_RB = 66 # RB + NR5G.NR_RBO = 0 # RB Offset + NR5G.NR_Mod = 'QAM64' # QPSK; QAM16; QAM64; QAM256; PITB NR5G.Set_5GNR_All() NR5G.jav_Clear() NR5G.jav_Close() diff --git a/rssd/examples/VST_Sweep.py b/rssd/examples/VST_Sweep.py index b62379b..eb0829e 100644 --- a/rssd/examples/VST_Sweep.py +++ b/rssd/examples/VST_Sweep.py @@ -1,9 +1,9 @@ """Sweep FSW/SMW Frequncy""" ########################################################## -### User Entry +# ## User Entry ########################################################## -SMW_IP = '192.168.1.115' #IP Address -FSW_IP = '192.168.1.109' #IP Address +SMW_IP = '192.168.1.115' # IP Address +FSW_IP = '192.168.1.109' # IP Address FreqStart = int(24e9) FreqStop = int(40e9) FreqStep = int(1e9) @@ -12,33 +12,33 @@ Mixer = 0 ########################################################## -### Code Start +# ## Code Start ########################################################## import time from rssd.FSW_Common import VSA from rssd.SMW_Common import VSG from rssd.FileIO import FileIO -OFileCSV = FileIO().makeFile(__file__+'csv') -OFileXML = FileIO().makeFile(__file__+'xml') -SMW = VSG().jav_Open(SMW_IP,OFileCSV) #Create SMW Object -FSW = VSA().jav_Open(FSW_IP,OFileCSV) #Create FSW Object +OFileCSV = FileIO().makeFile(__file__ + 'csv') +OFileXML = FileIO().makeFile(__file__ + 'xml') +SMW = VSG().jav_Open(SMW_IP, OFileCSV) # Create SMW Object +FSW = VSA().jav_Open(FSW_IP, OFileCSV) # Create FSW Object ########################################################## -### Instrument Settings +# ## Instrument Settings ########################################################## -SMW.Set_RFPwr(SWM_Out) #Output Power -SMW.Set_RFState('ON') #Turn RF Output on +SMW.Set_RFPwr(SWM_Out) # Output Power +SMW.Set_RFState('ON') # Turn RF Output on FSW.Set_SweepCont(0) -#FSW.Set_SweepTime(200e-3) +# FSW.Set_SweepTime(200e-3) FSW.Set_Span(fSpan) -if Mixer: #Mixer +if Mixer: # Mixer FSW.write('SENS:MIX:STAT ON') FSW.write('SENS:MIX:HARM:BAND V') -for freq in range(FreqStart,FreqStop,FreqStep): +for freq in range(FreqStart, FreqStop, FreqStep): SMW.Set_Freq(freq) time.sleep(0.01) FSW.Set_Freq(freq) @@ -48,5 +48,5 @@ OFileCSV.write(f'{freq},{Mkr[0]},{Mkr[1]}') OFileXML.write(f' ') -SMW.jav_ClrErr() #Clear Errors -FSW.jav_ClrErr() #Clear Errors +SMW.jav_ClrErr() # Clear Errors +FSW.jav_ClrErr() # Clear Errors diff --git a/rssd/examples/VST_WLAN_All.py b/rssd/examples/VST_WLAN_All.py index c15039d..7de2e03 100644 --- a/rssd/examples/VST_WLAN_All.py +++ b/rssd/examples/VST_WLAN_All.py @@ -1,18 +1,18 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Title : Sample SMW FSW WLAN EVM Sweep -### Author : mclim -### Date : 2019.03.21 +# ## Rohde & Schwarz Automation for demonstration use. +# ## Title : Sample SMW FSW WLAN EVM Sweep +# ## Author : mclim +# ## Date : 2019.03.21 ########################################################## -### User Entry +# ## User Entry ########################################################## SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' -FreqArry = [2.1e9,2.2e9] +FreqArry = [2.1e9, 2.2e9] pwrArry = [-20, -10, -5] -StdArry = ['AC','N'] -CHBWArry = [20,40] -MCSArry = [1,3,5] +StdArry = ['AC', 'N'] +CHBWArry = [20, 40] +MCSArry = [1, 3, 5] SweepTime = 0.002 MeasEVM = 0 @@ -20,51 +20,51 @@ MeasSEM = 1 ########################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ########################################################## # import time -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 -from rssd.VST_WLAN import VST #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611, E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611, E0401 +from rssd.VST_WLAN import VST # pylint: disable=E0611, E0401 OFile = FileIO().makeFile(__file__) ########################################################## -### Code Start +# ## Code Start ########################################################## -WLAN = VST().jav_Open(SMW_IP,FSW_IP,OFile) +WLAN = VST().jav_Open(SMW_IP, FSW_IP, OFile) ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String -OFile.write('Freq,SMWPwr,ALTime,Std,ChBW,MCS,Attn,Preamp,RefLvl,MeasPwr,EVM,SEM,TxCh,Adj-,Adj+,Alt1-,Alt1+,Alt2-,Alt2+,CmdTime') # All +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") # Date String +OFile.write('Freq, SMWPwr, ALTime, Std, ChBW, MCS, Attn, Preamp, RefLvl, MeasPwr, EVM, SEM, TxCh, Adj-, Adj+, Alt1-, Alt1+, Alt2-, Alt2+, CmdTime') # All WLAN.FSW.jav_Reset() WLAN.FSW.Init_WLAN() WLAN.FSW.Set_Trig1_Source('EXT') WLAN.FSW.Set_SweepCont(0) -for std in StdArry: #Loop: Standard - for chbw in CHBWArry: #Loop: Ch Bandwidth - for MCS in MCSArry: #Loop: Modulation +for std in StdArry: # Loop: Standard + for chbw in CHBWArry: # Loop: Ch Bandwidth + for MCS in MCSArry: # Loop: Modulation WLAN.WLAN_Std = std WLAN.WLAN_MCS = MCS WLAN.WLAN_ChBW = chbw - WLAN.Set_WLAN_All() ### Make Waveform ### + WLAN.Set_WLAN_All() # ## Make Waveform ### print(f'802.11{std} RFBW:{WLAN.WLAN_ChBW} MCS:{MCS}') WLAN.FSW.Set_SweepTime(SweepTime) WLAN.FSW.write(':TRAC:IQ:SRAT 160e6') - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency WLAN.FSW.Set_Freq(freq) WLAN.SMW.Set_Freq(freq) - for pwr in pwrArry: #Loop: Power + for pwr in pwrArry: # Loop: Power WLAN.SMW.Set_RFPwr(pwr) - ### Autolevel Timing + # ## Autolevel Timing tick = datetime.now() - WLAN.FSW.write(':CONF:BURS:IQ:IMM') #EVM - WLAN.FSW.write(':SENS:DEM:FORM:BCON:AUTO 1') #Auto PPDU Demod + WLAN.FSW.write(':CONF:BURS:IQ:IMM') # EVM + WLAN.FSW.write(':SENS:DEM:FORM:BCON:AUTO 1') # Auto PPDU Demod WLAN.FSW.Set_WLAN_Autolvl() Attn = WLAN.FSW.Get_AmpSettings() WLAN.FSW.Set_SweepCont(0) @@ -72,36 +72,36 @@ tick = datetime.now() WLAN.FSW.Set_InitImm() - ### Measure EVM + # ## Measure EVM if MeasEVM: WLAN.FSW.Set_InitImm() - WLAN.FSW.write(':CONF:BURS:IQ:IMM') #EVM - WLAN.FSW.write(':SENS:DEM:FORM:BCON:AUTO 1') #Auto PPDU Demod + WLAN.FSW.write(':CONF:BURS:IQ:IMM') # EVM + WLAN.FSW.write(':SENS:DEM:FORM:BCON:AUTO 1') # Auto PPDU Demod WLAN.FSW.Set_InitImm() EVM = WLAN.FSW.Get_WLAN_EVMParams() else: - EVM = '-9999,-9999' - ### Measure ACLR + EVM = '-9999, -9999' + # ## Measure ACLR if MeasACLR: - WLAN.FSW.write(':CONF:BURS:SPEC:ACPR:IMM') #Config ACLR Ch + WLAN.FSW.write(':CONF:BURS:SPEC:ACPR:IMM') # Config ACLR Ch WLAN.FSW.Set_InitImm() WLAN.FSW.Set_InitImm() ACLR = WLAN.FSW.Get_ACLR() else: - ACLR = [-9999,-9999,-9999,-9999,-9999,-9999,-9999] + ACLR = [-9999, -9999, -9999, -9999, -9999, -9999, -9999] - ### Measure SEM + # ## Measure SEM if MeasSEM: - WLAN.FSW.write(':CONF:BURS:SPEC:MASK:IMM') #Config SEM Ch + WLAN.FSW.write(':CONF:BURS:SPEC:MASK:IMM') # Config SEM Ch WLAN.FSW.Set_InitImm() SEM = WLAN.FSW.query(':CALC1:LIM:FAIL?') else: SEM = 'NotTested' d = datetime.now() - tick - OutStr = f'{freq},{pwr:3d},{ALTime.seconds:3d}.{ALTime.microseconds:06d},{WLAN.WLAN_Std},{WLAN.WLAN_ChBW},{WLAN.WLAN_MCS},{Attn},{EVM},{SEM},{ACLR},{d.seconds:3d}.{d.microseconds:06d}' + OutStr = f'{freq}, {pwr:3d}, {ALTime.seconds:3d}.{ALTime.microseconds:06d}, {WLAN.WLAN_Std}, {WLAN.WLAN_ChBW}, {WLAN.WLAN_MCS}, {Attn}, {EVM}, {SEM}, {ACLR}, {d.seconds:3d}.{d.microseconds:06d}' OFile.write(OutStr) ########################################################## -### Cleanup Automation +# ## Cleanup Automation ########################################################## WLAN.jav_Close() diff --git a/rssd/examples/VST_WLAN_EVM.py b/rssd/examples/VST_WLAN_EVM.py index 658224d..33de123 100644 --- a/rssd/examples/VST_WLAN_EVM.py +++ b/rssd/examples/VST_WLAN_EVM.py @@ -1,62 +1,62 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. +# ## Rohde & Schwarz Automation for demonstration use. ### -### Title : Sample SMW FSW WLAN EVM Sweep -### Author : mclim -### Date : 2019.03.21 +# ## Title : Sample SMW FSW WLAN EVM Sweep +# ## Author : mclim +# ## Date : 2019.03.21 ### ########################################################## -### User Entry +# ## User Entry ########################################################## SMW_IP = '192.168.1.114' FSW_IP = '192.168.1.109' -FreqArry = [5.25e9,5.57e9] +FreqArry = [5.25e9, 5.57e9] pwrArry = [-20, -10, -5] -pwrArry = range(-50,10,3) #Power Array -ModArry = [['AC', 80,11], #Std,BW,MCS - ['AC',160,11]] #Std,BW,MCS +pwrArry = range(-50, 10, 3) # Power Array +ModArry = [['AC', 80, 11], # Std, BW, MCS + ['AC', 160, 11]] # Std, BW, MCS SweepTime = 0.002 ########################################################## -### Code Overhead: Import and create objects +# ## Code Overhead: Import and create objects ########################################################## # import time -from datetime import datetime #pylint: disable=E0611,E0401 -from rssd.FileIO import FileIO #pylint: disable=E0611,E0401 -from rssd.VST.WLAN import VST #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611, E0401 +from rssd.FileIO import FileIO # pylint: disable=E0611, E0401 +from rssd.VST.WLAN import VST # pylint: disable=E0611, E0401 OFile = FileIO().makeFile(__file__) ########################################################## -### Code Start +# ## Code Start ########################################################## -WLAN = VST().jav_Open(SMW_IP,FSW_IP,OFile) +WLAN = VST().jav_Open(SMW_IP, FSW_IP, OFile) ########################################################## -### Measure Time +# ## Measure Time ########################################################## -#sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String -OFile.write('Freq,Pwr,ALTime,Std,ChBW,MCS,Pwr,Attn,Preamp,RefLvl,EVM,CmdTime') +# sDate = datetime.now().strftime("%y%m%d-%H:%M:%S.%f") #Date String +OFile.write('Freq, Pwr, ALTime, Std, ChBW, MCS, Pwr, Attn, Preamp, RefLvl, EVM, CmdTime') WLAN.FSW.Init_WLAN() WLAN.FSW.Set_Trig1_Source('EXT') WLAN.FSW.Set_SweepCont(0) -for mod in ModArry: #Loop: Standard +for mod in ModArry: # Loop: Standard WLAN.WLAN_Std = mod[0] WLAN.WLAN_ChBW = mod[1] WLAN.WLAN_MCS = mod[2] - WLAN.Set_WLAN_All() ### Make Waveform ### + WLAN.Set_WLAN_All() # ## Make Waveform ### print(f'802.11{WLAN.WLAN_Std} RFBW:{WLAN.WLAN_ChBW} MCS:{WLAN.WLAN_MCS}') WLAN.FSW.Set_SweepTime(SweepTime) # WLAN.FSW.write(':TRAC:IQ:SRAT 160e6') - for freq in FreqArry: #Loop: Frequency + for freq in FreqArry: # Loop: Frequency WLAN.FSW.Set_Freq(freq) WLAN.SMW.Set_Freq(freq) WLAN.Freq = freq - for pwr in pwrArry: #Loop: Power + for pwr in pwrArry: # Loop: Power WLAN.SMW.Set_RFPwr(pwr) - #Autolevel Timing + # Autolevel Timing tick = datetime.now() WLAN.FSW.Set_WLAN_Autolvl() WLAN.FSW.Set_SweepCont(0) @@ -69,10 +69,10 @@ EVM = WLAN.FSW.Get_WLAN_EVMParams() Attn = WLAN.FSW.Get_AmpSettings() d = datetime.now() - tick - OutStr = f'{freq},{pwr:3d},{ALTime.seconds:3d}.{ALTime.microseconds:06d},{WLAN.WLAN_Std},{WLAN.WLAN_ChBW},{WLAN.WLAN_MCS},{Attn},{EVM},{d.seconds:3d}.{d.microseconds:06d}' + OutStr = f'{freq}, {pwr:3d}, {ALTime.seconds:3d}.{ALTime.microseconds:06d}, {WLAN.WLAN_Std}, {WLAN.WLAN_ChBW}, {WLAN.WLAN_MCS}, {Attn}, {EVM}, {d.seconds:3d}.{d.microseconds:06d}' OFile.write(OutStr) ########################################################## -### Cleanup Automation +# ## Cleanup Automation ########################################################## WLAN.jav_Close() diff --git a/rssd/examples/misc/00_IDN.py b/rssd/examples/misc/00_IDN.py index 47091ac..b8a8cf5 100644 --- a/rssd/examples/misc/00_IDN.py +++ b/rssd/examples/misc/00_IDN.py @@ -1,42 +1,42 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### -### Purpose: Quick visa utility -### Requird: python -m pip install pyvisa -### Author: Martin C Lim -### Date: 2017.08.01 -### Description: Simple utility to: -### 1) Create socket connection -### 2) Create VISA connection -### 3) Query instrument for *IDN? +# ## Rohde & Schwarz Automation for demonstration use. +# ## +# ## Purpose: Quick visa utility +# ## Requird: python -m pip install pyvisa +# ## Author: Martin C Lim +# ## Date: 2017.08.01 +# ## Description: Simple utility to: +# ## 1) Create socket connection +# ## 2) Create VISA connection +# ## 3) Query instrument for *IDN? ########################################################## -### User Entry +# ## User Entry ########################################################## savefile = '00_IDN.txt' -IPArry = ['192.168.1.109', #FSW - '192.168.1.114', #SMW - '192.168.1.115', #SMB - '192.168.1.130', #SMA - '192.168.1.30', #ZVA - '192.168.1.40', #ZVA - '192.168.1.150', #OSP - '192.168.1.140'] #RTO +IPArry = ['192.168.1.109', # FSW + '192.168.1.114', # SMW + '192.168.1.115', # SMB + '192.168.1.130', # SMA + '192.168.1.30', # ZVA + '192.168.1.40', # ZVA + '192.168.1.150', # OSP + '192.168.1.140'] # RTO ########################################################## -### Code Begin +# ## Code Begin ########################################################## import time import socket import visa ########################################################## -### Function Definition +# ## Function Definition ########################################################## def FileWrite(sOutput): sHostname = socket.gethostname() sDate = time.strftime("%y%m%d,%H%M%S") - f = open(savefile,'a+') - f.write("%s,%s,%s\n"%(sDate,sHostname,sOutput)) + f = open(savefile, 'a+') + f.write("%s,%s,%s\n"%(sDate, sHostname, sOutput)) f.close() def Socket_Query(IPAddr): @@ -48,7 +48,7 @@ def Socket_Query(IPAddr): s.sendall(SCPI.encode()) sRead = s.recv(1024).decode().strip() s.close() - except: #If error + except: # If error sRead = "###Socket Instrument not found###" print(IPAddr + ',' + sRead) FileWrite(IPAddr + ',' + sRead) @@ -57,7 +57,7 @@ def VISA_Query(IPAddr): try: rm = visa.ResourceManager() rmlist = rm.list_resources() - VISA1 = rm.open_resource('TCPIP0::'+ IPAddr +'::inst0::INSTR') + VISA1 = rm.open_resource(f'TCPIP0::{IPAddr}::inst0::INSTR') sRead = VISA1.query('*IDN?').strip() VISA1.close() except: @@ -66,7 +66,7 @@ def VISA_Query(IPAddr): FileWrite(IPAddr + ',' + sRead) ########################################################## -### Main Code +# ## Main Code ########################################################## for IP in IPArry: Socket_Query(IP) diff --git a/rssd/examples/misc/FSW_cal.py b/rssd/examples/misc/FSW_cal.py index 1d466e9..6e6dce1 100644 --- a/rssd/examples/misc/FSW_cal.py +++ b/rssd/examples/misc/FSW_cal.py @@ -1,34 +1,33 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Purpose: Simple Instrument Socket Example -### Author: mclim +# ## Rohde & Schwarz Automation for demonstration use. +# ## Purpose: Simple Instrument Socket Example ########################################################## -### User Entry +# ## User Entry ########################################################## -host = '192.168.1.109' #Instrument IP address -port = 5025 #Instrument control port +host = '192.168.1.109' # Instrument IP address +port = 5025 # Instrument control port ########################################################## -### Code Begin +# ## Code Begin ########################################################## -import socket #Import socket module +import socket # Import socket module def sQuery(SCPI): out = SCPI + "\n" - s.sendall(out.encode()) #Write 'cmd' - sOut = s.recv(2048).strip() #read socket + s.sendall(out.encode()) # Write 'cmd' + sOut = s.recv(2048).strip() # read socket return sOut.decode() def sWrite(SCPI): out = SCPI + "\n" - s.sendall(out.encode()) #Write 'cmd' + s.sendall(out.encode()) # Write 'cmd' ########################################################## -### Main Code +# ## Main Code ########################################################## -s = socket.socket() #Create a socket object +s = socket.socket() # Create a socket object s.connect((host, port)) -s.settimeout(1) #Timeout in seconds +s.settimeout(1) # Timeout in seconds print("*IDN? :" + sQuery("*IDN?")) print("*OPT? :" + sQuery("*OPT?")) diff --git a/rssd/examples/misc/RSATE_GUI.py b/rssd/examples/misc/RSATE_GUI.py index eb4b3dc..49817a4 100644 --- a/rssd/examples/misc/RSATE_GUI.py +++ b/rssd/examples/misc/RSATE_GUI.py @@ -3,7 +3,7 @@ textWindWid = 120 maxCol = 6 btnRow = 20 -ColorBG = "black" #gray30 +ColorBG = "black" # gray30 ColorFG = "green" ColorCurs = "White" @@ -19,7 +19,7 @@ import tkFileDialog END = Tkinter.END -#Code specific libraries +# Code specific libraries from RSVar import RSATE import RSATE_K96 @@ -30,37 +30,37 @@ def btn_Button(): pass def btn_Waveforms(): - lstWaveF.delete(0,END) + lstWaveF.delete(0, END) filez = tkFileDialog.askopenfilenames() fileList = list(filez) for i in fileList: - lstWaveF.insert(END,i) + lstWaveF.insert(END, i) lstWaveF.see(END) def btn_ClearWaves(): posi = lstWaveF.curselection() - lstWaveF.delete(0,END) + lstWaveF.delete(0, END) def btn_SaveCond(): RSVar.SMW_IP = Entry1.get() RSVar.FSW_IP = Entry2.get() - RSVar.WvArry = list(lstWaveF.get(0,END)) + RSVar.WvArry = list(lstWaveF.get(0, END)) RSVar.FreqArry = Entry3.get() RSVar.PwrArry = Entry4.get() dataSave(RSVar) def btn_Test(): - test.funcy(GUI,lstOutpt) + test.funcy(GUI, lstOutpt) def btn_Clear(): posi = lstOutpt.curselection() - lstOutpt.delete(0,END) + lstOutpt.delete(0, END) def btn_RunLoops(): fprintf("RSATERun: Run Tests") btn_SaveCond() - RSVar.FreqArry = map(float,ArrayInput(Entry3.get())) - RSVar.PwrArry = map(float,ArrayInput(Entry4.get())) + RSVar.FreqArry = map(float, ArrayInput(Entry3.get())) + RSVar.PwrArry = map(float, ArrayInput(Entry4.get())) for i, item in enumerate(RSVar.WvArry): head, tail = split(item) RSVar.WvArry[i] = tail.split(".")[0] @@ -85,30 +85,30 @@ def menu_Save(): def ArrayInput(stringIn): OutputList = [] - InputList = stringIn.split(",") + InputList = stringIn.split(", ") for i in InputList: i = i.strip() OutputList.append(i) return OutputList def fprintf(inStr): - #print(inStr) + # print(inStr) try: - #lstOutpt.insert(END,inStr) - lstOutpt.insert(0,inStr) - #lstOutpt.see(END) + # lstOutpt.insert(END, inStr) + lstOutpt.insert(0, inStr) + # lstOutpt.see(END) GUI.update() except: pass def dataSave(data): - with open("RSATE_GUI.dat","wb") as f: + with open("RSATE_GUI.dat", "wb") as f: pickle.dump(data, f) fprintf("DataSave: File Saved") def dataLoad(): try: - with open("RSATE_GUI.dat","rb") as f: + with open("RSATE_GUI.dat", "rb") as f: data = pickle.load(f) fprintf("DataLoad: OK") except: @@ -120,80 +120,80 @@ def dataLoad(): # Define GUI Widgets # ***************************************************************** RSVar = copy.copy(dataLoad()) -GUI = Tkinter.Tk() #Create GUI object -GUI.title("Rohde Schwarz DemoATE") #GUI Title -Lbl1 = Tkinter.Label(GUI, text="SMW IP") #Create Label -Entry1 = Tkinter.Entry(GUI,bg=ColorBG, fg=ColorFG,insertbackground=ColorCurs) #Create Entry background -Entry1.insert(END, RSVar.SMW_IP) #Default Value -Lbl2 = Tkinter.Label(GUI, text="FSW IP") #Create Label -Entry2 = Tkinter.Entry(GUI,bg=ColorBG, fg=ColorFG,insertbackground=ColorCurs) #Entry Background -Entry2.insert(END, RSVar.FSW_IP) #Default Value -Lbl3 = Tkinter.Label(GUI, text="Freq Array") #Create Label -Entry3 = Tkinter.Entry(GUI,bg=ColorBG, fg=ColorFG,insertbackground=ColorCurs) #Entry Background -Entry3.insert(END, RSVar.FreqArry) #Default Value -Lbl4 = Tkinter.Label(GUI, text="Power Array") #Create Label -Entry4 = Tkinter.Entry(GUI,bg=ColorBG, fg=ColorFG,insertbackground=ColorCurs) #Entry Background -Entry4.insert(END, RSVar.PwrArry) #Default Value -btnWaveF = Tkinter.Button(GUI, width=btnWid, text = "Select *.WV", command = btn_Waveforms) -btnWaveC = Tkinter.Button(GUI, width=btnWid, text = "Clear Waves", command = btn_ClearWaves) -btnSaveC = Tkinter.Button(GUI, width=btnWid, text = "Save", command = btn_SaveCond) -btnClear = Tkinter.Button(GUI, width=btnWid, text = "Test", command = btn_Test) -btnRunIt = Tkinter.Button(GUI, width=btnWid, text = "Run", command = btn_RunLoops) -btnQuit = Tkinter.Button(GUI, width=btnWid, text = "Quit", command = menu_Exit) -lstOutpt = Tkinter.Listbox(GUI, width=textWindWid,bg=ColorBG, fg=ColorFG) -srlOutpt = ttk.Scrollbar(GUI, orient=Tkinter.VERTICAL, command=lstOutpt.yview) #Create scrollbar S -lstOutpt.config(yscrollcommand=srlOutpt.set) #Link lstOutpt change to S -lstWaveF = Tkinter.Listbox(GUI,bg=ColorBG, fg=ColorFG,width=80) -srlWaveF = ttk.Scrollbar(GUI, orient=Tkinter.VERTICAL, command=lstWaveF.yview) #Create scrollbar S +GUI = Tkinter.Tk() # create GUI object +GUI.title("Rohde Schwarz DemoATE") # GUI Title +Lbl1 = Tkinter.Label(GUI, text="SMW IP") # create Label +Entry1 = Tkinter.Entry(GUI, bg=ColorBG, fg=ColorFG, insertbackground=ColorCurs) # create Entry background +Entry1.insert(END, RSVar.SMW_IP) # Default Value +Lbl2 = Tkinter.Label(GUI, text="FSW IP") # create Label +Entry2 = Tkinter.Entry(GUI, bg=ColorBG, fg=ColorFG, insertbackground=ColorCurs) # Entry Background +Entry2.insert(END, RSVar.FSW_IP) # Default Value +Lbl3 = Tkinter.Label(GUI, text="Freq Array") # create Label +Entry3 = Tkinter.Entry(GUI, bg=ColorBG, fg=ColorFG, insertbackground=ColorCurs) # Entry Background +Entry3.insert(END, RSVar.FreqArry) # Default Value +Lbl4 = Tkinter.Label(GUI, text="Power Array") # create Label +Entry4 = Tkinter.Entry(GUI, bg=ColorBG, fg=ColorFG, insertbackground=ColorCurs) # Entry Background +Entry4.insert(END, RSVar.PwrArry) # Default Value +btnWaveF = Tkinter.Button(GUI, width=btnWid, text="Select *.WV", command=btn_Waveforms) +btnWaveC = Tkinter.Button(GUI, width=btnWid, text="Clear Waves", command=btn_ClearWaves) +btnSaveC = Tkinter.Button(GUI, width=btnWid, text="Save", command=btn_SaveCond) +btnClear = Tkinter.Button(GUI, width=btnWid, text="Test", command=btn_Test) +btnRunIt = Tkinter.Button(GUI, width=btnWid, text="Run", command=btn_RunLoops) +btnQuit = Tkinter.Button(GUI, width=btnWid, text="Quit", command=menu_Exit) +lstOutpt = Tkinter.Listbox(GUI, width=textWindWid, bg=ColorBG, fg=ColorFG) +srlOutpt = ttk.Scrollbar(GUI, orient=Tkinter.VERTICAL, command=lstOutpt.yview) # create scrollbar S +lstOutpt.config(yscrollcommand=srlOutpt.set) # Link lstOutpt change to S +lstWaveF = Tkinter.Listbox(GUI, bg=ColorBG, fg=ColorFG, width=80) +srlWaveF = ttk.Scrollbar(GUI, orient=Tkinter.VERTICAL, command=lstWaveF.yview) # create scrollbar S for item in RSVar.WvArry: lstWaveF.insert(END, item) -lstWaveF.config(yscrollcommand=srlWaveF.set) #Link lstWaveF change to S -lstFrequ = Tkinter.Listbox(GUI,bg=ColorBG, fg=ColorFG) -lstPower = Tkinter.Listbox(GUI,bg=ColorBG, fg=ColorFG) +lstWaveF.config(yscrollcommand=srlWaveF.set) # Link lstWaveF change to S +lstFrequ = Tkinter.Listbox(GUI, bg=ColorBG, fg=ColorFG) +lstPower = Tkinter.Listbox(GUI, bg=ColorBG, fg=ColorFG) # Grid up the Widgets -Lbl1.grid(row=0,column=0,sticky=Tkinter.E,columnspan=1) -Lbl2.grid(row=1,column=0,sticky=Tkinter.E,columnspan=1) -Lbl3.grid(row=2,column=0,sticky=Tkinter.E,columnspan=1) -Lbl4.grid(row=3,column=0,sticky=Tkinter.E,columnspan=1) -Entry1.grid(row=0,column=1,columnspan=1) -Entry2.grid(row=1,column=1,columnspan=1) -Entry3.grid(row=2,column=1,columnspan=1) -Entry4.grid(row=3,column=1,columnspan=1) -btnWaveF.grid(row=btnRow,column=0) -btnWaveC.grid(row=btnRow,column=1) -btnSaveC.grid(row=btnRow,column=2) -btnClear.grid(row=btnRow,column=3) -btnRunIt.grid(row=btnRow,column=4) -btnQuit.grid(row=btnRow,column=5) - -lstWaveF.grid(row=0,column=2,columnspan=4,rowspan=5) -srlWaveF.grid(column=6,row=0,rowspan=5,sticky=(Tkinter.W,Tkinter.N,Tkinter.S)) -#lstFrequ.grid(row=0,column=4,rowspan=5) -#lstPower.grid(row=0,column=5,rowspan=5) -lstOutpt.grid(row=btnRow-1,column=0,columnspan=maxCol) -srlOutpt.grid(column=maxCol,row=btnRow-1, sticky=(Tkinter.W,Tkinter.N,Tkinter.S)) +Lbl1.grid(row=0, column=0, sticky=Tkinter.E, columnspan=1) +Lbl2.grid(row=1, column=0, sticky=Tkinter.E, columnspan=1) +Lbl3.grid(row=2, column=0, sticky=Tkinter.E, columnspan=1) +Lbl4.grid(row=3, column=0, sticky=Tkinter.E, columnspan=1) +Entry1.grid(row=0, column=1, columnspan=1) +Entry2.grid(row=1, column=1, columnspan=1) +Entry3.grid(row=2, column=1, columnspan=1) +Entry4.grid(row=3, column=1, columnspan=1) +btnWaveF.grid(row=btnRow, column=0) +btnWaveC.grid(row=btnRow, column=1) +btnSaveC.grid(row=btnRow, column=2) +btnClear.grid(row=btnRow, column=3) +btnRunIt.grid(row=btnRow, column=4) +btnQuit.grid(row=btnRow, column=5) + +lstWaveF.grid(row=0, column=2, columnspan=4, rowspan=5) +srlWaveF.grid(column=6, row=0, rowspan=5, sticky=(Tkinter.W, Tkinter.N, Tkinter.S)) +# lstFrequ.grid(row=0, column=4, rowspan=5) +# lstPower.grid(row=0, column=5, rowspan=5) +lstOutpt.grid(row=btnRow - 1, column=0, columnspan=maxCol) +srlOutpt.grid(column=maxCol, row=btnRow - 1, sticky=(Tkinter.W, Tkinter.N, Tkinter.S)) # ***************************************************************** # Define menu # ***************************************************************** -menu = Tkinter.Menu(GUI) #create dropdown in GUI +menu = Tkinter.Menu(GUI) # create dropdown in GUI GUI.config(menu=menu) -fileMenu = Tkinter.Menu(menu) #create dropdown in menu -fileMenu.add_command(label="Open",command=menu_Open) -fileMenu.add_command(label="Save",command=menu_Save) +fileMenu = Tkinter.Menu(menu) # create dropdown in menu +fileMenu.add_command(label="Open", command=menu_Open) +fileMenu.add_command(label="Save", command=menu_Save) fileMenu.add_separator() -fileMenu.add_command(label="Exit",command=menu_Exit) +fileMenu.add_command(label="Exit", command=menu_Exit) -editMenu = Tkinter.Menu(menu) #create dropdown in menu -editMenu.add_command(label="Edit",command=menu_Open) +editMenu = Tkinter.Menu(menu) # create dropdown in menu +editMenu.add_command(label="Edit", command=menu_Open) -menu.add_cascade(label="File",menu=fileMenu) #add dropdown menu -menu.add_cascade(label="Edit",menu=editMenu) #add dropdown menu +menu.add_cascade(label="File", menu=fileMenu) # add dropdown menu +menu.add_cascade(label="Edit", menu=editMenu) # add dropdown menu # ***************************************************************** # Start Program # ***************************************************************** -GUI.mainloop() #Display window +GUI.mainloop() # Display window diff --git a/rssd/examples/misc/Simple_Socket.py b/rssd/examples/misc/Simple_Socket.py index 33e04d6..bb32144 100644 --- a/rssd/examples/misc/Simple_Socket.py +++ b/rssd/examples/misc/Simple_Socket.py @@ -1,5 +1,5 @@ """Rohde & Schwarz Automation for demonstration use. """ -#pylint: disable=invalid-name +# pylint: disable=invalid-name import socket # Import socket module # import xml.etree.ElementTree as ET @@ -26,7 +26,7 @@ def getSysInfo(): return xmlIn ############################################################################### -### Main Code +# ## Main Code ############################################################################### s = socket.socket() # Create a socket object s.connect(('192.168.58.30', 5025)) diff --git a/rssd/examples/misc/Simple_Socket_FSW.py b/rssd/examples/misc/Simple_Socket_FSW.py index 795636b..55e850f 100644 --- a/rssd/examples/misc/Simple_Socket_FSW.py +++ b/rssd/examples/misc/Simple_Socket_FSW.py @@ -14,7 +14,7 @@ def sWrite(SCPI): s.sendall(f'{SCPI}\n'.encode()) # Write SCPI # ############################################################################## -### Main Code +# ## Main Code # ############################################################################## s = socket.socket() # Create a socket object s.connect(('192.168.58.109', 5025)) diff --git a/rssd/examples/misc/Simple_Socket_SCPI_Player.py b/rssd/examples/misc/Simple_Socket_SCPI_Player.py index cdc261c..7d1bd7c 100644 --- a/rssd/examples/misc/Simple_Socket_SCPI_Player.py +++ b/rssd/examples/misc/Simple_Socket_SCPI_Player.py @@ -1,32 +1,31 @@ """Rohde & Schwarz Automation for demonstration use. """ -#pylint: disable=invalid-name, unused-import +# pylint: disable=invalid-name, unused-import import os -import socket #Import socket module +import socket # Import socket module import logging -import xml.etree.ElementTree as ET -host = '10.0.0.16' #Instrument IP address +host = '10.0.0.16' # Instrument IP address ############################################################################### -### Code Begin +# ## Code Begin ############################################################################### def sQuery(SCPI): '''socket query''' out = SCPI + "\n" - s.sendall(out.encode()) #Write 'cmd' - sOut = s.recv(2048).strip() #read socket + s.sendall(out.encode()) # Write 'cmd' + sOut = s.recv(2048).strip() # read socket return sOut.decode() def sWrite(SCPI): '''socket write''' out = SCPI + "\n" - s.sendall(out.encode()) #Write 'cmd' + s.sendall(out.encode()) # Write 'cmd' def getSysInfo(): '''get system options''' xmlIn = sQuery("SYST:DFPR?") strStart = xmlIn.find('deviceId="') + len('deviceID="') strStop = xmlIn.find('type="') - 2 - xmlIn = xmlIn[strStart:strStop] #Remove header + xmlIn = xmlIn[strStart:strStop] # Remove header print(xmlIn) return xmlIn @@ -59,7 +58,7 @@ def sendSCPI(SCPIarry): logging.error(outStr) ############################################################################### -### Main Code +# ## Main Code ############################################################################### s = socket.socket() # Create a socket object s.connect((host, 5025)) diff --git a/rssd/examples/misc/Simple_Socket_SMWy.py b/rssd/examples/misc/Simple_Socket_SMWy.py index 5c67180..f678ed5 100644 --- a/rssd/examples/misc/Simple_Socket_SMWy.py +++ b/rssd/examples/misc/Simple_Socket_SMWy.py @@ -1,9 +1,9 @@ """ Rohde & Schwarz Automation for demonstration use.""" -#pylint: disable=invalid-name +# pylint: disable=invalid-name ########################################################## -### User Entry +# ## User Entry ########################################################## -import socket #Import socket module +import socket # Import socket module def sQuery(SCPI): """Socket Query""" @@ -18,10 +18,10 @@ def sWrite(SCPI): s.sendall(f'{SCPI}\n'.encode()) # Write SCPI ########################################################## -### Main Code +# ## Main Code ########################################################## -s = socket.socket() #Create a socket object +s = socket.socket() # Create a socket object s.connect(('192.168.58.114', 5025)) -s.settimeout(1) #Timeout in seconds +s.settimeout(1) # Timeout in seconds sQuery('*IDN?') diff --git a/rssd/examples/misc/Simple_VISA.py b/rssd/examples/misc/Simple_VISA.py index 7d6f260..161e447 100644 --- a/rssd/examples/misc/Simple_VISA.py +++ b/rssd/examples/misc/Simple_VISA.py @@ -1,26 +1,26 @@ '''Rohde & Schwarz Automation for demonstration use.''' -#pylint: disable=invalid-name, unused-import, using-constant-test +# pylint: disable=invalid-name, unused-import, using-constant-test import xml.etree.ElementTree as ET -import pyvisa #Import VISA module +import pyvisa # Import VISA module ############################################################################### -### Code Begin +# ## Code Begin ############################################################################### def vQuery(SCPI): '''VISA query''' VISA1.read_termination = '\n' # 0x0A for socket - vOut = VISA1.query(SCPI) #Query cmd + vOut = VISA1.query(SCPI) # Query cmd return vOut.strip() def vWrite(SCPI): '''VISA write''' - VISA1.write(SCPI) #Write cmd + VISA1.write(SCPI) # Write cmd def getSysInfo(): '''Get System Info''' xmlIn = vQuery("SYST:DFPR?") - xmlIn = xmlIn[xmlIn.find('>')+1:] #Remove header + xmlIn = xmlIn[xmlIn.find('>') + 1:] # Remove header root = ET.fromstring(xmlIn) if 0: DData = root.find('DeviceData').items() @@ -34,7 +34,7 @@ def getSysInfo(): print(dType, devID) ############################################################################### -### Main Code +# ## Main Code ############################################################################### rm = pyvisa.ResourceManager() rmlist = rm.list_resources() diff --git a/rssd/examples/misc/VISA_SCPI_Player.py b/rssd/examples/misc/VISA_SCPI_Player.py index 2055146..5a2a111 100644 --- a/rssd/examples/misc/VISA_SCPI_Player.py +++ b/rssd/examples/misc/VISA_SCPI_Player.py @@ -1,12 +1,12 @@ """Rohde & Schwarz Automation for demonstration use. """ -#pylint: disable=invalid-name, unused-import +# pylint: disable=invalid-name, unused-import import os import logging import pyvisa -host = '10.0.0.16' #Instrument IP address +host = '10.0.0.16' # Instrument IP address ############################################################################### -### Code Begin +# ## Code Begin ############################################################################### def readSCPI(): '''read SCPI array from file''' @@ -36,11 +36,11 @@ def sendSCPI(SCPIarry): logging.error(outStr) ############################################################################### -### Main Code +# ## Main Code ############################################################################### -rm = pyvisa.ResourceManager() #Create Resource Manager -instr = rm.open_resource(f'TCPIP0::{host}::hislip0::INSTR') #Create Visa Obj -instr.timeout = 5000 #Timeout, millisec +rm = pyvisa.ResourceManager() # Create Resource Manager +instr = rm.open_resource(f'TCPIP0::{host}::hislip0::INSTR') # Create Visa Obj +instr.timeout = 5000 # Timeout, millisec # logger = logging.getLogger(__name__) # logger.setLevel(logging.DEBUG) # file_handler = logging.FileHandler(os.path.splitext(__file__)[0] + '.log') diff --git a/rssd/examples/misc/XMLParse.py b/rssd/examples/misc/XMLParse.py index ee207df..5c1e79a 100644 --- a/rssd/examples/misc/XMLParse.py +++ b/rssd/examples/misc/XMLParse.py @@ -1,26 +1,25 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### -### Purpose: Simple Instrument Socket Example -### Author: mclim -### Date: 2017.09.01 +# ## Rohde & Schwarz Automation for demonstration use. +# ## +# ## Purpose: Simple Instrument Socket Example +# ## Author: mclim ########################################################## -### User Entry +# ## User Entry ########################################################## -xmlFile = 'syst_dfpr-FSW.txt' #Instrument IP address +xmlFile = 'syst_dfpr-FSW.txt' # Instrument IP address ########################################################## -### Code Begin +# ## Code Begin ########################################################## -import xml.etree.ElementTree as ET +import xml.etree.ElementTree as ET ########################################################## -### Main Code +# ## Main Code ########################################################## tree = ET.parse('syst_dfpr-FSW.txt') root = tree.getroot() -#xmlIn = xmlIn[xmlIn.find('>')+1:]#Remove header -#root = ET.fromstring(xmlIn) +# xmlIn = xmlIn[xmlIn.find('>')+1:]#Remove header +# root = ET.fromstring(xmlIn) # DData = root.find('DeviceData').items() # devID = DData[0][1] # dType = DData[1][1] @@ -34,23 +33,23 @@ print("HW Options:") for hwopt in root.iter('Hardware'): try: - print(" ",hwopt.attrib['name'],hwopt.attrib['partNumber'],hwopt.attrib['sn']) + print(" ", hwopt.attrib['name'], hwopt.attrib['partNumber'], hwopt.attrib['sn']) except: pass - + print("SW Options:") for swopt in root.iter('Software'): try: - print(" ",swopt.attrib['name'], end='') + print(" ", swopt.attrib['name'], end='') print(swopt.attrib['version'], end='') except: pass print("") - + print("License Options:") for swopt in root.iter('ActiveLicense'): try: - print(" ",end='') + print(" ", end='') print(swopt.attrib['optionIndex'], end='') print(swopt.attrib['used'], end='') except: diff --git a/rssd/examples/misc/parseRSI.py b/rssd/examples/misc/parseRSI.py index 4cdbd57..b1d1508 100644 --- a/rssd/examples/misc/parseRSI.py +++ b/rssd/examples/misc/parseRSI.py @@ -3,21 +3,21 @@ import glob import regex -# Version of script +# Version of script __version__ = "6" # String variable to hold contents to be written to CSV file at the end csv_output_string = "" # Supported file types -supported_file_types =('.rsi', '.xml') +supported_file_types = ('.rsi', '.xml') class XmlNode(): def __init__(self, xml_string=""): self.xml_string = xml_string - + # Print the XML string(for debugging) - #print("Extracted xml string:\n{0}".format(self.xml_string)) - - # Transform the XML string to an Element tree for easy parsing + # print("Extracted xml string:\n{0}".format(self.xml_string)) + + # Transform the XML string to an Element tree for easy parsing self.root = ET.fromstring(self.xml_string) def printToScreen(self, output_string): @@ -35,13 +35,12 @@ def printNset_AttributeFromNode(self, attribute_name): def printNset_AttributesFromElement(self, element_name, attributes_list): # Find element element = self.root.find(element_name) - + # Find attributes from element for attribute_name in attributes_list: attribute_value = element.get(attribute_name) self.printToScreen("\t{0}:\t{1}".format(attribute_name, attribute_value)) self.writeToCsv("{0},".format(attribute_value)) - # Parse the input argument & retrieve a list of file paths def parseInputArguments(): @@ -50,7 +49,7 @@ def parseInputArguments(): parser.add_argument('-f', '--file', type=str, help='name of RSI or XML file, wildcards are also accepted') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) return parser.parse_args() - + def isFileTypeSupported(args): if args.file.endswith(supported_file_types): @@ -64,65 +63,61 @@ def getListOfFilesFromArgument(args): # Check if the file argument was specified if not args.file: return - + inputfiles_list = [] - - # check the extension names + + # check the extension names if isFileTypeSupported(args): - + inputfiles_list = glob.glob(args.file) num_files_found = len(inputfiles_list) - if(num_files_found > 0): + if (num_files_found > 0): ext_name = args.file.split('.')[1] print("Found {0} {1} file(s)".format(num_files_found, ext_name)) else: print("ERROR: {0} not found".format(args.file)) return - + return inputfiles_list def getListOfFilesFromCurrentFolder(): inputfiles_list = [] - for file_type in supported_file_types: - files_list = glob.glob('*' + file_type) print("Found {0} {1} file(s)".format(len(files_list), file_type)) - inputfiles_list += files_list - return inputfiles_list def parseInputFile(i, inputfile): print('\n{0}) Loading {1}'.format(i, inputfile)) - + global csv_output_string csv_output_string += "\n\n%s\n" % inputfile - + # Open the file & read the contents into memory with open(inputfile, mode='rb') as file: # b is important -> binary fileContent_bytes = file.read() # To be compliant with Python 3, decode the binary bytes to string fileContent_string = fileContent_bytes.decode('utf_8', 'ignore') - + # Regex search pattern regex_pattern = r'^()\s*\n' - + # Extract all XML nodes of type KeyInstallation xml_string_list = regex.findall(regex_pattern, fileContent_string, regex.S | regex.M, overlapped=True) print("\tFound {0} option key XML node(s)".format(len(xml_string_list))) - - #print(xml_string_list) # Print the list of nodes found(for debugging) - + + # print(xml_string_list) # Print the list of nodes found(for debugging) + for j, xml_string in enumerate(xml_string_list, 1): node = XmlNode(xml_string) # List of required attributes attributes_list = ['option_type', 'full_name', 'key_type', 'duration'] - #Print CSV Header - if j ==1: + # Print CSV Header + if j == 1: csv_output_string += "\nmodel_name,device_id,{0}\n".format(",".join(attributes_list)) node.printToScreen(" ") @@ -142,17 +137,17 @@ def writeResultsToCsv(output_filename): def main(): args = parseInputArguments() - + inputfiles_list = getListOfFilesFromArgument(args) - + # If no input arguments given, search for files in local directory - if not(inputfiles_list): + if not inputfiles_list: inputfiles_list = getListOfFilesFromCurrentFolder() - + # Loop through all RSI files & retrieve XML content for i, inputfile in enumerate(inputfiles_list, 1): parseInputFile(i, inputfile) - + writeResultsToCsv("parseRSI_results.csv") diff --git a/rssd/examples/misc/pythonBasics.py b/rssd/examples/misc/pythonBasics.py index 8c387ef..f75b9b8 100644 --- a/rssd/examples/misc/pythonBasics.py +++ b/rssd/examples/misc/pythonBasics.py @@ -1,7 +1,7 @@ '''Basic Python Functions''' print("__file__: " + __file__) -print("__name__: " + __name__) +print("__name__: " + __name__) globals()["Test"] = 12345 print(globals()) @@ -9,5 +9,5 @@ print("FilePath: " + os.path.dirname(os.path.realpath(__file__))) asdf = 8 -for i in range(2,int(asdf/2)+1): +for i in range(2, int(asdf / 2) + 1): print(i) diff --git a/rssd/examples/misc/syst_dfpr_parse.py b/rssd/examples/misc/syst_dfpr_parse.py index 514689d..5232aed 100644 --- a/rssd/examples/misc/syst_dfpr_parse.py +++ b/rssd/examples/misc/syst_dfpr_parse.py @@ -5,18 +5,18 @@ from rssd.yaVISA import jaVisa from rssd.FileIO import FileIO -### User Entry +# ## User Entry ########################################################## IPaddr = '10.0.0.25' ########################################################## -### Code Begin +# ## Code Begin ########################################################## OFile = FileIO().makeFile(__file__) -K2 = jaVisa().jav_openvisa(f'TCPIP0::{IPaddr}::INSTR', OFile) #Create VISA object +K2 = jaVisa().jav_openvisa(f'TCPIP0::{IPaddr}::INSTR', OFile) # Create VISA object rdStr = K2.query('SYST:DFPR?') -XMLstr = '<' + rdStr.split('<',1)[1] +XMLstr = '<' + rdStr.split('<', 1)[1] # print(XMLstr) if rdStr == '': @@ -26,5 +26,5 @@ for child in root_element: print(child) - for key,value in child.attrib.items(): + for key, value in child.attrib.items(): print(f' {key}:{value}') diff --git a/rssd/examples/misc/timeTest.py b/rssd/examples/misc/timeTest.py index 59e970a..b4fdf16 100644 --- a/rssd/examples/misc/timeTest.py +++ b/rssd/examples/misc/timeTest.py @@ -1,20 +1,20 @@ ########################################################## -### Rohde & Schwarz Automation for demonstration use. -### Title : Timing SCPI Commands Example -### Author : mclim +# ## Rohde & Schwarz Automation for demonstration use. +# ## Title : Timing SCPI Commands Example +# ## Author : mclim ########################################################## -### User Entry +# ## User Entry ########################################################## numMeas = 10 ########################################################## -### Code Begin +# ## Code Begin ########################################################## -from datetime import datetime #pylint: disable=E0611,E0401 +from datetime import datetime # pylint: disable=E0611,E0401 import time -for i in range(numMeas): #Loop: # of Measurements +for i in range(numMeas): # Loop: # of Measurements tick = datetime.now() time.sleep(1) d = datetime.now() - tick diff --git a/rssd/instrument.py b/rssd/instrument.py index 252efca..efd7e06 100644 --- a/rssd/instrument.py +++ b/rssd/instrument.py @@ -32,11 +32,11 @@ def close(self): except: pass - def delay(self,sec): + def delay(self, sec): '''delay in Sec''' time.sleep(sec) - def open(self, address, type = 'socket', param = 5025): # pylint: disable=redefined-builtin + def open(self, address, type='socket', param=5025): # pylint: disable=redefined-builtin '''Open bus Sesion. Return bus object''' if type == 'socket': self.bus = jaSocket().open(address, param) @@ -54,44 +54,44 @@ def open(self, address, type = 'socket', param = 5025): # pylint: disabl self.SCPI_clrErr() return self - def query(self,cmd): - read ="" + def query(self, cmd): + read = "" try: if self.dataIDN != "": read = self.bus.query(cmd).strip() # Write if connected except: logging.error(f'SCPI_RdErr : {self.Model}-->{cmd}') - self.SCPI_file_write(f'{self.Model},{cmd},{read}') + self.SCPI_file_write(f'{self.Model}, {cmd}, {read}') return read - def queryFloat(self,cmd): + def queryFloat(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [float(i) for i in strArry][0] except: return -9999.9999 - def queryFloatArry(self,cmd): + def queryFloatArry(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [float(i) for i in strArry] except: return [-9999.9999, -888.888, -777.777, -666.666, -555.555, -444.444] - def queryInt(self,cmd): + def queryInt(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return int([float(i) for i in strArry][0]) # Float for scientific 'e' notation except: return -9999 - def queryIntArry(self,cmd): + def queryIntArry(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [int(i) for i in strArry] except: - return [-9999,-8888,-7777] + return [-9999, -8888, -7777] def SCPI_clear(self): '''Clear Errors''' @@ -110,13 +110,13 @@ def SCPI_clrErr(self): self.dLastErr = RdStr ErrList.append(RdStr) logging.error(f'SCPI_ClrErr: {self.Model}-->{RdStr}') - except: #Instrument does not support SYST:ERR? + except: # Instrument does not support SYST:ERR? logging.error('SCPI_ClrErr: {self.Model}-->SYST:ERR not Supported') return ErrList def SCPI_error(self): '''Read SYST:ERR?''' - RdStr = self.query("SYST:ERR?").strip().split(',') + RdStr = self.query("SYST:ERR?").strip().split(', ') return RdStr def SCPI_file_write(self, outstr): @@ -128,7 +128,7 @@ def SCPI_IDN(self): self.dataIDN = "Temp" # Temp for self.query self.dataIDN = self.query("*IDN?").strip() if self.dataIDN != "": # Data Returned? - IDNStr = self.dataIDN.split(',') + IDNStr = self.dataIDN.split(', ') try: self.Make = IDNStr[0] self.Model = IDNStr[1] @@ -190,19 +190,19 @@ def SCPI_read_wait(self, InCMD): def timeout(self, seconds): self.bus.timeout(seconds) - def write(self,cmd): + def write(self, cmd): try: if self.dataIDN != "": self.bus.write(cmd) # Write if connected except: logging.error(f'SCPI_WrtErr : {self.Model}-->{cmd}') - self.SCPI_file_write(f'{self.Model},{cmd}') + self.SCPI_file_write(f'{self.Model}, {cmd}') - def write_raw(self,SCPI): + def write_raw(self, SCPI): self.bus.write_raw(SCPI) - def write_scpilist(self,SCPIList): + def write_scpilist(self, SCPIList): '''Send SCPI list & Query if "?" ''' - ### Collect read results into a list for return. + # ## Collect read results into a list for return. OutList = [] for cmd in SCPIList: if cmd.find('?') == -1: diff --git a/rssd/iqdata.py b/rssd/iqdata.py index a0c88c6..fb18b76 100644 --- a/rssd/iqdata.py +++ b/rssd/iqdata.py @@ -30,7 +30,7 @@ class IQ(object): """ Util IQ Converting Object """ def __init__(self): - self.iqData = [complex(1,1)] #Complex IQ Data + self.iqData = [complex(1, 1)] # Complex IQ Data self.iiqqList = [] self.iqiqList = [] self.NumberOfSamples = 0 @@ -42,7 +42,7 @@ def __iqiq2complex__(self, iqiq): print("Expecting IQIQIQ order, input vector has odd number of samples!") return self.NumberOfSamples = len(iqiq) // 2 - self.iqData = [complex(iqiq[2*n], iqiq[2*n+1]) for n in range(self.NumberOfSamples)] + self.iqData = [complex(iqiq[2 * n], iqiq[2 * n + 1]) for n in range(self.NumberOfSamples)] def __iiqq2complex__(self, iiqq): """Returns a complex list of I/Q samples from a single list containing IIIQQQ values""" @@ -50,13 +50,13 @@ def __iiqq2complex__(self, iiqq): print("Expecting IIIQQQ order, input vector has odd number of samples!") return self.NumberOfSamples = len(iiqq) // 2 - self.iqData = [complex(iiqq[n], iiqq[n+self.NumberOfSamples]) for n in range(self.NumberOfSamples)] + self.iqData = [complex(iiqq[n], iiqq[n + self.NumberOfSamples]) for n in range(self.NumberOfSamples)] def __complex2iqiq__(self): """Returns a list of I/Q samples from a complex list. iqiqlist = __complex2iqiq__(complexList)""" - f= lambda iq,i: iq.real if i==0 else iq.imag - self.iqiqList = [f(iq,i) for iq in self.iqData for i in range(2)] + f = lambda iq, i: iq.real if i == 0 else iq.imag + self.iqiqList = [f(iq, i) for iq in self.iqData for i in range(2)] return self.iqiqList @@ -73,20 +73,20 @@ def writeIqw(self, FileName): # Ve Note: IIIQQQ is a deprecated format, don't use it for new files. writtenSamples = writeIqw(iqList, "MyFile.wv")""" - #check if self.iqData is complex + # check if self.iqData is complex if isinstance(self.iqData[0], complex): self.__complex2iqiq__() self.NumberOfSamples = len(self.iqiqList) // 2 try: file = open(FileName, "wb") - file.write(struct.pack("f"*len(self.iqiqList),*self.iqiqList)) + file.write(struct.pack("f" * len(self.iqiqList), *self.iqiqList)) file.close() except: - print("File (" + FileName +") write error!") + print(f"File ({FileName}) write error!") return 0 return self.NumberOfSamples - def readIqw(self, FileName, iqiq = True): # Verified 2020.0115 + def readIqw(self, FileName, iqiq=True): # Verified 2020.0115 """Reads an IQW (iiqq or iqiq) file--> self.__iXXq2complex__ --> self.iqData - If iqiq is True, samples are read pairwise (IQIQIQ) - else, samples are read, i first then q (IIIQQQ) @@ -99,10 +99,10 @@ def readIqw(self, FileName, iqiq = True): # Ve data = file.read() file.close() except: - print("File open error ("+ FileName+")!") + print(f"File open error ({FileName})!") ReadSamples = len(data) // BytesPerValue - data = list(struct.unpack("f"*ReadSamples, data)) + data = list(struct.unpack("f" * ReadSamples, data)) if iqiq: self.__iqiq2complex__(data) else: @@ -112,30 +112,30 @@ def writeWv(self, FileName): # Verified 2020.0115 """writes a WV file. self.iqData can be a list of complex or list of floats (iqiqiq format).""" - #check if self.iqData is complex + # check if self.iqData is complex if isinstance(self.iqData[0], complex): self.__complex2iqiq__() self.NumberOfSamples = len(self.iqiqList) // 2 - #Find maximum magnitude and scale for max to be FullScale (1.0) + # find maximum magnitude and scale for max to be FullScale (1.0) power = [] for n in range(self.NumberOfSamples): - power.append(abs(self.iqiqList[2*n]**2 + self.iqiqList[2*n+1]**2)) + power.append(abs(self.iqiqList[2 * n]**2 + self.iqiqList[2 * n + 1]**2)) scaling = math.sqrt(max(power)) self.iqiqList = [iq / scaling for iq in self.iqiqList] # normalize to magnitude 1 - rms = math.sqrt(sum(power)/self.NumberOfSamples)/scaling # calculate rms in dB (below full scale) - rms = abs(20*math.log10(rms)) # Convert to dB - self.iqiqList = [math.floor(iq * 32767 +.5) for iq in self.iqiqList] # Convert to int16 + rms = math.sqrt(sum(power) / self.NumberOfSamples) / scaling # calculate rms in dB (below full scale) + rms = abs(20 * math.log10(rms)) # Convert to dB + self.iqiqList = [math.floor(iq * 32767 + .5) for iq in self.iqiqList] # Convert to int16 try: file = open(FileName, "wb") file.write("{TYPE: SMU-WV,0}".encode("ASCII")) file.write("{COMMENT: R&S WaveForm, TheAE-RA}".encode("ASCII")) - file.write(("{DATE: " + str(datetime.today())+ "}").encode("ASCII")) - file.write(("{CLOCK:" +str(self.fSamplingRate) + "}").encode("ASCII")) - file.write(("{LEVEL OFFS:" + "{:2.4f}".format(rms) + ",0}").encode("ASCII")) + file.write(("{DATE: " + str(datetime.today()) + "}").encode("ASCII")) + file.write(("{CLOCK:" + str(self.fSamplingRate) + "}").encode("ASCII")) + file.write(("{LEVEL OFFS:" + "{:2.4f}".format(rms) + ",0}").encode("ASCII")) file.write(("{SAMPLES:" + str(self.NumberOfSamples) + "}").encode("ASCII")) # if(m1start > 0 && m1stop > 0) # %Control Length only needed for markers @@ -143,23 +143,23 @@ def writeWv(self, FileName): # Verified 2020.0115 # fprintf(file_id,'%s',['{CLOCK MARKER:' num2str(fSamplingRate) '}']); # fprintf(file_id,'%s',['{MARKER LIST 1: ' num2str(m1start) ':1;' num2str(m1stop) ':0}']); # end - file.write(("{WAVEFORM-" + str(4*self.NumberOfSamples+1) + ": #").encode("ASCII")) - file.write(struct.pack("h"*len(self.iqiqList),*self.iqiqList)) + file.write(("{WAVEFORM-" + str(4 * self.NumberOfSamples + 1) + ": #").encode("ASCII")) + file.write(struct.pack("h" * len(self.iqiqList), *self.iqiqList)) file.write("}".encode("ASCII")) file.close() except: - print("File (" + FileName +") write error!") + print(f"File ({FileName}) write error!") return 0 return self.NumberOfSamples - def readWv(self,FileName): # Verified 2020.0115 + def readWv(self, FileName): # Verified 2020.0115 """Reads a WV file --> self.__iqiq2complex__ --> self.iqData""" try: file = open(FileName, "rb") data = file.read() file.close() except: - print("File open error ("+ FileName+")!") + print(f"File open ({FileName}) error!") return binaryStart = 0 @@ -167,9 +167,9 @@ def readWv(self,FileName): Counter = 0 ConverterSize = 20 while (binaryStart == 0) & (Counter < len(data)): - tags += data[Counter:Counter+ConverterSize].decode("ASCII","ignore") + tags += data[Counter:Counter + ConverterSize].decode("ASCII", "ignore") Counter += ConverterSize - res = re.search("WAVEFORM.{0,20}:.{0,3}#",tags) + res = re.search("WAVEFORM.{0,20}:.{0,3}#", tags) if res is not None: binaryStart = res.span()[1] @@ -177,12 +177,12 @@ def readWv(self,FileName): print("Required tags not found, potentially incompatible file format!") return - res = re.search("SAMPLES[ ]*:[ ]*(?P[0-9]*)",tags) + res = re.search("SAMPLES[ ]*:[ ]*(?P[0-9]*)", tags) self.NumberOfSamples = int(res.group("NumberOfSamples")) - res = re.search("CLOCK[ ]*:[ ]*(?P[0-9]*)",tags) + res = re.search("CLOCK[ ]*:[ ]*(?P[0-9]*)", tags) self.fSamplingRate = float(res.group("SamplingRate")) - data = list(struct.unpack("h"*self.NumberOfSamples*2, data[binaryStart:-1])) #MMM data: IQ arry - data = list(map(lambda x: x/32767.0, data)) #MMM consumes a lot of time + data = list(struct.unpack("h" * self.NumberOfSamples * 2, data[binaryStart:-1])) # MMM data: IQ arry + data = list(map(lambda x: x / 32767.0, data)) # MMM consumes a lot of time self.__iqiq2complex__(data) def writeXml(self, filenameiqw, filenamexml): # Verified 2020.0115 @@ -191,55 +191,55 @@ def writeXml(self, filenameiqw, filenamexml): xmlfile.write("\n") xmlfile.write("\n") xmlfile.write("\n") - xmlfile.write("Python iq.tar writer (self.iqData.py)\n") #Optional - xmlfile.write("RS WaveForm, TheAE-RA\n") #Optional - xmlfile.write(""+ datetime.now(None).isoformat() +"\n") + xmlfile.write("Python iq.tar writer (self.iqData.py)\n") # Optional + xmlfile.write("RS WaveForm, TheAE-RA\n") # Optional + xmlfile.write("" + datetime.now(None).isoformat() + "\n") xmlfile.write("" + str(self.NumberOfSamples) + "\n") xmlfile.write("" + str(self.fSamplingRate) + "\n") xmlfile.write("complex\n") xmlfile.write("float32\n") - xmlfile.write("1\n") #Optional - xmlfile.write("1\n") #Optional - xmlfile.write("" + filenameiqw+ "\n") - # xmlfile.write("\n") #Optional + xmlfile.write("1\n") # Optional + xmlfile.write("1\n") # Optional + xmlfile.write("" + filenameiqw + "\n") + # xmlfile.write("\n") # Optional xmlfile.write("\n") xmlfile.close() return 1 - def writeIqTar(self, FileName): # Verified 2020.0115 #pylint: disable=R1710 + def writeIqTar(self, FileName): # Verified 2020.0115 # pylint: disable=R1710 """writes an iq.tar file. Complex self.iqData values are interpreted as Volts. self.iqData can be a list of complex or list of floats (iqiqiq format).""" - path,filename = os.path.split(FileName) #pylint: disable=W0612 + path, filename = os.path.split(FileName) # pylint: disable=W0612 - #Create binary file + # Create binary file binaryfile = re.sub("iq.tar", "complex.1ch.float32", filename, flags=re.IGNORECASE) self.writeIqw(os.path.join(path, binaryfile)) if self.NumberOfSamples == 0: return 0 - # xsltfilename = "open_IqTar_xml_file_in_web_browser.xslt" #xslt is optional + # xsltfilename = "open_IqTar_xml_file_in_web_browser.xslt" # xslt is optional xmlfilename = binaryfile + '.xml' self.writeXml(binaryfile, os.path.join(path, xmlfilename)) try: tar = tarfile.open(FileName, "w") tar.add(os.path.join(path, binaryfile), arcname=binaryfile) - #tar.add(os.path.join(path, xsltfilename), arcname=xsltfilename) #xslt is optional + # tar.add(os.path.join(path, xsltfilename), arcname=xsltfilename) # xslt is optional tar.add(os.path.join(path, xmlfilename), arcname=xmlfilename) tar.close() os.remove(os.path.join(path, binaryfile)) os.remove(os.path.join(path, xmlfilename)) except: - print("IqTar (" + FileName +") write error!") + print(f"IqTar ({FileName}) write error!") return 0 - def readIqTar(self,FileName): # Verified 2020.0115 + def readIqTar(self, FileName): # Verified 2020.0115 """Reads an iq.tar file --> self.iqData""" - path,filename = os.path.split(FileName) #pylint: disable=W0612 + path, filename = os.path.split(FileName) # pylint: disable=W0612 self.fSamplingRate = 0 try: tar = tarfile.open(FileName, "r:") - a=tar.getnames() + a = tar.getnames() xmlfile = [filename for filename in a if ".xml" in filename.lower()] xmlfile = xmlfile[0] tar.extract(xmlfile) @@ -250,7 +250,7 @@ def readIqTar(self,FileName): # Verified 2020.0115 helper = root.find("ScalingFactor") scaling = 1 if helper: - if helper.get("unit")!="V": + if helper.get("unit") != "V": print("Only (V)olts scaling factor supported - assuming 1V!") else: scaling = float(root.find("ScalingFactor").text) @@ -261,15 +261,15 @@ def readIqTar(self,FileName): # Verified 2020.0115 self.readIqw(binaryfilename) os.remove(binaryfilename) except: - print("IqTar (" + FileName +") read error!") + print(f"IqTar ({FileName}) read error!") - self.iqData = [sample * scaling for sample in self.iqData] #Apply scaling factor + self.iqData = [sample * scaling for sample in self.iqData] # Apply scaling factor - def main(self): #pragma: no cover - #for testing only + def main(self): # pragma: no cover + # for testing only filename = "C:\\Users\\lim_m\\ownCloud\\ATE\\AA_Code\\DSP_python\\DSP_python\\SampleWv\\CW_10tones_32MHz_100usec.iq.tar" - ### Read data + # ## Read data if '.wv' in filename: self.readWv(filename) elif '.iq.tar' in filename: @@ -284,17 +284,17 @@ def main(self): #pragma: no cover self.writeWv(filename + '.wv') self.writeIqw(filename + '.iqw') duration = time.time() - start - speed = self.NumberOfSamples/1e6/duration - print("Total: %d samples in %2.2f ms. writeSpeed: %f MSamples/s"%(self.NumberOfSamples,duration*1e3,speed)) + speed = self.NumberOfSamples / 1e6 / duration + print("Total: %d samples in %2.2f ms. writeSpeed: %f MSamples/s"%(self.NumberOfSamples, duration * 1e3, speed)) -def dataConvert(): #pragma: no cover +def dataConvert(): # pragma: no cover ''' binary to float32 conversion ''' # numpy.frombuffer dtype=float32() sampledata = b'\x0E\x78\x94\xB7' - print('Data %s %d'%(sampledata,len(sampledata))) - print("Float=",struct.unpack(" file for""" -# pylint: disable=E0611,E0401,E0202,'pointless-statement' +# pylint: disable=E0611, E0401, E0202, 'pointless-statement' import time import pyvisa @@ -26,7 +26,7 @@ def __init__(self): self.VISA = '' # '@py' for pyvisa-py self.K2 = 'NoVISA' - def delay(self,sec): + def delay(self, sec): """delay in Sec""" time.sleep(sec) @@ -46,23 +46,23 @@ def jav_Close(self): def jav_ClrErr(self): """Read all SYST:ERR messages""" ErrList = [] - try: #Instrument supports SYST:ERR? + try: # Instrument supports SYST:ERR? while True: RdStr = self.query("SYST:ERR?").strip() ErrList.append(RdStr) - RdStrSplit = RdStr.split(',') - if RdStr == "" : break #No readstring - if RdStrSplit[0] == "0" : break #Read 0 error:R&S - if RdStrSplit[0] == "+0": break #Read 0 error:Other + RdStrSplit = RdStr.split(', ') + if RdStr == "" : break # No readstring + if RdStrSplit[0] == "0" : break # Read 0 error:R&S + if RdStrSplit[0] == "+0": break # Read 0 error:Other self.dLastErr = RdStr - if self.debug: print("jav_ClrErr: %s-->%s"%(self.Model,RdStr)) - except: #Instrument does not support SYST:ERR? + if self.debug: print("jav_ClrErr: %s-->%s"%(self.Model, RdStr)) + except: # Instrument does not support SYST:ERR? if self.debug: print("jav_ClrErr: %s-->SYST:ERR not Supported"%(self.Model)) return ErrList def jav_Error(self): """Read SYST:ERR?""" - RdStr = self.query("SYST:ERR?").strip().split(',') + RdStr = self.query("SYST:ERR?").strip().split(', ') return RdStr def jav_fileout(self, fily, outstr): @@ -74,10 +74,10 @@ def jav_fileout(self, fily, outstr): def jav_IDN(self): """query *IDN? Assign data to properties""" - self.dataIDN = "Temp" #Temp for self.query + self.dataIDN = "Temp" # Temp for self.query self.dataIDN = self.query("*IDN?").strip() - if self.dataIDN != "": #Data Returned? - IDNStr = self.dataIDN.split(',') + if self.dataIDN != "": # Data Returned? + IDNStr = self.dataIDN.split(', ') try: self.Make = IDNStr[0] self.Model = IDNStr[1] @@ -86,24 +86,24 @@ def jav_IDN(self): except: pass else: - self.dataIDN = "" #Reset if not read + self.dataIDN = "" # Reset if not read return self.dataIDN def jav_logscpi(self): - self.f = rssd.FileIO() #pylint:disable=E1101 - DataFile = self.f.init("yaVISA") #pylint:disable=W0612 + self.f = rssd.FileIO() # pylint:disable=E1101 + DataFile = self.f.init("yaVISA") # pylint:disable=W0612 def jav_OPC_Wait(self, InCMD): """ Wait based on *OPC """ start_time = time.time() - self.write("*ESE 1") #Event Status Enable - self.write("*SRE 32") #ServiceReqEnable-Bit5:Std Event - self.write(InCMD + ";*OPC") #Initiate Read. *OPC will trigger ESR - #print (' OPC Wait: ' +InCMD) + self.write("*ESE 1") # Event Status Enable + self.write("*SRE 32") # ServiceReqEnable-Bit5:Std Event + self.write(InCMD + ";*OPC") # Initiate Read. *OPC will trigger ESR + # print (' OPC Wait: ' +InCMD) read = 0 - while (read & 1) != 1: #Loop until done + while (read & 1) != 1: # Loop until done try: - read = self.queryInt("*ESR?") #Poll EventStatReg-Bit0:Op Complete (STB?) + read = self.queryInt("*ESR?") # Poll EventStatReg-Bit0:Op Complete (STB?) except: if self.debug: print("jav_OPCWai:*ESR? Error") time.sleep(0.5) @@ -121,13 +121,13 @@ def jav_Open(self, IPAddr, fily=''): # VISA: 'TCPIP0::'+IP_Address+'::inst0' # VISA: 'TCPIP0::'+IP_Address+'::hislip0' # VISA: 'TCPIP0::'+IP_Address+'::hislip0::INSTR' - self.jav_openvisa('TCPIP0::'+IPAddr+'::hislip0::INSTR',fily) + self.jav_openvisa(f'TCPIP0::{IPAddr}::hislip0::INSTR', fily) # except: # print('VISA Openerror. Using Raw Socket') - # self.jav_openvisa('TCPIP::'+IPAddr+'::5025::SOCKET',fily) + # self.jav_openvisa('TCPIP::'+IPAddr+'::5025::SOCKET', fily) return self - def jav_OpenTest(self, host): #pylint: disable='unused-argument' + def jav_OpenTest(self, host): # pylint: disable='unused-argument' self.debug = 0 self.VISA = '@py' # self.jav_Open(host) @@ -157,13 +157,13 @@ def jav_openvisa(self, sVISAStr, fily=''): """ TMR = timer() TMR.start() - rm = pyvisa.ResourceManager(self.VISA) #Create Resource Manager + rm = pyvisa.ResourceManager(self.VISA) # Create Resource Manager TMR.tick() - #rmList = rm.list_resources() #List VISA Resources + # rmList = rm.list_resources() # List VISA Resources try: - # self.K2 = rm.open_resource(sVISAStr, open_timeout=100) #Create Visa Obj - self.K2 = rm.open_resource(sVISAStr) #Create Visa Obj - self.K2.timeout = 5000 #Timeout, millisec + # self.K2 = rm.open_resource(sVISAStr, open_timeout=100) # Create Visa Obj + self.K2 = rm.open_resource(sVISAStr) # Create Visa Obj + self.K2.timeout = 5000 # Timeout, millisec # self.K2.write_termination = self.EOL # self.K2.read_termination = self.EOL self.jav_IDN() @@ -184,15 +184,15 @@ def jav_Reset(self): def jav_reslist(self): try: - rm = pyvisa.ResourceManager() #Create Resource Manager - rmList = rm.list_resources() #List VISA Resources + rm = pyvisa.ResourceManager() # Create Resource Manager + rmList = rm.list_resources() # List VISA Resources except: - rmList =["No VISA"] + rmList = ["No VISA"] return rmList - def jav_scpilist(self,SCPIList): + def jav_scpilist(self, SCPIList): """Send SCPI list & Query if "?" """ - ### Collect read results into a list for return. + # ## Collect read results into a list for return. OutList = [] for cmd in SCPIList: if cmd.find('?') == -1: @@ -205,11 +205,11 @@ def jav_scpilist(self,SCPIList): def jav_Wait(self, InCMD): """Brute Force Wait and check *OPC? """ start_time = time.time() - self.write(InCMD) #Initiate Command + self.write(InCMD) # Initiate Command read = "0" - while (int(read) & 1) != 1: #Loop until done + while (int(read) & 1) != 1: # Loop until done try: - read = self.queryInt("*OPC?") #See if we can get *OPC? + read = self.queryInt("*OPC?") # See if we can get *OPC? except: pass time.sleep(1) @@ -220,53 +220,53 @@ def jav_Wait(self, InCMD): if self.debug: print('jav_Wai : %0.2fsec'%(delta)) return delta - def query(self,cmd): - read ="" + def query(self, cmd): + read = "" try: if self.dataIDN != "": - read = self.K2.query(cmd).strip() #Write if connected + read = self.K2.query(cmd).strip() # Write if connected except: - if self.debug: print("jav_RdErr : %s-->%s"%(self.Model,cmd)) - self.jav_fileout(self.f, "%s,%s,%s"%(self.Model,cmd,read)) + if self.debug: print("jav_RdErr : %s-->%s"%(self.Model, cmd)) + self.jav_fileout(self.f, "%s, %s, %s"%(self.Model, cmd, read)) return read - def queryFloat(self,cmd): + def queryFloat(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [float(i) for i in strArry][0] except: return -9999.9999 - def queryFloatArry(self,cmd): + def queryFloatArry(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [float(i) for i in strArry] except: return [-9999.9999, -888.888, -777.777, -666.666, -555.555, -444.444] - def queryInt(self,cmd): + def queryInt(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return int([float(i) for i in strArry][0]) # Float for scientific 'e' notation except: return -9999 - def queryIntArry(self,cmd): + def queryIntArry(self, cmd): try: - strArry = self.query(cmd).split(',') + strArry = self.query(cmd).split(', ') return [int(i) for i in strArry] except: - return [-9999,-8888,-7777] + return [-9999, -8888, -7777] - def write(self,cmd): + def write(self, cmd): try: - if self.dataIDN != "": self.K2.write(cmd) #Write if connected + if self.dataIDN != "": self.K2.write(cmd) # Write if connected except: - if self.debug: print("jav_WrtErr: %s-->%s"%(self.Model,cmd)) - self.jav_fileout(self.f, "%s,%s"%(self.Model,cmd)) + if self.debug: print("jav_WrtErr: %s-->%s"%(self.Model, cmd)) + self.jav_fileout(self.f, "%s, %s"%(self.Model, cmd)) - def jav_write_raw(self,SCPI): + def jav_write_raw(self, SCPI): self.K2.write_raw(SCPI) if __name__ == "__main__": @@ -274,10 +274,10 @@ def jav_write_raw(self,SCPI): ipaddress = '10.0.0.10' RS.debug = 1 # RS.jav_logscpi() - RS.jav_Open(ipaddress) #Default HiSlip - # RS.jav_openvisa(f'TCPIP::{ipaddress}::hislip0::INSTR') #hislip - # RS.jav_openvisa(f'TCPIP::{ipaddress}::instr0::INSTR') #VXI11 - # RS.jav_openvisa(f'TCPIP::{ipaddress}::5025::SOCKET') #Socket + RS.jav_Open(ipaddress) # Default HiSlip + # RS.jav_openvisa(f'TCPIP::{ipaddress}::hislip0::INSTR') # hislip + # RS.jav_openvisa(f'TCPIP::{ipaddress}::instr0::INSTR') # VXI11 + # RS.jav_openvisa(f'TCPIP::{ipaddress}::5025::SOCKET') # Socket rdStr = RS.query('*IDN?') print(rdStr) RS.jav_Close() diff --git a/rssd/yaVISA_GUI.py b/rssd/yaVISA_GUI.py index 1925f13..c2fb02b 100644 --- a/rssd/yaVISA_GUI.py +++ b/rssd/yaVISA_GUI.py @@ -1,64 +1,59 @@ -from __future__ import division #int div to float +from __future__ import division # int div to float ######################################################################## # Title: Rohde & Schwarz Simple ATE example GUI ######################################################################## # User Input Settings ######################################################################## btnWid = 11 -Col0Wid = 10 #Text Labels -Col1Wid = 14 #Text Input -ColxWid = 4*(btnWid+4) -4 -BotWindWid = Col0Wid+Col1Wid+ColxWid +Col0Wid = 10 # Text Labels +Col1Wid = 14 # Text Input +ColxWid = 4 * (btnWid + 4) - 4 +BotWindWid = Col0Wid + Col1Wid + ColxWid maxCol = 6 btnRow = 20 -ClrTxtBg = "black" #gray30 +ClrTxtBg = "black" # gray30 ClrTxtFg = "green2" BtnTxtFg = "white" ColorCurs = "white" ClrAppBG = "grey30" ######################################################################## -### Code Import +# ## Code Import ######################################################################## -try: #Python2 naming - import Tkinter as Tk - import ttk - import tkFileDialog -except: #Python3 naming - import tkinter as Tk - from tkinter import ttk - import tkinter.filedialog as tkFileDialog +import tkinter as Tk +from tkinter import ttk +import tkinter.filedialog as tkFileDialog END = Tk.END -#Code specific libraries +# Code specific libraries import copy from datetime import datetime from yaVISA import jaVisa ######################################################################## -### Functions +# ## Functions ######################################################################## class GUIData(object): def __init__(self): - self.Title = "Rohde&Schwarz VISA Utility" - self.EntTxt1= "Instrument IP" - self.Entry1 = "127.0.0.1" - self.EntTxt2= "SCPI String" - self.Entry2 = "*IDN?" - self.EntTxt3= "Entry 3" - self.Entry3 = "" - self.EntTxt4= "Entry 4" - self.Entry4 = "" - self.List1 = ['*IDN?','*OPT?'] - self.BtnTxt1= 'VISA Scan' - self.BtnTxt2= 'SCPI List' - self.BtnTxt3= '*IDN?' - self.BtnTxt4= 'Query' - self.BtnTxt5= 'Write' + self.Title = "Rohde&Schwarz VISA Utility" + self.EntTxt1 = "Instrument IP" + self.Entry1 = "127.0.0.1" + self.EntTxt2 = "SCPI String" + self.Entry2 = "*IDN?" + self.EntTxt3 = "Entry 3" + self.Entry3 = "" + self.EntTxt4 = "Entry 4" + self.Entry4 = "" + self.List1 = ['*IDN?', '*OPT?'] + self.BtnTxt1 = 'VISA Scan' + self.BtnTxt2 = 'SCPI List' + self.BtnTxt3 = '*IDN?' + self.BtnTxt4 = 'Query' + self.BtnTxt5 = 'Write' def ArrayInput(stringIn): OutputList = [] - InputList = stringIn.split(",") + InputList = stringIn.split(", ") for i in InputList: i = i.strip() OutputList.append(i) @@ -66,7 +61,7 @@ def ArrayInput(stringIn): def btn_Clear(): # posi = lstBotWind.curselection() - lstBotWind.delete(0.0,END) + lstBotWind.delete(0.0, END) def btn1(): """Scan VISA""" @@ -82,7 +77,7 @@ def btn2(): windowLowerWrite("[SCPI LIST]") K2 = jaVisa() K2.jav_Open(Entry1.get()) - SCPIList = lstTopWind.get("1.0",END).split('\n') + SCPIList = lstTopWind.get("1.0", END).split('\n') OutList = K2.jav_scpilist(SCPIList) try: windowLowerWrite(' Err:' + ''.join(K2.jav_Close())) @@ -121,11 +116,8 @@ def btn5(): def dataLoad(): OutObj = GUIData() try: - try: #Python3 - f = open(__file__ + ".csv","rt") - except: #Python2 - f = open(__file__ + ".csv","rb") - data = f.read().split(',') + f = open(__file__ + ".csv", "rt") + data = f.read().split(', ') OutObj.Entry1 = data[0] OutObj.Entry2 = data[1] OutObj.Entry3 = data[2] @@ -136,37 +128,37 @@ def dataLoad(): return OutObj def dataSave(): - try: #Python3 - f = open(__file__ + ".csv",'wt', encoding='utf-8') + try: # Python3 + f = open(__file__ + ".csv", 'wt', encoding='utf-8') except: - f = open(__file__ + ".csv",'wb') - f.write('%s,'%(Entry1.get())) - f.write('%s,'%(Entry2.get())) - f.write('%s,'%(Entry3.get())) - f.write('%s,'%(Entry4.get())) + f = open(__file__ + ".csv", 'wb') + f.write('%s, '%(Entry1.get())) + f.write('%s, '%(Entry2.get())) + f.write('%s, '%(Entry3.get())) + f.write('%s, '%(Entry4.get())) f.close() windowLowerWrite("DataSave: File Saved") def windowLowerClear(): # posi = lstBotWind.curselection() - lstBotWind.delete(0.0,END) + lstBotWind.delete(0.0, END) def windowLowerWrite(inStr): - sDate = datetime.now().strftime("%y%m%d-%H%M%S.%f") #Date String + sDate = datetime.now().strftime("%y%m%d-%H%M%S.%f") # Date String try: - lstBotWind.insert(Tk.INSERT,"%s %s\n"%(sDate[:-3],inStr)) #Text moves down - # lstBotWind.insert(END,"%s %s\n"%(sDate[:-3],inStr)) #Text moves up - # lstBotWind.see(END) #Text moves up + lstBotWind.insert(Tk.INSERT, "%s %s\n"%(sDate[:-3], inStr)) # Text moves down + # lstBotWind.insert(END, "%s %s\n"%(sDate[:-3], inStr)) # Text moves up + # lstBotWind.see(END) # Text moves up GUI.update() except: pass def windowUpperClear(): - #posi = lstTopWind.curselection() - lstTopWind.delete(0.0,END) + # posi = lstTopWind.curselection() + lstTopWind.delete(0.0, END) def windowUpperWrite(inStr): - lstTopWind.insert(END,'\n'+inStr) + lstTopWind.insert(END, '\n' + inStr) lstTopWind.see(END) GUI.update() @@ -185,120 +177,120 @@ def menu_Save(): dataSave() def mnu_TopWindLoad_Files(): - lstTopWind.delete(0,END) + lstTopWind.delete(0, END) filez = tkFileDialog.askopenfilenames() for i in list(filez): - lstTopWind.insert(END,i) + lstTopWind.insert(END, i) lstTopWind.see(END) def mnu_TopWindLoad_Read(): - lstTopWind.delete(0,END) + lstTopWind.delete(0, END) filez = tkFileDialog.askopenfilename() windowLowerWrite(filez) for i in list(filez): - lstTopWind.insert(END,i) + lstTopWind.insert(END, i) lstTopWind.see(END) def mnu_TopWindClear(): # posi = lstTopWind.curselection() - lstTopWind.delete(0.0,END) + lstTopWind.delete(0.0, END) def mnu_SaveCond(): dataSave() ######################################################################## -### Main Code +# ## Main Code ######################################################################## RSVar = copy.copy(dataLoad()) -GUI = Tk.Tk() #Create GUI object -GUI.title(RSVar.Title) #GUI Title -#GUI.iconbitmap('RSIcon.ico') -GUI.resizable(0,0) +GUI = Tk.Tk() # Create GUI object +GUI.title(RSVar.Title) # GUI Title +# GUI.iconbitmap('RSIcon.ico') +GUI.resizable(0, 0) GUI.config(bg=ClrAppBG) ######################################################################## -### Define GUI Widgets -Label1 = Tk.Label(GUI,width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt1) #Create Label -Entry1 = Tk.Entry(GUI,width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) -Entry1.insert(END,RSVar.Entry1) #Default Value -Label2 = Tk.Label(GUI,width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt2) #Create Label -Entry2 = Tk.Entry(GUI,width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) -Entry2.insert(END,RSVar.Entry2) #Default Value -Label3 = Tk.Label(GUI,width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt3) #Create Label -Entry3 = Tk.Entry(GUI,width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) -Entry3.insert(END,RSVar.Entry3) #Default Value -Label4 = Tk.Label(GUI,width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt4) #Create Label -Entry4 = Tk.Entry(GUI,width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) -Entry4.insert(END,RSVar.Entry4) #Default Value -btnObj1 = Tk.Button(GUI,width=btnWid,bg=ClrAppBG,fg=BtnTxtFg,text=RSVar.BtnTxt1,command = btn1) -btnObj2 = Tk.Button(GUI,width=btnWid,bg=ClrAppBG,fg=BtnTxtFg,text=RSVar.BtnTxt2,command = btn2) -btnObj3 = Tk.Button(GUI,width=btnWid,bg=ClrAppBG,fg=BtnTxtFg,text=RSVar.BtnTxt3,command = btn3) -btnObj4 = Tk.Button(GUI,width=btnWid,bg=ClrAppBG,fg=BtnTxtFg,text=RSVar.BtnTxt4,command = btn4) -btnObj5 = Tk.Button(GUI,width=btnWid,bg=ClrAppBG,fg=BtnTxtFg,text=RSVar.BtnTxt5,command = btn5) -btnQuit = Tk.Button(GUI,width=btnWid,bg='red' ,fg=BtnTxtFg,text="Quit", command = menu_Exit) +# ## Define GUI Widgets +Label1 = Tk.Label(GUI, width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt1) # Create Label +Entry1 = Tk.Entry(GUI, width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) +Entry1.insert(END, RSVar.Entry1) # Default Value +Label2 = Tk.Label(GUI, width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt2) # Create Label +Entry2 = Tk.Entry(GUI, width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) +Entry2.insert(END, RSVar.Entry2) # Default Value +Label3 = Tk.Label(GUI, width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt3) # Create Label +Entry3 = Tk.Entry(GUI, width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) +Entry3.insert(END, RSVar.Entry3) # Default Value +Label4 = Tk.Label(GUI, width=Col0Wid, bg=ClrAppBG, text=RSVar.EntTxt4) # Create Label +Entry4 = Tk.Entry(GUI, width=Col1Wid, bg=ClrTxtBg, fg=ClrTxtFg, insertbackground=ColorCurs) +Entry4.insert(END, RSVar.Entry4) # Default Value +btnObj1 = Tk.Button(GUI, width=btnWid, bg=ClrAppBG, fg=BtnTxtFg, text=RSVar.BtnTxt1, command=btn1) +btnObj2 = Tk.Button(GUI, width=btnWid, bg=ClrAppBG, fg=BtnTxtFg, text=RSVar.BtnTxt2, command=btn2) +btnObj3 = Tk.Button(GUI, width=btnWid, bg=ClrAppBG, fg=BtnTxtFg, text=RSVar.BtnTxt3, command=btn3) +btnObj4 = Tk.Button(GUI, width=btnWid, bg=ClrAppBG, fg=BtnTxtFg, text=RSVar.BtnTxt4, command=btn4) +btnObj5 = Tk.Button(GUI, width=btnWid, bg=ClrAppBG, fg=BtnTxtFg, text=RSVar.BtnTxt5, command=btn5) +btnQuit = Tk.Button(GUI, width=btnWid, bg='red', fg=BtnTxtFg, text="Quit", command=menu_Exit) ######################################################################## -### List Boxes +# ## List Boxes ######################################################################## -lstBotWind = Tk.Text(GUI, width=BotWindWid, bg=ClrTxtBg, fg=ClrTxtFg,\ - wrap=Tk.CHAR, height=15) -srlBotWind = ttk.Scrollbar(GUI, orient=Tk.VERTICAL, command=lstBotWind.yview) #Create scrollbar +lstBotWind = Tk.Text(GUI, width=BotWindWid, bg=ClrTxtBg, fg=ClrTxtFg, \ + wrap=Tk.CHAR, height=15) +srlBotWind = ttk.Scrollbar(GUI, orient=Tk.VERTICAL, command=lstBotWind.yview) # Create scrollbar lstBotWind.config(wrap='none') -lstBotWind.config(yscrollcommand=srlBotWind.set) #Link scroll to lstBotWind -lstBotWind.insert(Tk.INSERT,"Output Window\n") +lstBotWind.config(yscrollcommand=srlBotWind.set) # Link scroll to lstBotWind +lstBotWind.insert(Tk.INSERT, "Output Window\n") lstBotWind.tag_add("here", "1.0", "1.40") lstBotWind.tag_config("here", background="yellow", foreground="blue") -lstTopWind = Tk.Text(GUI,bg=ClrTxtBg, fg=ClrTxtFg, width=ColxWid,height=10) -srlTopWind = ttk.Scrollbar(GUI, orient=Tk.VERTICAL,command=lstTopWind.yview) #Create scrollbar +lstTopWind = Tk.Text(GUI, bg=ClrTxtBg, fg=ClrTxtFg, width=ColxWid, height=10) +srlTopWind = ttk.Scrollbar(GUI, orient=Tk.VERTICAL, command=lstTopWind.yview) # Create scrollbar for item in RSVar.List1: lstTopWind.insert(END, item + '\n') -lstTopWind.config(yscrollcommand=srlTopWind.set) #Link scroll to lstTopWind +lstTopWind.config(yscrollcommand=srlTopWind.set) # Link scroll to lstTopWind ######################################################################## -### Draw Widgets w/ Grid +# ## Draw Widgets w/ Grid ######################################################################## -Label1.grid(row=0,column=0,sticky=Tk.E) -Label2.grid(row=1,column=0,sticky=Tk.E) -#Label3.grid(row=2,column=0,sticky=Tk.E) -#Label4.grid(row=3,column=0,sticky=Tk.E) -Entry1.grid(row=0,column=1) -Entry2.grid(row=1,column=1) -#Entry3.grid(row=2,column=1) -#Entry4.grid(row=3,column=1) -btnObj1.grid(row=btnRow,column=0) -btnObj2.grid(row=btnRow,column=1) -btnObj3.grid(row=btnRow,column=2) -btnObj4.grid(row=btnRow,column=3) -btnObj5.grid(row=btnRow,column=4) -btnQuit.grid(row=btnRow,column=5) - -lstTopWind.grid(row=0, column=2, columnspan=4,rowspan=4, sticky=(Tk.E)) -srlTopWind.grid(row=0, column=maxCol, rowspan=4, sticky=(Tk.W,Tk.N,Tk.S)) -lstBotWind.grid(row=btnRow-1,column=0, columnspan=(maxCol), sticky=Tk.E) -srlBotWind.grid(row=btnRow-1,column=maxCol, sticky=(Tk.W,Tk.N,Tk.S)) +Label1.grid(row=0, column=0, sticky=Tk.E) +Label2.grid(row=1, column=0, sticky=Tk.E) +# Label3.grid(row=2, column=0, sticky=Tk.E) +# Label4.grid(row=3, column=0, sticky=Tk.E) +Entry1.grid(row=0, column=1) +Entry2.grid(row=1, column=1) +# Entry3.grid(row=2, column=1) +# Entry4.grid(row=3, column=1) +btnObj1.grid(row=btnRow, column=0) +btnObj2.grid(row=btnRow, column=1) +btnObj3.grid(row=btnRow, column=2) +btnObj4.grid(row=btnRow, column=3) +btnObj5.grid(row=btnRow, column=4) +btnQuit.grid(row=btnRow, column=5) + +lstTopWind.grid(row=0, column=2, columnspan=4, rowspan=4, sticky=(Tk.E)) +srlTopWind.grid(row=0, column=maxCol, rowspan=4, sticky=(Tk.W, Tk.N, Tk.S)) +lstBotWind.grid(row=btnRow - 1, column=0, columnspan=(maxCol), sticky=Tk.E) +srlBotWind.grid(row=btnRow - 1, column=maxCol, sticky=(Tk.W, Tk.N, Tk.S)) ######################################################################## # Define menu ######################################################################## -menu = Tk.Menu(GUI) #create GUI dropdown -GUI.config(menu=menu) #define GUI's menu +menu = Tk.Menu(GUI) # create GUI dropdown +GUI.config(menu=menu) # define GUI's menu -fileMenu = Tk.Menu(menu) #create dropdown menu -fileMenu.add_command(label="Open",command=menu_Open) -fileMenu.add_command(label="Save",command=menu_Save) +fileMenu = Tk.Menu(menu) # create dropdown menu +fileMenu.add_command(label="Open", command=menu_Open) +fileMenu.add_command(label="Save", command=menu_Save) fileMenu.add_separator() fileMenu.add_command(label="SCPI Load", command=mnu_TopWindLoad_Read) -fileMenu.add_command(label="SCPI Clear",command=mnu_TopWindClear) +fileMenu.add_command(label="SCPI Clear", command=mnu_TopWindClear) fileMenu.add_separator() -fileMenu.add_command(label="Exit",command=menu_Exit) -menu.add_cascade(label="File",menu=fileMenu) #add dropdown menu +fileMenu.add_command(label="Exit", command=menu_Exit) +menu.add_cascade(label="File", menu=fileMenu) # add dropdown menu -editMenu = Tk.Menu(menu) #create dropdown menu -editMenu.add_command(label="Edit",command=menu_Open) -menu.add_cascade(label="Edit",menu=editMenu) #add dropdown menu +editMenu = Tk.Menu(menu) # create dropdown menu +editMenu.add_command(label="Edit", command=menu_Open) +menu.add_cascade(label="Edit", menu=editMenu) # add dropdown menu ######################################################################## # Start Program ######################################################################## -GUI.mainloop() #Display window +GUI.mainloop() # Display window diff --git a/rssd/yaVISA_socket.py b/rssd/yaVISA_socket.py index 4c3b57a..932b475 100644 --- a/rssd/yaVISA_socket.py +++ b/rssd/yaVISA_socket.py @@ -19,14 +19,14 @@ def __init__(self): self.dLastErr = '' # Last error self.K2 = 'NoVISA' - def delay(self,sec): + def delay(self, sec): """delay in Sec""" time.sleep(sec) def jav_Clear(self): """Clear VISA Errors""" - #self.K2.clear() - pass #pylint: disable=unnecessary-pass + # self.K2.clear() + pass # pylint: disable=unnecessary-pass def jav_Close(self): """Close K2 Session""" @@ -40,18 +40,18 @@ def jav_Close(self): def jav_ClrErr(self): """Read all SYST:ERR messages""" ErrList = [] - try: #Instrument supports SYST:ERR? + try: # Instrument supports SYST:ERR? while True: RdStr = self.query("SYST:ERR?").strip() ErrList.append(RdStr) RdStrSplit = RdStr.split(',') - if RdStr == "" : break #No readstring - if RdStrSplit[0] == "0" : break #Read 0 error:R&S - if RdStrSplit[0] == "+0": break #Read 0 error:Other - if 'Page Could not be Displayed' in RdStrSplit[0] : break #For html testing socket + if RdStr == "": break # No readstring + if RdStrSplit[0] == "0": break # Read 0 error:R&S + if RdStrSplit[0] == "+0": break # Read 0 error:Other + if 'Page Could not be Displayed' in RdStrSplit[0]: break # For html testing socket self.dLastErr = RdStr - if self.debug: print("jav_ClrErr: %s-->%s"%(self.Model,RdStr)) - except: #Instrument does not support SYST:ERR? + if self.debug: print("jav_ClrErr: %s-->%s"%(self.Model, RdStr)) + except: # Instrument does not support SYST:ERR? if self.debug: print("jav_ClrErr: %s-->SYST:ERR not Supported"%(self.Model)) return ErrList @@ -69,9 +69,9 @@ def jav_fileout(self, fily, outstr): def jav_IDN(self): """query *IDN? Assign data to properties""" - self.dataIDN = "Temp" #Temp for self.query + self.dataIDN = "Temp" # Temp for self.query self.dataIDN = self.query("*IDN?").strip() - if (self.dataIDN != "") and ('' not in self.dataIDN): #Data Returned? + if (self.dataIDN != "<notRead>") and ('<title>' not in self.dataIDN): # Data Returned? IDNStr = self.dataIDN.split(',') try: self.Make = IDNStr[0] @@ -81,24 +81,24 @@ def jav_IDN(self): except: pass else: - self.dataIDN = "" #Reset if not read + self.dataIDN = "" # Reset if not read return self.dataIDN def jav_logscpi(self): - self.f = rssd.FileIO() #pylint:disable=E1101 - self.f.init("yaVISA") #pylint:disable=W0612 + self.f = rssd.FileIO() # pylint:disable=E1101 + self.f.init("yaVISA") # pylint:disable=W0612 def jav_OPC_Wait(self, InCMD): """ Wait based on *OPC """ start_time = time.time() - self.write("*ESE 1") #Event Status Enable - self.write("*SRE 32") #ServiceReqEnable-Bit5:Std Event - self.write(InCMD + ";*OPC") #Initiate Read. *OPC will trigger ESR - #print (' OPC Wait: ' +InCMD) + self.write("*ESE 1") # Event Status Enable + self.write("*SRE 32") # ServiceReqEnable-Bit5:Std Event + self.write(InCMD + ";*OPC") # Initiate Read. *OPC will trigger ESR + # print (' OPC Wait: ' +InCMD) read = 0 - while (read & 1) != 1: #Loop until done + while (read & 1) != 1: # Loop until done try: - read = self.queryInt("*ESR?") #Poll EventStatReg-Bit0:Op Complete (STB?) + read = self.queryInt("*ESR?") # Poll EventStatReg-Bit0:Op Complete (STB?) except: if self.debug: print("jav_OPCWai:*ESR? Error") time.sleep(0.5) @@ -110,14 +110,14 @@ def jav_OPC_Wait(self, InCMD): self.jav_ClrErr() return delta - def jav_Open(self, sIPAddr,fily='',port=5025): - #***************************************************************** - #*** Open raw socket Connection - #***************************************************************** + def jav_Open(self, sIPAddr, fily='', port=5025): + # ***************************************************************** + # *** Open raw socket Connection + # ***************************************************************** self.K2 = socket.socket() try: self.K2.settimeout(0.3) - self.K2.connect((sIPAddr,port)) + self.K2.connect((sIPAddr, port)) self.jav_IDN() self.jav_fileout(fily, self.dataIDN) self.jav_ClrErr() @@ -126,13 +126,13 @@ def jav_Open(self, sIPAddr,fily='',port=5025): self.K2 = 'NoSOCKET' return self - def jav_Open_Basic(self, sIPAddr,fily='',port=5025): + def jav_Open_Basic(self, sIPAddr, fily='', port=5025): """ Open raw socket Connection No IDN or Error checking""" self.K2 = socket.socket() try: self.K2.settimeout(1) - self.K2.connect((sIPAddr,port)) + self.K2.connect((sIPAddr, port)) self.dataIDN = 'jav_Open_Basic' self.jav_fileout(fily, self.dataIDN) except: @@ -152,9 +152,9 @@ def jav_reslist(self): print('Socket does not support Resource list') return ["No VISA"] - def jav_scpilist(self,SCPIList): + def jav_scpilist(self, SCPIList): """Send SCPI list & Query if "?" """ - ### Collect read results into a list for return. + # ## Collect read results into a list for return. OutList = [] for cmd in SCPIList: if cmd.find('?') == -1: @@ -167,11 +167,11 @@ def jav_scpilist(self,SCPIList): def jav_Wait(self, InCMD): """Brute Force Wait and check *OPC? """ start_time = time.time() - self.write(InCMD) #Initiate Command + self.write(InCMD) # Initiate Command read = "0" - while (int(read) & 1) != 1: #Loop until done + while (int(read) & 1) != 1: # Loop until done try: - read = self.queryInt("*OPC?") #See if we can get *OPC? + read = self.queryInt("*OPC?") # See if we can get *OPC? except: pass time.sleep(2) @@ -182,62 +182,62 @@ def jav_Wait(self, InCMD): if self.debug: print('jav_Wai : %0.2fsec'%(delta)) return delta - def query(self,cmd): - read ="<notRead>" + def query(self, cmd): + read = "<notRead>" try: if self.dataIDN != "": cmd = cmd + '\n' - self.K2.sendall(cmd.encode()) #Write if connected - sOut = self.K2.recv(10000).strip() #read socket + self.K2.sendall(cmd.encode()) # Write if connected + sOut = self.K2.recv(10000).strip() # read socket read = sOut.decode() except: - if self.debug: print("jav_RdErr : %s-->%s"%(self.Model,cmd)) - self.jav_fileout(self.f, "%s,%s,%s"%(self.Model,cmd,read)) + if self.debug: print("jav_RdErr : %s-->%s"%(self.Model, cmd)) + self.jav_fileout(self.f, "%s,%s,%s"%(self.Model, cmd, read)) return read - def queryFloat(self,cmd): + def queryFloat(self, cmd): try: strArry = self.query(cmd).split(',') return [float(i) for i in strArry][0] except: return -9999.9999 - def queryFloatArry(self,cmd): + def queryFloatArry(self, cmd): try: strArry = self.query(cmd).split(',') return [float(i) for i in strArry] except: return [-9999.9999, -888.888, -777.777, -666.666, -555.555, -444.444] - def queryInt(self,cmd): + def queryInt(self, cmd): try: strArry = self.query(cmd).split(',') return [int(i) for i in strArry][0] except: return -9999 - def queryIntArry(self,cmd): + def queryIntArry(self, cmd): try: strArry = self.query(cmd).split(',') return [int(i) for i in strArry] except: - return [-9999,-8888,-7777] + return [-9999, -8888, -7777] - def write(self,cmd): + def write(self, cmd): try: out = cmd + self.EOL - if self.dataIDN != "": self.K2.sendall(out.encode()) #Write if connected + if self.dataIDN != "": self.K2.sendall(out.encode()) # Write if connected except: - if self.debug: print("jav_WrtErr: %s-->%s"%(self.Model,cmd)) - self.jav_fileout(self.f, "%s,%s"%(self.Model,cmd)) + if self.debug: print("jav_WrtErr: %s-->%s"%(self.Model, cmd)) + self.jav_fileout(self.f, "%s,%s"%(self.Model, cmd)) - def jav_write_raw(self,SCPI): + def jav_write_raw(self, SCPI): self.K2.write(SCPI) if __name__ == "__main__": - RS = jaVisa().jav_Open_Basic("192.168.1.160",5025) + RS = jaVisa().jav_Open_Basic("192.168.1.160", 5025) RS.EOL = '\r\n' - # RS = jaVisa().jav_Open_Basic("192.168.1.50",200) + # RS = jaVisa().jav_Open_Basic("192.168.1.50", 200) # RS.EOL = '\x00' print(RS.query("*IDN?")) RS.jav_Close() diff --git a/test/test_HW_OTA_ATS1000.py b/test/test_HW_OTA_ATS1000.py index 71d2212..38f5a13 100644 --- a/test/test_HW_OTA_ATS1000.py +++ b/test/test_HW_OTA_ATS1000.py @@ -47,6 +47,6 @@ def test_OTA_SystemStat(self): self.ATS1000.Get_CxAngle() if __name__ == '__main__': -#coverage run -a -m unittest -b -v test_HW_OTA_Common +# coverage run -a -m unittest -b -v test_HW_OTA_Common suite = unittest.TestLoader().loadTestsFromTestCase(TestGeneral) unittest.TextTestRunner(verbosity=4).run(suite)