from math import * import sys import easygui as eg def message(uitkomst): msg = uitkomst title = "Results: continue ?" if eg.ccbox(msg, title): # show a Continue/Cancel dialog menu() else: # user chose Cancel sys.exit(0) def fout(): msg = "Wrong valuea for this mode" title = "Ooops" if eg.ccbox(msg, title): # show a Continue/Cancel dialog menu() else: # user chose Cancel sys.exit(0) def displayZ(f,Rs,Xs): if Xs < 0: if Rs == 0: Rs = 0.0000001 else: Z=complex(Rs,Xs) Zabs=round(abs(Z),4) uitkomst='' uitkomst=('Frequentie = '+ str(f)+'\n'+'Z = '+ str(Z)+'\n'+'|Z| = ' +str(Zabs)+'\n') capacitance(f,Rs,Xs,uitkomst) menu() else: if Rs == 0: Rs = 0.0000001 if Xs == 0: Xs = 0.0000001 Z=complex(Rs,Xs) Zabs=round(abs(Z),4) Z=complex(Rs,Xs) Zabs=abs(Z) uitkomst='' uitkomst=('Frequentie = '+ str(f)+'\n'+'Z = '+ str(Z)+'\n'+'|Z| = ' +str(Zabs)+'\n') inductance(f,Rs,Xs,uitkomst) menu() def displayY(f,RsG,XsB): if XsB < 0: if RsG==0: RsG=-0.0000001 else: Y=complex(RsG,XsB) Yabs=round(abs(Y),4) Rx=(1000000.0*RsG)/((RsG*RsG)+(XsB*XsB)) Xx=(-1000000.0*XsB)/((RsG*RsG)+(XsB*XsB)) Rx=round(Rx,4) Xx=round(Xx,4) Zx=complex(Rx,Xx) Zabs=abs(Zx) Zabs=round(Zabs,4) uitkomst='' uitkomst=('Frequency = '+ str(f)+'\n'+'Y = '+ str(Y)+'\n'+'|Y| (umoh) = ' +str(Yabs)+'\n'+'Z = ('+str(Rx)+str(Xx)+'j)'+'\n'+'|Z| = '+str(Zabs)+'\n') inductance(f,Rx,Xx,uitkomst) else: if XsB==0: XsB=0.00000001 elif RsG==0: RsG==0.00000001 else: Y=complex(RsG,XsB) Yabs=round(abs(Y),4) Rx=(1000000.0*RsG)/((RsG*RsG)+(XsB*XsB)) Xx=(-1000000.0*XsB)/((RsG*RsG)+(XsB*XsB)) Rx=round(Rx,4) Xx=round(Xx,4) Zx=complex(Rx,Xx) Zabs=abs(Zx) Zabs=round(Zabs,4) uitkomst='' uitkomst=('Frequency = '+ str(f)+'\n'+'Y = ('+ str(Y)+'\n'+'|Y| (umoh) = ' +str(Yabs)+'\n'+'Z = ('+str(Rx)+', '+str(Xx)+'j)'+'\n'+'|Z| = '+str(Zabs)+'\n') capacitance(f,Rx,Xx,uitkomst) def capacitance(f,Rs,Xs,uitkomst): C=(1/Xs)/(2*pi*f)*1000000000.0 C=abs(C) C = round(C,4) ESR = abs(Rs) ESR = round(ESR,4) D= ESR / abs(Xs) D= round(D,4) Phase=round(90-atan(D),4) P=round((ESR*ESR)/((ESR*ESR)+(Xs*Xs)),6) uitkomst= uitkomst+('Cs = '+ str(C)+' nF'+'\n'+'ESR = '+ str(ESR)+' Ohm'+'\n'+'D = ' +str(D)+'\n'+'PF = '+str(P)+'\n'+'Phase = -'+str(Phase)) message(uitkomst) def inductance(f,Rs,Xs,uitkomst): L=Xs/(2*pi*f) L= round(abs(L),4) ESR=round(abs(Rs),4) Q=round(abs(Xs)/ESR,4) Phase=round(90-atan(1/Q),4) uitkomst= uitkomst+('Ls = '+ str(L*1000000.0)+' uH'+'\n'+'Rs = '+ str(ESR)+' Ohm'+'\n'+'Q = ' +str(Q)+'\n'+'Phase = -'+str(Phase)) message(uitkomst) def impedance(): msg = "Enter all fields" title = "Measure impedance" fieldNames = ["Generator frequency in kHz","Position fo knob in kHz (must be higher as Fgen)","R = ","X = "] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) # make sure that none of the fields was left blank while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] f= float(f)*1000.0 fo= fieldValues[1] fo= float(fo)*1000.0 Rs= fieldValues[2] Rs= float(Rs)*1.0 Xs= fieldValues[3] Xs=(fo/f)*float(Xs)*1.0 displayZ(f,Rs,Xs) menu() def admitance(): msg = "Enter all fields" title = "Measure admittance" fieldNames = ["Generator frequency in kHz","Position fo knob in kHz (must be lower as Fgen)","G = ","B = "] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) # make sure that none of the fields was left blank while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] f= float(f)*1000.0 fo= fieldValues[1] fo= float(fo)*1000.0 RsG= fieldValues[2] RsG= float(RsG)*1.0 XsB= fieldValues[3] XsB=((f/fo)*float(XsB)*1.0) displayY(f,RsG,XsB) menu() def ver1(): msg = "Inductive Zx or Yx, both R/G and X/B are small" title = "GR-1603 Z/Y bridge" choices =['1= Impedance Z', '2= Admitance Y'] choice = eg.choicebox(msg, title, choices) antwoord = eg.indexbox(str(choice)) type= choice[0] if type == str(1): title = "Inductive Zx , both R and X are small" msg = ''' No prebalance \n Set switch to "Z measure" \n \n Preset both "Delta knobs" near top scale \n Balance with "main R" and "main X" dials \n \n Enter Delta R and Delta X \n\n Set switch to "Z initial bal" reversed \n Make final balance with both delta knobs \n\n Enter final Delta R and Delta X''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be higher as Fgen)','first "delta R"','first "delta X"','Final "delta R"','Final "delta X"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] dR1= fieldValues[2] dX1= fieldValues[3] dR2= fieldValues[4] dX2= fieldValues[5] fo= float(fo)*1000.0 f= float(f)*1000.0 dR1= float(dR1)*-1.0 dX1= float(dX1)*-1.0 dR2= float(dR2)*-1.0 dX2= float(dX2)*-1.0 Rs= dR2-dR1 Rs= abs(Rs) Xs= (dX2-dX1)*(fo/f)*-1.0 if Xs < 0: fout() else: displayZ(f,Rs, Xs) menu() elif type == str(2): title = "Inductive Yx, both G and B are small" msg = ''' No prebalance \n Set switch to "Y measure" \n \n Preset both "Delta knobs" near top scale \n Balance with "main G" and "main B" dials \n \n Enter Delta G and Delta B \n\n Set switch to "Y initial bal" reversed \n Make final balance with both delta knobs \n\n Enter final Delta G and Delta B''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be lower as Fgen)','first "delta G"','first "delta B"','Final "delta G"','Final "delta B"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] dG1= fieldValues[2] dB1= fieldValues[3] dG2= fieldValues[4] dB2= fieldValues[5] f= float(f)*1000.0 fo= float(fo)*1000.0 dG1= float(dG1)*-1.0 dB1= float(dB1)*-1.0 dG2= float(dG2)*-1.0 dB2= float(dB2)*-1.0 k=1000000.0 RsG=dG2-dG1 RsG=abs(RsG) XsB=(dB2-dB1)*(f/fo)*-1.0 if XsB > 0: fout() else: displayY(f,RsG,XsB) menu() def ver2(): title = "Capacitive Zx, both R and X are small" msg = ''' Set switch to Z initial bal reversed \n preset Delta X near top scale \n Prebalance R and do not move \n Balance with delta R dial and X main dial \n \n Enter Delta R and Delta X \n\n Set switch to Z measure \n Make final balance with both delta knobs \n\n Make final balance with both delta knobs \n Enter final Delta R and Delta X''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be higher as Fgen)','first "delta R"','first "delta X"','Final "delta R"','Final "delta X"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] dR1= fieldValues[2] dX1= fieldValues[3] dR2= fieldValues[4] dX2= fieldValues[5] f= float(f)*1000.0 fo= float(fo)*1000.0 dR1= float(dR1)*1.0 dX1= float(dX1)*1.0 dR2= float(dR2)*1.0 dX2= float(dX2)*1.0 Rs=dR2-dR1 Rs=abs(Rs) Xs=(dX2-dX1)*(fo/f) if Xs > 0: fout() else: displayZ(f,Rs,Xs) menu() def ver3(): title = "Capacitive Yx, both G and B are small" msg = ''' Set switch to "Y initial bal reversed" \n preset both Delta knobs near top scale \n Prebalance "main G" and do not move \n Balance with "delta G" dial and "main B" dial \n \n Enter Delta G and Delta B \n\n Set switch to "Y measure" \n\n Make final balance with both delta knobs \n Enter final Delta G and Delta B''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be lower as Fgen)','first "delta G"','first "delta B"','Final "delta G"','Final "delta B"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] dG1= fieldValues[2] dB1= fieldValues[3] dG2= fieldValues[4] dB2= fieldValues[5] f= float(f)*1000.0 fo= float(fo)*1000.0 dG1= float(dG1)*1.0 dB1= float(dB1)*1.0 dG2= float(dG2)*1.0 dB2= float(dB2)*1.0 k=1000000.0 RsG=dG2-dG1 RsG=abs(RsG) XsB=((dB2-dB1)*(f/fo)*-1) if XsB < 0: fout() else: displayY(f,RsG,XsB) menu() def ver4(): msg = "Zx (small R, large X) or Yx (large G, small B)" title = "GR-1603 Z/Y bridge" choices =['1= Impedance Z', '2= Admitance Y'] choice = eg.choicebox(msg, title, choices) antwoord = eg.indexbox(str(choice)) type= choice[0] if type == str(1): title = "Zx (small R, large X)" msg = ''' Set switch to "Z initial bal reversed" \n \n preset "main X" knob at zero (centre scale) \n Balance with "delta X" dail and "main R" dial \n \n Enter Delta R and Main X \n\n Set switch to "Z measure" \n Make final balance with "delta R" and "main X" knobs \n\n Enter final delta R and main X''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be higher as Fgen)','first "delta R"','first "main X"','Final "delta R"','Final "main X"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] dR1= fieldValues[2] X1= fieldValues[3] dR2= fieldValues[4] X2= fieldValues[5] fo= float(fo)*1000.0 f= float(f)*1000.0 dR1= float(dR1)*1.0 X1= float(X1)*1.0 dR2= float(dR2)*1.0 X2= float(X2)*1.0 k=1000000 Rs=dR2-dR1 Rs=abs(Rs) Xs=(X2-X1)*(fo/f) displayZ(f,Rs,Xs) menu() else: title = "Yx (large G, small B)" msg = ''' Set switch to "Y initial bal reversed" \n \n preset "main G" knob at zero (centre scale) \n Balance with "delta G" dail and "main B" dial \n \n Enter Main G and Delta B \n\n Set switch to "Y measure" \n Make final balance with "Main G" and "Delta B" knobs \n\n Enter final Main G and Delta B''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be lower as Fgen)','first "main G"','first "delta B"','Final "main G"','Final "delta B"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] G1= fieldValues[2] dB1= fieldValues[3] G2= fieldValues[4] dB2= fieldValues[5] fo= float(fo)*1000.0 f= float(f)*1000.0 G1= float(G1)*1.0 dB1= float(dB1)*1.0 G2= float(G2)*1.0 dB2= float(dB2)*1.0 k=1000000 RsG=G2-G1 RsG=abs(RsG) XsB=(dB2-dB1)*(f/fo)*-1.0 if XsB < 0: fout() else: displayY(f,RsG,XsB) menu() def ver5(): msg = "Zx (large R, small X) or Yx (small G, large B)" title = "GR-1603 Z/Y bridge" choices =['1= Impedance Z', '2= Admitance Y'] choice = eg.choicebox(msg, title, choices) antwoord = eg.indexbox(str(choice)) type= choice[0] if type == str(1): title = "Zx (large R, small X)" msg = ''' Set switch to "Z initial bal reversed" \n \n preset "main R" knob at zero (centre scale) \n Balance with "main X" dail and "delta R" dial \n \n Enter main R and delta X \n\n Set switch to "Z measure" \n Make final balance with "main R" and "delta X" knobs \n\n Enter final main R and delta X''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be higher as Fgen)','first "main R"','first "delta X"','Final "main R"','Final "delta X"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] R1= fieldValues[2] dX1= fieldValues[3] R2= fieldValues[4] dX2= fieldValues[5] fo= float(fo)*1000.0 f= float(f)*1000.0 R1= float(R1)*1.0 dX1= float(dX1)*1.0 R2= float(R2)*1.0 dX2= float(dX2)*1.0 k=1000000 Rs=R2-R1 Rs=abs(Rs) Xs=(dX2-dX1)*(fo/f) displayZ(f,Rs,Xs) menu() else: title = "Yx (small G, large B)" msg = ''' Set switch to "Y initial bal reversed" \n \n preset "main B" knob at zero (centre scale) \n Balance with " main G" dail and "Delta B" dial \n \n Enter Main B and Delta G \n\n Set switch to "Y measure" \n Make final balance with "Main B" and "Delta G" knobs \n\n Enter final Main B and Delta G''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be lower as Fgen)','first "main B"','first "delta G"','Final "main B"','Final "delta G"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] B1= fieldValues[2] dG1= fieldValues[3] B2= fieldValues[4] dG2= fieldValues[5] fo= float(fo)*1000.0 f= float(f)*1000.0 B1= float(B1)*1.0 dG1= float(dG1)*1.0 B2= float(B2)*1.0 dG2= float(dG2)*1.0 Rs=dG2-dG1 Rs=abs(Rs) Xs=(B2-B1)*(f/fo) displayY(f,Rs, Xs) menu() def ver6(): msg = "High frequency 10-20 kHz" title = "GR-1603 Z/Y bridge" choices =['1= Impedance Z', '2= Admitance Y'] choice = eg.choicebox(msg, title, choices) antwoord = eg.indexbox(str(choice)) type= choice[0] if type == str(1): title = "High frequency impedance" msg = ''' Set switch to "Z initial bal reversed" \n \n preset "main R" and "main X" at zero (centre scale) \n Balance with "delta X" dail and "delta R" dial \n \n Set switch to "Z measure" \n Make final balance with "main R" and "main X" dial\n\n Enter final main R and main X''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be higher as Fgen)','Final "main R"','Final "main X"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] R2= fieldValues[2] X2= fieldValues[3] fo= float(fo)*1000.0 f= float(f)*1000.0 R2= float(R2)*1.0 X2= float(X2)*1.0 Rs= R2 Rs= abs(Rs) Xs= X2*(fo/f) displayZ(f,Rs, Xs) menu() else: title = "High frequency admittance" msg = ''' Set switch to "Y initial bal reversed" \n \n preset "main G" and "main B" at zero (centre scale) \n Balance with "delta G" dail and "delta B" dial \n \n Set switch to "Y measure" \n Make final balance with "main B" and "main G" dial\n\n Enter final main B and main G''' fieldNames = ['Generator frequency in kHz','Position fo knob in kHz (must be lower as Fgen)','Final "main G"','Final "main B"'] fieldValues = [] # we start with blanks for the values fieldValues = eg.multenterbox(msg,title, fieldNames) while 1: if fieldValues == None: stopbox() errmsg = "" for i in range(len(fieldNames)): if fieldValues[i].strip() == "": errmsg += ('"%s" is a required field.\n\n' % fieldNames[i]) if errmsg == "": break # no problems found fieldValues = eg.multenterbox(errmsg, title, fieldNames, fieldValues) eg.writeln("Reply was: %s" % str(fieldValues)) f= fieldValues[0] fo= fieldValues[1] G2= fieldValues[2] B2= fieldValues[3] fo= float(fo)*1000.0 f= float(f)*1000.0 G2= float(G2)*1.0 B2= float(B2)*1.0 B2= B2*(f/fo) displayY(f,G2,B2) menu() def stopbox(): title = "GR-1603 Z/Y bridge" keus = ['OK','Nee'] antwoord = eg.indexbox('Stoppen', title, keus) if antwoord == 0: sys.exit(0) else: menu() def menu(): msg = "input values in all boxes" title = "GR-1603 Z/Y bridge" choices =['1= Impedance Z', '2= Admitance Y', '3= inv 1, Inductive Z/Y, R/G and X/B both small', '4= inv 2, capacitive Z, R and X both small ', '5= inv 3 Y, capacitive, G and B both small ', '6= inv 4 Z=(X), Y=(>G,R,B)', '8= inv 6, High frequency'] choice = eg.choicebox(msg, title, choices) print choice if choice == None: stopbox() type= choice[0] if type == str(1): impedance() elif type == str(2): admitance() elif type == str(3): ver1() elif type == str(4): ver2() elif type == str(5): ver3() elif type == str(6): ver4() elif type == str(7): ver5() elif type == str(8): ver6() else: menu() menu() sys.exit(0)