def onPartView(self): self.focus() device = self.device numPorts = device['ports'].GetValue() referenceDesignator = device['ref'].GetValue() portLine = 'port' for port in range(numPorts): portLine = portLine + ' ' + str( port + 1) + ' ' + referenceDesignator + ' ' + str(port + 1) deviceLine = device.NetListLine() netList = [deviceLine, portLine] import SignalIntegrity.Lib as si spnp = si.p.SystemSParametersNumericParser( si.fd.EvenlySpacedFrequencyList( SignalIntegrity.App. Project['CalculationProperties.EndFrequency'], SignalIntegrity. App.Project['CalculationProperties.FrequencyPoints'])) spnp.AddLines(netList) try: sp = spnp.SParameters() except si.SignalIntegrityException as e: messagebox.showerror('S-parameter Calculator', e.parameter + ': ' + e.message) return fileParts = copy.copy(self.parent.parent.fileparts) fileParts.filename = fileParts.filename + '_' + referenceDesignator spd = SParametersDialog( self.parent.parent, sp, filename=fileParts.FullFilePathExtension('s' + str(sp.m_P) + 'p')) spd.grab_set()
def onFileView(self): self.parentFrame.focus() filename = self.partProperty.GetValue() if filename != '': import SignalIntegrity.Lib as si if self.partProperty['PropertyName'] == 'filename': fp = FileParts(filename) if fp.fileext == '.si': result = os.system('SignalIntegrity ' + os.path.abspath(filename) + ' --external') if result != 0: messagebox.showerror('ProjectFile', 'could not be opened') return else: try: sp = si.sp.SParameterFile(filename) except si.SignalIntegrityException as e: messagebox.showerror('S-parameter Viewer', e.parameter + ': ' + e.message) return spd = SParametersDialog(self.parent.parent.parent, sp, filename) spd.grab_set() elif self.partProperty['PropertyName'] == 'waveformfilename': if FileParts(filename).fileext == '.si': result = os.system('SignalIntegrity ' + os.path.abspath(filename) + ' --external') if result != 0: messagebox.showerror('ProjectFile', 'could not be opened') return else: filenametoshow = ('/'.join( filename.split('\\'))).split('/')[-1] if filenametoshow is None: filenametoshow = '' try: wf = self.parent.device.Waveform() except si.SignalIntegrityException as e: messagebox.showerror('Waveform Viewer', e.parameter + ': ' + e.message) return sd = SimulatorDialog(self.parent.parent) sd.title(filenametoshow) sd.UpdateWaveforms([wf], [filenametoshow]) sd.state('normal') sd.grab_set()
def onExamineTransferMatrices(self): buttonLabelList=[[out+' due to '+inp for inp in self.parent.sourceNames] for out in self.parent.outputWaveformLabels] maxLength=len(max([item for sublist in buttonLabelList for item in sublist],key=len)) buttonLabelList=[[item.ljust(maxLength) for item in sublist] for sublist in buttonLabelList] sp=self.parent.transferMatrices.SParameters() SParametersDialog(self.parent.parent,sp, self.parent.parent.fileparts.FullFilePathExtension('s'+str(sp.m_P)+'p'), 'Transfer Parameters',buttonLabelList)
def VirtualProbe(self,TransferMatricesOnly=False): netList=self.parent.Drawing.schematic.NetList() netListText=netList.Text() import SignalIntegrity.Lib as si cacheFileName=None if SignalIntegrity.App.Preferences['Cache.CacheResults']: cacheFileName=self.parent.fileparts.FileNameTitle() si.sd.Numeric.trySVD=SignalIntegrity.App.Preferences['Calculation.TrySVD'] snp=si.p.VirtualProbeNumericParser( si.fd.EvenlySpacedFrequencyList( SignalIntegrity.App.Project['CalculationProperties.EndFrequency'], SignalIntegrity.App.Project['CalculationProperties.FrequencyPoints']), cacheFileName=cacheFileName) snp.AddLines(netListText) progressDialog=ProgressDialog(self.parent,"Transfer Parameters",snp,snp.TransferMatrices, granularity=1.0) try: self.transferMatrices=progressDialog.GetResult() except si.SignalIntegrityException as e: messagebox.showerror('Virtual Probe',e.parameter+': '+e.message) return self.transferMatriceProcessor=si.td.f.TransferMatricesProcessor(self.transferMatrices) si.td.wf.Waveform.adaptionStrategy='SinX' if SignalIntegrity.App.Preferences['Calculation.UseSinX'] else 'Linear' si.td.wf.Waveform.maximumWaveformSize = SignalIntegrity.App.Preferences['Calculation.MaximumWaveformSize'] try: self.inputWaveformList=self.parent.Drawing.schematic.InputWaveforms() self.sourceNames=netList.MeasureNames() except si.SignalIntegrityException as e: messagebox.showerror('Virtual Probe',e.parameter+': '+e.message) return if TransferMatricesOnly: buttonLabelList=[[out+' due to '+inp for inp in self.sourceNames] for out in self.outputWaveformLabels] maxLength=len(max([item for sublist in buttonLabelList for item in sublist],key=len)) buttonLabelList=[[item.ljust(maxLength) for item in sublist] for sublist in buttonLabelList] sp=self.transferMatrices.SParameters() SParametersDialog(self.parent,sp, self.parent.fileparts.FullFilePathExtension('s'+str(sp.m_P)+'p'), 'Transfer Parameters',buttonLabelList) progressDialog=ProgressDialog(self.parent,"Waveform Processing",self.transferMatriceProcessor,self._ProcessWaveforms) try: outputWaveformList = progressDialog.GetResult() except si.SignalIntegrityException as e: messagebox.showerror('Virtual Probe',e.parameter+': '+e.message) return self.outputWaveformLabels=netList.OutputNames() for outputWaveformIndex in range(len(outputWaveformList)): outputWaveform=outputWaveformList[outputWaveformIndex] outputWaveformLabel = self.outputWaveformLabels[outputWaveformIndex] for device in self.parent.Drawing.schematic.deviceList: if device['partname'].GetValue() in ['Output','DifferentialVoltageOutput','CurrentOutput','EyeProbe','DifferentialEyeProbe']: if device['ref'].GetValue() == outputWaveformLabel: # probes may have different kinds of gain specified gainProperty = device['gain'] gain=gainProperty.GetValue() offset=device['offset'].GetValue() delay=device['td'].GetValue() if gain != 1.0 or offset != 0.0 or delay != 0.0: outputWaveform = outputWaveform.DelayBy(delay)*gain+offset outputWaveformList[outputWaveformIndex]=outputWaveform break userSampleRate=SignalIntegrity.App.Project['CalculationProperties.UserSampleRate'] outputWaveformList = [wf.Adapt( si.td.wf.TimeDescriptor(wf.td.H,int(wf.td.K*userSampleRate/wf.td.Fs),userSampleRate)) for wf in outputWaveformList] self.SimulatorDialog().title('Virtual Probe: '+self.parent.fileparts.FileNameTitle()) self.SimulatorDialog().ExamineTransferMatricesDoer.Activate(True) self.SimulatorDialog().SimulateDoer.Activate(True) self.UpdateWaveforms(outputWaveformList, self.outputWaveformLabels) self.SimulatorDialog().update_idletasks() # gather up the eye probes and create a dialog for each one eyeDiagramDict=[] for outputWaveformIndex in range(len(outputWaveformList)): outputWaveform=outputWaveformList[outputWaveformIndex] outputWaveformLabel = self.outputWaveformLabels[outputWaveformIndex] for device in self.parent.Drawing.schematic.deviceList: if device['partname'].GetValue() in ['EyeProbe','DifferentialEyeProbe']: if device['ref'].GetValue() == outputWaveformLabel: eyeDict={'Name':outputWaveformLabel, 'BaudRate':device['br'].GetValue(), 'Waveform':outputWaveformList[self.outputWaveformLabels.index(outputWaveformLabel)], 'Config':device.configuration} eyeDiagramDict.append(eyeDict) break self.UpdateEyeDiagrams(eyeDiagramDict)
def Simulate(self, SParameters=False): """ simulates with a network analyzer model """ # # the first step is to calculate the s-parameters of a DUT connected to the ports # of the network analyzer. # self.parent.Drawing.stateMachine.Nothing() netList = self.parent.Drawing.schematic.NetList().Text() import SignalIntegrity.Lib as si fd = si.fd.EvenlySpacedFrequencyList( SignalIntegrity.App.Project['CalculationProperties.EndFrequency'], SignalIntegrity.App. Project['CalculationProperties.FrequencyPoints']) cacheFileName = None if SignalIntegrity.App.Preferences['Cache.CacheResults']: cacheFileName = self.parent.fileparts.FileNameTitle( ) + '_DUTSParameters' si.sd.Numeric.trySVD = SignalIntegrity.App.Preferences[ 'Calculation.TrySVD'] spnp = si.p.DUTSParametersNumericParser(fd, cacheFileName=cacheFileName) spnp.AddLines(netList) progressDialog = ProgressDialog(self.parent, "Calculating DUT S-parameters", spnp, spnp.SParameters, granularity=1.0) try: (DUTSp, NetworkAnalyzerProjectFile) = progressDialog.GetResult() showDutsp = False if showDutsp: from SignalIntegrity.App.SParameterViewerWindow import SParametersDialog self.spd = self.spd = SParametersDialog( self.parent, DUTSp, filename=self.parent.fileparts.FullFilePathExtension( 's' + str(DUTSp.m_P) + 'p')) except si.SignalIntegrityException as e: messagebox.showerror('DUT S-parameter Calculator', e.parameter + ': ' + e.message) return None # # DUTSp now contains the s-parameters of the DUT. The DUT has a number of ports dictated by how many ports were actually connected # to the network analzyer, and the port connections are in spnp.NetworkAnalyzerPortConnectionList # # The next step is to get the netlist from the network analyzer model's project # netListText = None if NetworkAnalyzerProjectFile != None: level = SignalIntegrityAppHeadless.projectStack.Push() try: app = SignalIntegrityAppHeadless() if app.OpenProjectFile( os.path.realpath(NetworkAnalyzerProjectFile)): app.Drawing.DrawSchematic() netList = app.Drawing.schematic.NetList() netListText = netList.Text() else: raise SignalIntegrityExceptionNetworkAnalyzer( 'file could not be opened: ' + NetworkAnalyzerProjectFile) except SignalIntegrityException as e: messagebox.showerror('Network Analyzer Model: ', e.parameter + ': ' + e.message) finally: SignalIntegrityAppHeadless.projectStack.Pull(level) else: netList = self.parent.Drawing.schematic.NetList() netListText = self.parent.NetListText() if netListText == None: return # # Now, with the dut s-parameters and the netlist of the network analyzer model, get the transfer matrices for a simulation with the DUT # using the network analyzer model. # cacheFileName = self.parent.fileparts.FileNameTitle( ) + '_TransferMatrices' if SignalIntegrity.App.Preferences[ 'Cache.CacheResults'] else None si.sd.Numeric.trySVD = SignalIntegrity.App.Preferences[ 'Calculation.TrySVD'] snp = si.p.NetworkAnalyzerSimulationNumericParser( fd, DUTSp, spnp.NetworkAnalyzerPortConnectionList, cacheFileName=cacheFileName) snp.AddLines(netListText) progressDialog = ProgressDialog(self.parent, "Calculating Transfer Matrices", snp, snp.TransferMatrices, granularity=1.0) level = SignalIntegrityAppHeadless.projectStack.Push() try: os.chdir( FileParts(os.path.abspath( NetworkAnalyzerProjectFile)).AbsoluteFilePath()) self.transferMatrices = progressDialog.GetResult() except si.SignalIntegrityException as e: messagebox.showerror('Transfer Matrices Calculation: ', e.parameter + ': ' + e.message) return None finally: SignalIntegrityAppHeadless.projectStack.Pull(level) self.sourceNames = snp.m_sd.SourceVector() # # to clear up any confusion, if the DUT was not connected to all of the network analyzer ports, a multi-port DUT with # opens on the unconnected ports was constructed and connected as the DUT, but it was remembered which network # analyzer ports are actually driven. The driven ports, in order, are the first names in self.sourceNames with # snp.simulationNumPorts containing the number of them. # # In other words, if a single-port reflect calibration is performed on port 2 of the network analyzer, a two-port # DUT was installed, with an open on port 1, and the transfer parameters were computed for only the outputs needed # (the superfluous probe outputs were removed). self.sourceNames would contain only the reference designator for # the transmitter that is on port 2, followed by any other waveforms supplied to the system (usuaully noise). # # Now, we loop over all of the transmitters that are driven and create a list of lists, where each element in the list # is a list of input waveforms to be used in the simulation under that driven condition. We do this by first, setting # all of the transmitters in the appropriate on/off state, and then gathering all of the waveforms. # gdoDict = {} self.wflist = [] if NetworkAnalyzerProjectFile != None: level = SignalIntegrityAppHeadless.projectStack.Push() try: app = SignalIntegrityAppHeadless() if app.OpenProjectFile( os.path.realpath(NetworkAnalyzerProjectFile)): app.Drawing.DrawSchematic() # get output gain, offset, delay for name in [rdn[2] for rdn in snp.m_sd.pOutputList]: gdoDict[name] = { 'gain': float(app.Device(name)['gain']['Value']), 'offset': float(app.Device(name)['offset']['Value']), 'delay': float(app.Device(name)['td']['Value']) } for driven in range(snp.simulationNumPorts): for port in range(snp.simulationNumPorts): app.Device(self.sourceNames[port])['state'][ 'Value'] = 'on' if port == driven else 'off' self.wflist.append([ app.Device(self.sourceNames[wfIndex]).Waveform() for wfIndex in range(len(self.sourceNames)) ]) else: raise SignalIntegrityExceptionNetworkAnalyzer( 'file could not be opened: ' + NetworkAnalyzerProjectFile) except SignalIntegrityException as e: messagebox.showerror('Network Analyzer Model: ', e.parameter + ': ' + e.message) finally: SignalIntegrityAppHeadless.projectStack.Pull(level) else: # since we're modifying the current schematic, keep the state for restoring stateList = [ app.Device(self.sourceNames[port])['state']['Value'] for port in range(snp.simulationNumPorts) ] for name in [rdn[2] for rdn in snp.m_sd.pOutputList]: gdoDict[name] = { 'gain': float(app.Device()[name]['gain']['Value']), 'offset': float(app.Device()[name]['offset']['Value']), 'delay': float(app.Device()[name]['td']['Value']) } for driven in range(snp.simulationNumPorts): for port in range(snp.simulationNumPorts): app.Device( self.sourceNames[port] )['state']['Value'] = 'on' if port == driven else 'off' self.wflist.append([ app.Device(self.sourceNames[wfIndex]).Waveform() for wfIndex in range(len(self.sourceNames)) ]) # restore the states for port in range(snp.simulationNumPorts): app.Device( self.sourceNames[port])['state']['Value'] = stateList[port] # # Now, the list of list of input waveforms are processed, generating a list of list of output waveforms in # self.outputwflist. # self.transferMatriceProcessor = si.td.f.TransferMatricesProcessor( self.transferMatrices) si.td.wf.Waveform.adaptionStrategy = 'SinX' if SignalIntegrity.App.Preferences[ 'Calculation.UseSinX'] else 'Linear' progressDialog = ProgressDialog(self.parent, "Waveform Processing", self.transferMatriceProcessor, self._ProcessWaveforms) try: outputWaveformList = progressDialog.GetResult() except si.SignalIntegrityException as e: messagebox.showerror('Simulator', e.parameter + ': ' + e.message) return # # The list of list of input waveforms have been processed processed, generating a list of list of output waveforms in # self.outputwflist. The names of the output waveforms are in snp.m_sd.pOutputList. # self.outputwflist = [[ wf.Adapt( si.td.wf.TimeDescriptor(wf.td[wf.td.IndexOfTime(-5e-9)], fd.TimeDescriptor().K, wf.td.Fs)) for wf in driven ] for driven in self.outputwflist] # The port connection list, which is a list of True or False for each port on the network analyzer, is # converted to a list of network port indices corresponding to the driven ports. # portConnections = [] for pci in range(len(snp.PortConnectionList)): if snp.PortConnectionList[pci]: portConnections.append(pci) # Here, the output waveforms are refined by applying any probe gain, offset, and delay, and the # waveform labels are converted to a list of list of waveform labels, with the driven port appended. outputWaveformList = [] self.outputWaveformLabels = [] for r in range(len(self.outputwflist)): wflist = self.outputwflist[r] for c in range(len(wflist)): wf = wflist[c] wfName = snp.m_sd.pOutputList[c][2] gain = gdoDict[wfName]['gain'] offset = gdoDict[wfName]['offset'] delay = gdoDict[wfName]['delay'] if gain != 1.0 or offset != 0.0 or delay != 0.0: wf = wf.DelayBy(delay) * gain + offset outputWaveformList.append(wf) self.outputWaveformLabels.append(wfName + str(portConnections[r] + 1)) userSampleRate = SignalIntegrity.App.Project[ 'CalculationProperties.UserSampleRate'] outputWaveformList = [ wf.Adapt( si.td.wf.TimeDescriptor( wf.td.H, int(wf.td.K * userSampleRate / wf.td.Fs), userSampleRate)) for wf in outputWaveformList ] td = si.td.wf.TimeDescriptor( -5e-9, SignalIntegrity.App.Project['CalculationProperties.TimePoints'], SignalIntegrity.App.Project['CalculationProperties.BaseSampleRate'] ) frequencyList = td.FrequencyList() if snp.simulationType != 'CW': # note this matrix is transposed from what is normally expected Vmat = [[ outputWaveformList[self.outputWaveformLabels.index( 'V' + str(portConnections[r] + 1) + str(portConnections[c] + 1))] for r in range(len(portConnections)) ] for c in range(len(portConnections))] for vli in range(len(Vmat)): tdr = si.m.tdr.TDRWaveformToSParameterConverter( WindowForwardHalfWidthTime=500e-12, WindowReverseHalfWidthTime=500e-12, WindowRaisedCosineDuration=250e-12, Step=(snp.simulationType == 'TDRStep'), Length=0, Denoise=(snp.simulationType != 'TDRStep'), DenoisePercent=20., Inverted=False, fd=frequencyList) tdr.Convert(Vmat[vli], vli) for r in range(len(portConnections)): outputWaveformList.append(tdr.IncidentWaveform if r == vli else si.td.wf.Waveform(td)) self.outputWaveformLabels.append( 'A' + str(portConnections[r] + 1) + str(portConnections[vli] + 1)) for r in range(len(portConnections)): outputWaveformList.append(tdr.ReflectWaveforms[r]) self.outputWaveformLabels.append( 'B' + str(portConnections[r] + 1) + str(portConnections[vli] + 1)) if not SParameters: self.SimulatorDialog().title('Sim: ' + self.parent.fileparts.FileNameTitle()) self.SimulatorDialog().ExamineTransferMatricesDoer.Activate(True) self.SimulatorDialog().SimulateDoer.Activate(True) self.SimulatorDialog().ViewTimeDomainDoer.Set( snp.simulationType != 'CW') self.SimulatorDialog().ViewTimeDomainDoer.Activate( snp.simulationType != 'CW') self.SimulatorDialog().ViewSpectralContentDoer.Set( snp.simulationType == 'CW') self.SimulatorDialog().ViewSpectralDensityDoer.Set(False) self.UpdateWaveforms(outputWaveformList, self.outputWaveformLabels) else: frequencyContentList = [ wf.FrequencyContent(fd) for wf in outputWaveformList ] Afc = [[ frequencyContentList[self.outputWaveformLabels.index( 'A' + str(portConnections[r] + 1) + str(portConnections[c] + 1))] for c in range(len(portConnections)) ] for r in range(len(portConnections))] Bfc = [[ frequencyContentList[self.outputWaveformLabels.index( 'B' + str(portConnections[r] + 1) + str(portConnections[c] + 1))] for c in range(len(portConnections)) ] for r in range(len(portConnections))] from numpy import matrix data = [None for _ in range(len(frequencyList))] for n in range(len(frequencyList)): B = [[Bfc[r][c][n] for c in range(snp.simulationNumPorts)] for r in range(snp.simulationNumPorts)] A = [[Afc[r][c][n] for c in range(snp.simulationNumPorts)] for r in range(snp.simulationNumPorts)] data[n] = (matrix(B) * matrix(A).getI()).tolist() sp = si.sp.SParameters(frequencyList, data) return sp
def onPartView(self): self.focus() device = self.device numPorts = device['ports'].GetValue() referenceDesignator = device['ref'].GetValue() portLine = 'port' for port in range(numPorts): portLine = portLine + ' ' + str( port + 1) + ' ' + referenceDesignator + ' ' + str(port + 1) deviceLine = device.NetListLine() netList = [deviceLine, portLine] import SignalIntegrity.Lib as si spnp = si.p.SystemSParametersNumericParser( si.fd.EvenlySpacedFrequencyList( SignalIntegrity.App. Project['CalculationProperties.EndFrequency'], SignalIntegrity. App.Project['CalculationProperties.FrequencyPoints'])) spnp.AddLines(netList) try: sp = spnp.SParameters() except si.SignalIntegrityException as e: messagebox.showerror('S-parameter Calculator', e.parameter + ': ' + e.message) return fileParts = copy.copy(self.parent.parent.fileparts) fileParts.filename = fileParts.filename + '_' + referenceDesignator spd = SParametersDialog( self.parent.parent, sp, filename=fileParts.FullFilePathExtension('s' + str(sp.m_P) + 'p')) try: import platform thisOS = platform.system() if thisOS == 'Linux': spd.attributes('-type', 'dialog') elif thisOS == 'Windows': spd.attributes('-toolwindow', True) def disable_event(): pass self.parent.protocol("WM_DELETE_WINDOW", disable_event) spd.attributes('-topmost', 1) spd.focus_set() spd.grab_set() # spd.transient(self.parent) self.wait_window(spd) finally: self.parent.protocol("WM_DELETE_WINDOW", self.parent.cancel)
def onFileView(self): self.parentFrame.focus() filename = self.partProperty.GetValue() if filename != '': import SignalIntegrity.Lib as si if FileParts(filename).fileext == '.si': result = os.system('SignalIntegrity "' + os.path.abspath(filename) + '" --external') if result != 0: messagebox.showerror('ProjectFile', 'could not be opened') return elif self.partProperty['PropertyName'] == 'filename': try: sp = si.sp.SParameterFile(filename) except si.SignalIntegrityException as e: messagebox.showerror('S-parameter Viewer', e.parameter + ': ' + e.message) return spd = SParametersDialog(self.parent.parent.parent, sp, filename) try: spd.grab_set() spd.focus_set() import platform thisOS = platform.system() if thisOS == 'Linux': spd.attributes('-type', 'dialog') elif thisOS == 'Windows': spd.attributes('-toolwindow', True) def disable_event(): pass self.parent.parent.protocol("WM_DELETE_WINDOW", disable_event) spd.attributes('-topmost', 1) # spd.transient(self.parent.parent) self.wait_window(spd) finally: self.parent.parent.protocol("WM_DELETE_WINDOW", self.parent.parent.cancel) elif self.partProperty['PropertyName'] == 'waveformfilename': filenametoshow = ('/'.join( filename.split('\\'))).split('/')[-1] if filenametoshow is None: filenametoshow = '' try: wf = self.parent.device.Waveform() except si.SignalIntegrityException as e: messagebox.showerror('Waveform Viewer', e.parameter + ': ' + e.message) return sd = SimulatorDialog(self.parent.parent) sd.title(filenametoshow) sd.UpdateWaveforms([wf], [filenametoshow]) sd.state('normal') try: import platform thisOS = platform.system() if thisOS == 'Linux': sd.attributes('-type', 'dialog') elif thisOS == 'Windows': sd.attributes('-toolwindow', True) def disable_event(): pass self.parent.parent.protocol("WM_DELETE_WINDOW", disable_event) sd.attributes('-topmost', 1) sd.focus_set() sd.grab_set() # sd.transient(self.parent.parent) self.wait_window(sd) finally: self.parent.parent.protocol("WM_DELETE_WINDOW", self.parent.parent.cancel) elif self.partProperty['PropertyName'] == 'errorterms': calibration = self.parent.parent.parent.OpenCalibrationFile( os.path.abspath(filename)) if calibration is None: messagebox.showerror('Calibration File', 'could not be opened') return else: self.parent.parent.parent.ViewCalibration(calibration)