# python, bleh import time import datetime import serial import sys import struct def wait_for_GPIB_data_ready(): spoll = 0 while spoll == 0: ser.write('++spoll\r') s = '' while ser.inWaiting() == 0: time.sleep(0.001) while ser.inWaiting() > 0: s += ser.read(1) time.sleep(.001) spoll = int(s) #print "SPOLL: " + str(spoll) def write_GPIB(s): ser.write(s + '\r') time.sleep(0.01) # strips \n or \r from the last two chars def read_serial(): s = "" while ser.inWaiting() == 0: time.sleep(0.01) while ser.inWaiting() > 0: time.sleep(.001) s += ser.read(1) if s[-1] == "\n" or s[-1] == "\r": s = s[:-1] if s[-1] == "\n" or s[-1] == "\r": s = s[:-1] # print '=='+ s[:] +'==' + str(len(s)) return s def read_serial_bytes(i): while ser.inWaiting() < i: time.sleep(0.01) s = ser.read(i) return s # strips \n or \r from the last two chars def read_GPIB(): ser.write('++read eoi\n') s = '' while len(s) < 1 or s[-1] != chr(eot_char): s += ser.read(1) if s[-1] == "\n" or s[-1] == "\r": s = s[:-1] if s[-1] == "\n" or s[-1] == "\r": s = s[:-1] # print '=='+ s[:] +'==' + str(len(s)) return s # send query and receive a string response, strip terminating CR or LF def query_GPIB_string(s): ser.write(s + '\n') # send instrument command write_GPIB('++eot_enable 1') # Append user defined character when EOI detected ser.write('++read eoi\n') # read data until EOI char is received s = '' while len(s) == 0 or s[-1] != chr(eot_char): s += ser.read(1) s = s[:-1] # strip EOI termination char if s[-1] == "\n" or s[-1] == "\r": s = s[:-1] # strip CR at the end of string return s #--------------------------- MAIN ----------------------------------------- mv_per_div = 200 ps_per_div = 50 golden_ratio = 1.61803398875 chartheight = 400 chartwidth = int(golden_ratio * chartheight) chartXstart = 70 chartYstart = 10 imagewidth = 2 * chartXstart + chartwidth imageheight = chartYstart + chartheight traces = 10 trace_stroke_width = 2 graticule_stroke_width = 0.3 vrange = 32000.0 eot_char = 127 #if len(sys.argv) != 3: # print 'usage: python E4916A.py FREQUENCY_MHZ FILENAME' # exit() #F_nominal = float(sys.argv[1]) #filename = sys.argv[2] + '.csv' ser = serial.Serial(port='COM22', baudrate=9600, timeout=0.5, rtscts=1) ser.isOpen() write_GPIB('') write_GPIB('++mode 1') write_GPIB('++addr 1') write_GPIB('++auto 0') write_GPIB('++eoi 1') write_GPIB('++clr') write_GPIB('++eot_char ' + str(eot_char)) time.sleep(.01) write_GPIB('TEXT CLEAR') #write_GPIB('ACQuisition STOP') # drain touch buffer while query_GPIB_string('ABSTOUCH?').split(' ')[1] != '-1,-1': time.sleep(.01) #wait for screen tap touch = 0 while touch == 0: time.sleep(.01) write_GPIB("TEXT X:20,Y:1,STRING:'TAP HERE FOR NEXT PULSER'") if query_GPIB_string('ABSTOUCH?').split(' ')[1] != '-1,-1': touch = 1 write_GPIB('TEXT CLEAR') id = query_GPIB_string('ID?').split(' ')[1] head = query_GPIB_string('SAMid?').split(',')[1].split(':')[1].replace('"', '') head_sn = query_GPIB_string('UID?').split(',')[2].split(':')[1].replace('"', '') write_GPIB('ABBwfmpre ON') # reduced response to WFMPre? write_GPIB('CHM3 OFFSET:-5.0E-1,SENSITIVITY:'+str(mv_per_div * 0.001)+',SMOOTHING:ON') write_GPIB('CONDACQ TYPE:CONTINUOUS') write_GPIB('OUTPUT TRACE1') write_GPIB('TRIGGER MODE:NORMAL,STATUS:TRG,SOURCE:EXTERNAL,LEVEL:0,SLOPE:MINUS') #write_GPIB('TRIGGER MODE:NORMAL,STATUS:TRG,SOURCE:EXTERNAL,LEVEL:0,SLOPE:PLUS') write_GPIB('AUTOSET HORIZ:ON,VERT:OFF,TRIGGER:ON,MODE:EDGE,START') time.sleep(1) #write_GPIB('MAINPOS 44.65784E-9') write_GPIB('TBMAIN LENGTH:512,TIME:'+str(ps_per_div)+'E-12,XINCR:4.0E-13') write_GPIB('TBWIN LENGTH:512,TIME:1.0E-12,XINCR:2.0E-14') with open('image1.svg', "w") as text_file: # get graticule range parameters = query_GPIB_string('WFMPre?').split(',') for i in range(len(parameters)): param = parameters[i].split(':')[0] data = parameters[i].split(':')[1] if param == 'YZERO': yzero = float(data) if param == 'YMULT': ymult = float(data) print param, data text_file.write('\n') text_file.write('\n') text_file.write('') text_file.close() #write_GPIB('TRIGGER MODE:NORMAL,STATUS:TRG,SOURCE:EXTERNAL,LEVEL:0,SLOPE:MINUS') write_GPIB('TRIGGER MODE:NORMAL,STATUS:TRG,SOURCE:EXTERNAL,LEVEL:0,SLOPE:PLUS') write_GPIB('AUTOSET HORIZ:ON,VERT:OFF,TRIGGER:ON,MODE:EDGE,START') time.sleep(1) #write_GPIB('MAINPOS 44.65784E-9') write_GPIB('TBMAIN LENGTH:512,TIME:'+str(ps_per_div)+'E-12,XINCR:4.0E-13') write_GPIB('TBWIN LENGTH:512,TIME:1.0E-12,XINCR:2.0E-14') with open('image2.svg', "w") as text_file: # get graticule range parameters = query_GPIB_string('WFMPre?').split(',') for i in range(len(parameters)): param = parameters[i].split(':')[0] data = parameters[i].split(':')[1] if param == 'YZERO': yzero = float(data) if param == 'YMULT': ymult = float(data) print param, data text_file.write('\n') text_file.write('\n') text_file.write('') text_file.close() filename = 'pulser.html' with open(filename, "w") as text_file: text_file.write('') text_file.write('
') text_file.write('') text_file.write('
') text_file.write('') text_file.write('') text_file.write('') text_file.close() # https://github.com/kendallb/PrintHtml import os os.system('cmd /c "PrintHtml.exe -p Default pulser.html"') exit() write_GPIB('ID?') write_GPIB('++read eoi') print read_serial() print query_GPIB_string('ID?') print query_GPIB_string('UID?') print query_GPIB_string('SAMid?') print query_GPIB_string('ABBwfmpre?') print query_GPIB_string('ABSTouch?') print query_GPIB_string('ACQNum?') print query_GPIB_string('ACQuisition?') print query_GPIB_string('ADJtrace1?') print query_GPIB_string('ALTinkjet?') print query_GPIB_string('AMPlitude?') print query_GPIB_string('AUTOSet?') print query_GPIB_string('AVG?') print query_GPIB_string('BCOrrection?') print query_GPIB_string('BITMap?') print query_GPIB_string('BYT.or?') print query_GPIB_string('CALibrate?') print query_GPIB_string('CH?') #print query_GPIB_string('CHIdent?') print query_GPIB_string('COLor?') print query_GPIB_string('COMpare?') print query_GPIB_string('CONDacq?') print query_GPIB_string('COPy?') print query_GPIB_string('CROss?') print query_GPIB_string('CURSor?') print query_GPIB_string('CURVe?') print query_GPIB_string('DATE?') print query_GPIB_string('DCOmp?') print query_GPIB_string('DEBug?') print query_GPIB_string('DEFine?') print query_GPIB_string('DIAg?') print query_GPIB_string('DISPlay?') print query_GPIB_string('DISPNum?') print query_GPIB_string('DIV2?') print query_GPIB_string('DOT1Abs?') print query_GPIB_string('DSYmenu?') print query_GPIB_string('DSYS?') print query_GPIB_string('ENCdg?') print query_GPIB_string('MPAram?') print query_GPIB_string('NVRam?') print query_GPIB_string('POWeron?') print query_GPIB_string('SET?') print query_GPIB_string('RISetime?') print query_GPIB_string('FALltime?') print query_GPIB_string('OVErshoot?') exit()