#-- Find which serial port controls the SR785 (if this succeeds, comms work) wstderr("\nFinding instrument...\n") matches = SR785.findInstrument( model="SR785", searchSerial=True, searchEthernet=False, searchGPIB=False, idnQueryStr="OUTX RS232;*IDN?", debug=DEBUG) if len(matches['serial']) == 0: raise Exception("Cannot find a serial port, or SR785 not attached to a serial port") #-- Open the first matching serial port SR785.openPort(matches['serial'][0]) idnStr = SR785.query("*IDN?") # Log file... homeDir = os.path.expanduser("~") dataBaseDir = os.path.join(homeDir, "gibble", "data") dataSubDir = os.path.join(dataBaseDir, time.strftime("%Y"), time.strftime("%m-%b"), time.strftime("%d")) #-- Find existing run sub-directories and label this run accordingly if os.path.isdir(dataSubDir): existingRunDirs = [ d for d in os.listdir(dataSubDir) if os.path.isdir(os.path.join(dataSubDir,d)) ] else: existingRunDirs = [] runDirRE = re.compile(r"^SR785run([0-9]+)")
ipAddress=ipAddress) scopeIDN = tekScope.query("*IDN?") except: raise Exception("Expected Tek scope on Ethernet port. Aborting.") #============================================================================== #-- Establish comms with DDS #============================================================================== try: #-- Set up DDS comms DDS = InstrumentComms(useSerial=True, useEthernet=False, serCmdTerm='\n', baud=115200, dsrdtr=True) DDS.simpleSerial() commsType = "serial" #-- Grab IDN string DDSIDN = DDS.query("*IDN?") except: raise Exception("Expected DDS on serial port. Aborting.") #============================================================================== #-- Set scope channels, measurements #============================================================================== #============================================================================== #-- Read initial DDS parameters #============================================================================== #============================================================================== #-- Try to establish what the system gain is in V/Hz #============================================================================== freqScales = np.logspace(-6, +7, 14)
import sys from instrumentComms import InstrumentComms DEBUG = False def wstdout(txt): sys.stdout.write(txt) sys.stdout.flush() def wstderr(txt): sys.stderr.write(txt) sys.stderr.flush() if __name__ == "__main__": ipAddress = "128.118.112.2" httpPort = 80 try: #-- Set up with serial port comms instrument = InstrumentComms(useSerial=True, baud=19200) instrument.simpleSerial(debug=DEBUG) commsType = "serial" except: #-- If that failed, try to set up with Ethernet comms instrument = InstrumentComms(useEthernet=True, ipAddress=ipAddress) commsType = "Ethernet" wstdout("\"" + instrument.query(sys.argv[1]) + "\"")