def take_waveform(host, model, active_sources, waveform_format=None): dev = vxi11.Instrument("TCPIP::" + host + "::INSTR") dev.open() dev = vxi11.Instrument("TCPIP::" + host + "::INSTR") dev.open() dev.io_timeout = 10 if model in ['TDS5104', 'TDS7704']: raise ('not supported') elif model in ['MSO54', 'MSO56', 'MSO58', 'MSO64']: waveforms = {} for source in active_sources: dev.write('SAVE:WAVEFORM {},"waveform.wfm"'.format(source)) dev.write('*OPC?') while '1' not in dev.read(): time.sleep(0.01) save_time += 1 dev.write('*OPC?') if save_time > 10000: raise Exception( 'save waveform takes longer than 10 seconds') dev.write(r'FILESYSTEM:READFILE "waveform.wfm"') waveforms[source] = dev.read_raw() dev.write(r'FILESYSTEM:DELETE "waveform.wfm"') dev.close() return waveforms
def pressDoA(): if OSCPN in ('DPO5', 'DPO7', 'MSO5', 'DSA7', 'DSO7'): inst = vxi11.Instrument(OSCIP) inst.write('HORizontal:MODE constant') if scale != '': temp = 'HORizontal:MODE:SCAle ' + scale inst.write(temp) if recordLength != '': temp = 'HORizontal:MODE:RECOrdlength ' + recordLength inst.write(temp) if sampleRate != '': temp = 'HORizontal:MODE:SAMPLERate ' + sampleRate inst.write(temp) inst.close() print(temp) elif OSCPN in ('MDO4', 'MSO4', 'DPO4', 'MDO3'): inst = vxi11.Instrument(OSCIP) if scale != '': temp = 'HORizontal:SCAle ' + scale inst.write(temp) if recordLength != '': temp = 'HORizontal:RECOrdlength ' + recordLength inst.write(temp) if sampleRate != '': temp = 'HORizontal:SAMPLERate ' + sampleRate inst.write(temp) inst.close() print(temp)
def pressConnect(): global OSCIP #示波器IP地址 global PCIP #本地IP地址 global OSCPN #示波器型号 global ConnFlag #示波器连接状态 OSCIP = 'TCPIP::' + window.Element('OSCIP').get() + '::INSTR' PCIP = 'HARDCopy:PRINTer:ADD "labprn2", "", "' + window.Element( 'PCIP').get() + '"' try: inst = vxi11.Instrument(OSCIP) inst.ask('*IDN?') inst.close() except: window.Element('TCONN').Update('连接失败') ConnFlag = 0 print('connected failed. Please check your IP and Device') else: window.Element('TCONN').Update('已连接') ConnFlag = 1 inst = vxi11.Instrument(OSCIP) inst.write('*IDN?') OSCPN = inst.read().split(',')[1] print('connected with ' + OSCPN) OSCPN = OSCPN[0:4] print(OSCPN)
def create_generator(instr_info): """ Create the appropiate generator object given the instr_info dictionary. :param instr_info: generator instrument info dictionary. The instr_info format is: {'instr_type' : type of generator, defined by the command keywords. 'connection' : type of connection in Visa format. See https://pyvisa.readthedocs.io/en/stable/names.html 'def_freq' : Default frequency to use when not specified (in MHz). 'def_power' : Default power level to use when not specified (in dBm). } :param print_msgs: True: print command messages. False: do not. :return: Generator object. """ from scpi_generator import ScpiGenerator from anritsu_generator import AnritsuGenerator from sim_generator import SimGenerator # create the proper generator object with the correct inctruction keywords if instr_info['type'] == 'scpi': instr = vxi11.Instrument(instr_info['connection']) return ScpiGenerator(instr, instr_info) elif instr_info['type'] == 'anritsu': instr = vxi11.Instrument(instr_info['connection']) return AnritsuGenerator(instr, instr_info) elif instr_info['type'] == 'sim': return SimGenerator(None, instr_info) else: print("Error: Instrument type " + instr_info['type'] + "not recognized.") exit()
def scriptSave(fileName): if OSCPN in ('DPO5', 'DPO7', 'MSO5', 'DSA7', 'DSO7'): inst = vxi11.Instrument(OSCIP) inst.write('HARDCOPY:PORT FILE') inst.write('HARDCOPY:FILENAME "C:/Windows/temp"') inst.write('Hardcopy start') time.sleep(0.5) inst.write('filesystem:readfile "C:/Windows/temp.png"') image = inst.read_raw() filePath = window.Element('pathF').get() temp = filePath + '/' + fileName + ".png" print('save to:' + temp) my_file = open(temp, "wb") my_file.write(image) inst.write('FILESystem:DELEte "C:/Windows/temp.png"') inst.close() elif OSCPN in ('MDO4', 'MSO4', 'DPO4', 'MDO3'): inst = vxi11.Instrument(OSCIP) inst.write(PCIP) inst.write('HARDCopy:ACTIVeprinter "labprn2"') inst.write('Hardcopy start') image = inst.read_raw() filePath = window.Element('pathF').get() temp = filePath + '/' + fileName + ".png" print('save to:' + temp) my_file = open(temp, "wb") my_file.write(image) my_file.close() inst.close() window.refresh()
def __init__(self, connection_type, host, port): self.connection_type = connection_type self.host = host self.port = port if (connection_type == 'serial'): self.com = TCPLink(host, port) elif (connection_type == 'lan'): self.com = TCPLink(host, port) elif (connection_type == 'lan_udp'): self.com = UDPLink(host, port) self.com.open() self.com._socket.bind(('', port)) self.com._socket.settimeout(0.1) self.com.settimeout(0.1) elif (connection_type == 'gpib'): sPort = 'gpib0,%i' % port self.com = vxi11.Instrument(host, sPort) elif (connection_type == 'gpibSerial'): sPort = 'COM1,488' self.com = vxi11.Instrument(host, sPort) #This probably will solely work with Keysight E5810B elif (connection_type == 'usb'): self.com = serial.Serial(host, 9600) elif (connection_type == 'prologix'): self.com = Prologix(host, port) self.com.open() else: pass
def command2(): send2 = str(u.get()) if returnEntry() == "": time_instr = vxi11.Instrument("TCPIP::" + result + "::inst1::INSTR") time_instr.write('set:pin.E' + send2 + ':on') else: time_instr = vxi11.Instrument("TCPIP::" + returnEntry() + "::inst1::INSTR") time_instr.write('set:pin.E' + send2 + ':on')
def scriptSetLabel(CH1, CH1Name): if OSCPN in ('DPO5', 'DPO7', 'MSO5', 'DSA7', 'DSO7'): inst = vxi11.Instrument(OSCIP) temp = CH1 + ':LABel:NAMe ' + '"' + CH1Name + '"' inst.write(temp) print(temp) inst.close() elif OSCPN in ('MDO4', 'MSO4', 'DPO4', 'MDO3'): inst = vxi11.Instrument(OSCIP) temp = CH1 + ':LABel ' + '"' + CH1Name + '"' inst.write(temp) print(temp) inst.close()
def __init__(self, host): try: self.conn = vxi11.Instrument(host) self.dType = self.conn.ask('*IDN?') print self.dType except Exception as e: print e
def setTimebaseOffsetLe(self, text): self.properties['timebase']['offset'] = toFloat(text) scope = vxi11.Instrument(self.properties['main']['ip']) scope.write(':TIM:OFFS %f' % toFloat(text))
def setTimebaseScaleLe(self, text): self.properties['timebase']['scale'] = toFloat(text) scope = vxi11.Instrument(self.properties['main']['ip']) scope.write(':TIM:SCAL %f' % toFloat(text))
def setTriggerHoldoff(self, text): h = toFloat(text) self.properties['trigger']['holdoff'] = h scope = vxi11.Instrument(self.properties['main']['ip']) scope.write(':TRIG:HOLD {}'.format(h))
def setCurrentSettings(self): scope = vxi11.Instrument(self.properties['main']['ip']) for channel in (1, 2, 3, 4): d = self.properties['channel{}'.format(channel)] d['coupling'] = scope.ask(':CHAN{}:COUP?'.format(channel)) d['offset'] = float(scope.ask(':CHAN{}:OFFS?'.format(channel))) d['scale'] = float(scope.ask(':CHAN{}:SCAL?'.format(channel))) d['probe'] = float(scope.ask(':CHAN{}:PROB?'.format(channel))) tb = self.properties['timebase'] tb['scale'] = float(scope.ask(':TIM:SCAL?')) tb['offset'] = float(scope.ask(':TIM:OFFS?')) modes = { 'EDGE': 'edge', 'PULS': 'pulse', 'SLOP': 'slope', 'VID': 'video' } sweep = {'NORM': 'normal', 'AUTO': 'auto', 'SING': 'single'} trg = self.properties['trigger'] trg['mode'] = modes[scope.ask(':TRIG:MODE?')] trg['sweep'] = sweep[scope.ask(':TRIG:SWE?')] self.setVisuals()
def __init__( self, interface='eth0'): # interface is the network interface that the DT8824 is connected to self.ip = get_ip_address(interface) # get IP self.vx_handle = vxi11.Instrument(self.ip) # open instrument # check IDN string self.idn = self.vx_handle.ask('*IDN?').split(',') if self.idn[0]=='Data Translation' and self.idn[1]=='DT8824': pass else: raise ValueError('Incorrect IDN string: '.format(out)) # enable password protected commands response = self.ask(':SYST:PASS:CEN:STAT?') if(int(response) == 0): # commands already enabled if response == 1 # try to enable it self.write(':SYST:PASS:CEN admin') time.sleep(0.1) # wait 100ms response = self.ask(':SYST:PASS:CEN:STAT?') if(int(response) == 0): # commands now enabled raise ValueError('Could not enable password protected commands.') # set variables self.running = False self.istream = 0 self.nstream = 0 # setup self.get_frequency(); # check frequency settings self.get_channels(); # check channel settings self.get_gain(); self.get_buffer_type();
def __init__(self, ip, gpib_address, lock, title='Keithley 237'): self.title = title logging.debug(self.title + ' init started') self.lock = lock self.ip = ip self.gpib_address = gpib_address self.lock.acquire() try: self.instr = vxi11.Instrument(self.ip, "gpib0," + str(self.gpib_address)) self.instr.clear() self.instr.write("J0X") # Factory init self.instr.write("F0,0X") # Source V DC self.instr.write("H0X") # Immediate trigger self.instr.write( "G4,2,0X") # Output measure value with no prefix, no suffix self.instr.write("S3X") # 20ms integration time self.instr.write("V1X") # Enable 1000V range self.instr.write("B7.1,0,0X") # Bias 7.1V autorange self.instr.write("L500E-6,4X") # 500µA compliance auto range self.instr.close() except: logging.error("Error in %s __init__" % self.title, exc_info=True) pass finally: self.lock.release()
def TDSwfm_meas(ip, mes): """Return the wanted measure :param ip: IP Address of the oscilloscope :type ip: str :param mes: Measure to return, see note for more informations :type mes: str :return: *measure* :rtype: str .. note:: Available measures : AMPlitude, AREa, BURst, CARea, CMEan, CRMs, DELAY, FALL, FREQuency, HIGH, LOW, MAXimum, MEAN, MINImum, NDUty, NOVershoot, NWIdth, PDUty, PERIod, PHASE, PK2pk, POVershoot, PWIdth, RISe, RMS """ ######### #AMPlitude | AREa | BURst | CARea | CMEan | #CRMs | DELAY | FALL | FREQuency | HIGH | LOW | #MAXimum | MEAN | MINImum | NDUty | NOVershoot | #NWIdth | PDUty | PERIod | PHASE | PK2pk | POVershoot | #PWIdth | RISe | RMS ######### try: instr = vxi11.Instrument(ip) EOL = '\n' instr.write('measurement:immed:type ' + mes) a = instr.ask('measurement:immed:value?' + EOL) instr.close() return a except: return 'error'
def initialize(self, config): ''' The followings will be loaded after server starts. ''' super(AFG31052, self).initialize(config) self.vxi11 = vxi11.Instrument(self.vxi11_address) self.vxi11.timeout = self.timeout # ENTER SEQ MODE command = 'SEQC:STAT ON' self.vxi11.write(command) # Set sampling rate = 2 MS/s command = 'SEQC:SRAT 2E6' self.vxi11.write(command) # SET sequence run mode to Trigger mode command = 'SEQC:RMOD TRIG' self.vxi11.write(command) # SET external trigger for sequence-trigger mode, there is only 1 element in this mode command = 'SEQ:ELEM:TWA:EVEN EXT' self.vxi11.write(command) # SET rising edge for trigger input command = 'SEQ:ELEM:TWA:SLOP POS' self.vxi11.write(command) command = 'OUTP1:STAT ON' self.vxi11.write(command) command = 'OUTP2:STAT ON' self.vxi11.write(command) # LOAD waveforms lists from USB for waveform in self.waveforms: command = 'WLIS:WAV:IMP "{}"'.format(waveform) self.vxi11.write(command)
def _open(self): if self._backend == 'pyVISA': self._port = visa.ResourceManager() \ .open_resource(self._connection['port'], write_termination= self._write_termination, read_termination= self._read_termination) # timeout has to be in ms self._port.timeout = float(self._connection.get('timeout', 5)) * 1000 elif self._backend == 'linux-gpib': con = re.findall(r'\d+', self._connection['port']) self._port = gpib.dev(int(con[0]), int(con[1])) elif self._backend == 'pySerial': if not self._port.is_open: self._port.open() elif self._backend == 'pyDAQmx': pass elif self._backend in ['usbtmc', 'usbtmcWR']: self._port.open() elif self._backend == "file": file = Path(self._port) if not file.is_file(): self.log.warning("Path ist not a file! Check your port settings in config file!") #pylint: disable=line-too-long elif self._backend == "vxi11": self._port = vxi11.Instrument(self._connection["port"].replace( "vxi11://", "")) elif self._backend == "modbus": self._port.open()
def run(self): retdict = {} self.scope = vxi11.Instrument(self.ip) general = self.scope.ask(':SOUR%d:APPL?' % self.channel) general = general.split(',') retdict['shape'] = general[0].lower() retdict['frequency'] = float(general[1]) retdict['voltage'] = float(general[2]) retdict['offset'] = float(general[3]) retdict['phase'] = float(general[4]) retdict['duty'] = float( self.scope.ask(':SOUR%d:PULS:DCYC?' % self.channel)) retdict['symmetry'] = float( self.scope.ask(':SOUR%d:FUNC:RAMP:SYMM?' % self.channel)) if retdict['shape'] == 'squ': retdict['shape'] = 'square' elif retdict['shape'] in ('puls', 'nois'): retdict['shape'] += 'e' elif retdict['shape'] == 'user': retdict['shape'] = self.scope.ask(':SOUR%d:FUNC:SHAP?' % self.channel) if retdict['shape'] == 'EXT': retdict['shape'] = 'custom' self.updateInfo.emit(retdict)
def open_interfaces(ipadd): """ open a vxi11 instrument and assign it to the global the_vx_ifc """ global the_vx_ifc #pylint: disable=W0603,C0103 print('opening VXI-11 at %s ...' % ipadd, end=' ') the_vx_ifc = vxi11.Instrument(ipadd) print('done')
def take_screenshot_png(host, fullscreen=True): dev = vxi11.Instrument("TCPIP::" + host + "::INSTR") dev.open() dev.write(':DISPLAY:DATA? PNG') img_data = binary_block(dev.read_raw()) dev.close() return img_data
def pressWrite(command): inst = vxi11.Instrument(OSCIP) if command != '': value = command.split('>>') if value[0] == 'wait': print('wait 2s') window.refresh() time.sleep(2) elif value[0] == 'save': scriptSave(value[1]) elif value[0] == '#': pass elif value[0] == 'rise': scriptMeasRise(value[1]) elif value[0] == 'fall': scriptMeasFall(value[1]) elif value[0] == 'freq': scriptMeasFreq(value[1]) elif value[0] == 'high': scriptMeasVHigh(value[1]) elif value[0] == 'low': scriptMeasVLow(value[1]) elif value[0] == 'time': scriptTime(value[1], value[2]) elif value[0] == 'data': scriptData(value[1], value[2]) elif value[0] == 'delay': scriptMeasDelay(value[1], value[2], value[3], value[4]) elif value[0] == 'label': scriptSetLabel(value[1], value[2]) else: inst.write(value[0]) print(value[0]) inst.close()
def __init__(self, addr="192.168.1.10"): self.instr = vxi11.Instrument(addr) print(self.instr.ask("*IDN?")) self.triggerType = None self.system = None self.mainBus = None self.bus = None
def pressMeasGate(): inst = vxi11.Instrument(OSCIP) if window.Element('measGate').get() != '': temp = 'MEASUrement:GATing ' + window.Element('measGate').get() inst.write(temp) inst.close() print(temp)
def open(self): """ Make the connection to the device. Reset the device. """ self.scope = vxi11.Instrument(self.ip) self.reset_config()
def __init__(self, ip = '192.168.1.155'): self.instr = vxi11.Instrument(ip) try: print(self.instr.ask("*IDN?")) except: print("connecting to instrument failed.. exiting")
def __init__(self,channel=None, filename=None,query=None,command=None,FORCE=False,SAVE=True): ### Establish the connection ### self.command = None self.scope = v.Instrument(IP) if query: self.command = query print '\nAnswer to query:',self.command rep = self.query(self.command) print rep,'\n' sys.exit() elif command: self.command = command print '\nExecuting command',self.command self.scope.write(self.command) print '\n' sys.exit() self.stop() self.scope.write('HORizontal:RECOrdlength?') string = self.scope.read() length = string[len(':HORIZONTAL:RECORDLENGTH '):] self.scope.write('DAT:STAR 1') self.scope.write('DAT:STOP '+length) if filename: for i in range(len(channel)): time.sleep(0.1) self.get_data(chan=channel[i],filename=filename,SAVE=SAVE) self.run() else: print 'If you want to save, provide an output file name'
def _get_inst(self, **kwargs): host = kwargs.pop('host') timeout = kwargs.pop('timeout') inst = vxi11.Instrument(host, **kwargs) if timeout is not None: inst.timeout = timeout return inst
def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) if 'vxi11' not in globals(): global vxi11 import vxi11 self._inst = vxi11.Instrument(self._vxi11_address)
def __init__(self, parameters=dict({ 'chan': 'CHAN1', 'host': IP, 'toggle': False, 'SAVE': False }), pipe=None, queue=None): self.UPDATE = False self.flag_save = 1 self.parameters = parameters self.set_parameters(self.parameters) self.toggle2 = False if pipe is not None: self.pipe = pipe self.UPDATE = True self.q = queue try: self.sock = vxi.Instrument('169.254.108.195') self.sock.write(':WAVeform:TYPE RAW') self.sock.write(':WAVEFORM:BYTEORDER LSBFirst') self.sock.write(':TIMEBASE:MODE MAIN') self.sock.write(':WAVEFORM:SOURCE ' + parameters['chan']) self.sock.write(':WAVEFORM:FORMAT BYTE') except: print "Wrong IP, Listening port or bad connection \n Check cables first" self.load_data_loop()