コード例 #1
0
def adcSynchroJson(soft=True, corrector=None, count=10):
    jdata = {}

    if count < 2:
        (out1, out2) = adcRequestData()
        jdata["V"] = arrByteToShort(out1)
        jdata["I"] = arrByteToShort(out2)
    else:
        (out1x, out2x) = adcRequestData()
        out1xh = arrByteToShort(out1x)
        out2xh = arrByteToShort(out2x)
        out1 = [float(out1xh[i]) for i in xrange(len(out1xh))]
        out2 = [float(out2xh[i]) for i in xrange(len(out2xh))]
        for i in xrange(1, count):
            (out1x, out2x) = adcRequestData()
            out1xh = arrByteToShort(out1x)
            out2xh = arrByteToShort(out2x)
            for j in xrange(len(out1)):
                out1[j] += out1xh[j]
                out2[j] += out2xh[j]

        for j in xrange(len(out1)):
            out1[j] /= float(count)
            out2[j] /= float(count)
        jdata["V"] = out1
        jdata["I"] = out2

    jout = {}

    jout["attr"] = getAttr()
    jout["data"] = jdata

    f = open('out.json', 'w')
    f.write(json.dumps(jout))
    f.close()

    f = open('sout.json', 'w')
    #jout = adcLastCompute()
    if soft:
        jout = adcRequestLastComputeX(count)
    else:
        jout = adcRequestLastComputeHardAuto(count)
    f.write(json.dumps(jout))
    f.close()

    if corrector:
        data = corrector.calculateJson(jout)
        R = data['Zx']
    else:
        data = calculateJson(jout)
        R = data['R']

    print "Rre=", R.real
    print "Rim=", R.imag
    print "D={:3.3f} grad".format(cmath.phase(R) * 180.0 / math.pi)
    print "ErrV=", jout['summary']['V']['square_error']
    print "ErrI=", jout['summary']['I']['square_error']

    pass
コード例 #2
0
def adcSynchroJson(soft=True, corrector=None, count=10):
    jdata = {}

    if count < 2:
        (out1, out2) = adcRequestData()
        jdata["V"] = arrByteToShort(out1)
        jdata["I"] = arrByteToShort(out2)
    else:
        (out1x, out2x) = adcRequestData()
        out1xh = arrByteToShort(out1x)
        out2xh = arrByteToShort(out2x)
        out1 = [float(out1xh[i]) for i in range(len(out1xh))]
        out2 = [float(out2xh[i]) for i in range(len(out2xh))]
        for i in range(1, count):
            (out1x, out2x) = adcRequestData()
            out1xh = arrByteToShort(out1x)
            out2xh = arrByteToShort(out2x)
            for j in range(len(out1)):
                out1[j] += out1xh[j]
                out2[j] += out2xh[j]

        for j in range(len(out1)):
            out1[j] /= float(count)
            out2[j] /= float(count)
        jdata["V"] = out1
        jdata["I"] = out2

    jout = {}

    jout["attr"] = getAttr()
    jout["data"] = jdata

    f = open("out.json", "w")
    f.write(json.dumps(jout))
    f.close()

    f = open("sout.json", "w")
    # jout = adcLastCompute()
    if soft:
        jout = adcRequestLastComputeX(count)
    else:
        jout = adcRequestLastComputeHardAuto(count)
    f.write(json.dumps(jout))
    f.close()

    if corrector:
        data = corrector.calculateJson(jout)
        R = data["Zx"]
    else:
        data = calculateJson(jout)
        R = data["R"]

    print("Rre=", R.real)
    print("Rim=", R.imag)
    print("D={:3.3f} grad".format(cmath.phase(R) * 180.0 / math.pi))
    print("ErrV=", jout["summary"]["V"]["square_error"])
    print("ErrI=", jout["summary"]["I"]["square_error"])

    pass
コード例 #3
0
ファイル: plot.py プロジェクト: ng-designs/rlc-meter-balmer
    def UsbQuant(self):
        jf = usb_commands.oneFreq(self.period, maxAmplitude=self.maxAmplitude)
        if self.corr:
            res = self.corr.calculateJson(jf)
        else:
            res = jplot.calculateJson(jf)
            res['Zx'] = res['R']

        self.SetInfo(res)
        pass
コード例 #4
0
ファイル: plot.py プロジェクト: balmerdx/rlc-meter-balmer
	def UsbQuant(self):
		jf = usb_commands.oneFreq(self.period, maxAmplitude=self.maxAmplitude)
		if self.corr:
			res = self.corr.calculateJson(jf)
		else:
			res = jplot.calculateJson(jf)
			res['Zx'] = res['R']

		self.SetInfo(res)
		pass
コード例 #5
0
ファイル: plot.py プロジェクト: barons2015/rlc-meter-balmer
	def UsbThread(self):
		i = 0
		while not self.end_thread:
			jf = usb_commands.oneFreq(self.period, maxAmplitude=self.maxAmplitude)
			if self.corr:
				res = self.corr.calculateJson(jf)
			else:
				res = jplot.calculateJson(jf)
				res['Zx'] = res['R']

			if self.end_thread:
				return
			self.SetInfo(res)
		pass
コード例 #6
0
ファイル: main.py プロジェクト: x893/rlc-meter-balmer
    def SetInfo(self):
        s = self
        s.progress_bar.setValue(s.scan_freq.current())
        jout = s.scan_freq.jfreq[-1]
        data = jplot.calculateJson(jout)
        info = ''
        info += 'F=' + str(int(data['F']))
        info += '\n' + 'R='+usb_commands.getResistorValueStr(usb_commands.resistorIdx)
        info += '\n' + 'KU='+str(usb_commands.getGainValueV(usb_commands.gainVoltageIdx))+'x'
        info += ' KI='+str(usb_commands.getGainValueI(usb_commands.gainCurrentIdx))+'x'
        info += '\n' + 'Rre='+str(jplot.formatR(data['R'].real))
        info += '\n' + 'Rim='+str(jplot.formatR(data['R'].imag))

        s.info_label.setText(info)
        pass
コード例 #7
0
ファイル: main.py プロジェクト: ng-designs/rlc-meter-balmer
    def SetInfo(self):
        s = self
        s.progress_bar.setValue(s.scan_freq.current())
        jout = s.scan_freq.jfreq[-1]
        data = jplot.calculateJson(jout)
        info = ''
        info += 'F=' + str(int(data['F']))
        info += '\n' + 'R='+usb_commands.getResistorValueStr(usb_commands.resistorIdx)
        info += '\n' + 'KU='+str(usb_commands.getGainValueV(usb_commands.gainVoltageIdx))+'x'
        info += ' KI='+str(usb_commands.getGainValueI(usb_commands.gainCurrentIdx))+'x'
        info += '\n' + 'Rre='+str(jplot.formatR(data['R'].real))
        info += '\n' + 'Rim='+str(jplot.formatR(data['R'].imag))

        s.info_label.setText(info)
        pass
コード例 #8
0
    def UsbThread(self):
        i = 0
        while not self.end_thread:
            jf = usb_commands.oneFreq(self.period,
                                      maxAmplitude=self.maxAmplitude)
            if self.corr:
                res = self.corr.calculateJson(jf)
            else:
                res = jplot.calculateJson(jf)
                res['Zx'] = res['R']

            if self.end_thread:
                return
            self.SetInfo(res)
        pass
コード例 #9
0
ファイル: plot.py プロジェクト: ng-designs/rlc-meter-balmer
    def plotFreq(self, fileName):
        gtype = self.gtype
        ax = self.axes
        jout = jplot.readJson(fileName)
        jfreq = jout['freq']

        f_data = []
        re_data = []
        im_data = []
        dfi_data = []
        re_error = []
        im_error = []
        re_corr = []
        im_corr = []
        arr_L = []
        arr_C = []

        amp_I = []
        amp_V = []
        fiV_data = []
        fiI_data = []

        if gtype == "ReImRaw":
            corr = None
        else:
            corr = jplot.Corrector()

        for jf in jfreq:
            if corr:
                res = corr.calculateJson(jf)
                Zx = res['Zx']
            else:
                res = jplot.calculateJson(jf)
                Zx = res['R']

            #if res['period']<3*96:#quick fix
            #	continue

            F = res['F']
            f_data.append(F)

            #re_data.append(math.fabs(res['R'].real))
            #im_data.append(abs(res['R']))
            re_data.append(res['R'].real)
            #im_data.append(math.fabs(res['R'].imag))
            im_data.append(res['R'].imag)
            re_error.append(jf['summary']['V']['square_error'])
            im_error.append(jf['summary']['I']['square_error'])

            gain_I = jf['attr']["gain_I"]
            gain_V = jf['attr']["gain_V"]
            #re_error.append(math.sqrt(jf['summary']['V']['sin']**2+jf['summary']['V']['cos']**2)/gain_V)
            #im_error.append(math.sqrt(jf['summary']['I']['sin']**2+jf['summary']['I']['cos']**2)/gain_I)
            #re_error.append(gain_V)
            #im_error.append(gain_I)
            #re_error.append(jf['attr']["gain_index_V"])
            #im_error.append(jf['attr']["gain_index_I"])

            #amp_I.append(abs(complex(jf['summary']['I']['sin']/gain_I, jf['summary']['I']['cos']/gain_I)))
            #amp_V.append(abs(complex(jf['summary']['V']['sin']/gain_V, jf['summary']['V']['cos']/gain_V)))
            amp_I.append(
                abs(
                    complex(jf['summary']['I']['sin'],
                            jf['summary']['I']['cos'])))
            amp_V.append(
                abs(
                    complex(jf['summary']['V']['sin'],
                            jf['summary']['V']['cos'])))

            if gtype == 'dfic':
                dfi_data.append(cmath.phase(Zx) * 180 / math.pi)
            if gtype == 'dfi':
                dfi_data.append(cmath.phase(res['R']) * 180 / math.pi)
                #dfi_data.append((cmath.phase(res['R'])-cmath.phase(Zx))*180/math.pi) #dfi error

            fiV_data.append(res['fiV'])
            fiI_data.append(res['fiI'])

            if self.serial:
                re_corr.append(Zx.real)
                #im_corr.append(math.fabs(Zx.imag))
                im_corr.append(Zx.imag)

                if Zx.imag > 0:
                    L = Zx.imag / (2 * math.pi * F)
                else:
                    L = 0

                if Zx.imag < -1e-10:
                    C = -1 / (2 * math.pi * F * Zx.imag)
                    #C = min(C, 1e-6)
                else:
                    C = 0
                arr_L.append(L * 1e6)
                arr_C.append(C * 1e12)

            if not self.serial:  #parrallel
                Yx = 1 / Zx

                im_max = 1e10
                if Yx.real < 1 / im_max:
                    re_corr.append(im_max)
                else:
                    re_corr.append(1 / Yx.real)

                if math.fabs(Yx.imag) * im_max > 1:
                    im_corr.append(1 / Yx.imag)
                else:
                    if Yx.imag > 0:
                        im_corr.append(im_max)
                    else:
                        im_corr.append(-im_max)

                C = Yx.imag / (2 * math.pi * F)
                C = min(C, 1e-6)
                C = max(C, -1e-6)
                arr_C.append(C * 1e12)

                if Yx.imag < 0:
                    L = -1 / (2 * math.pi * F * Yx.imag)
                else:
                    L = 0
                arr_L.append(L * 1e6)

        #ax.set_title("1 uF 160 V")
        ax.set_xscale('log')
        #ax.set_yscale('log')
        ax.set_xlabel("Hz")

        #ax.set_ylabel("Om")
        #ax.plot (f_data, fiV_data, '-', color="red")
        #ax.plot (f_data, fiI_data, '-', color="blue")

        if gtype == "dfi" or gtype == "dfic":
            ax.plot(f_data, dfi_data, '-', color="green")

        if gtype == "error":
            ax.plot(f_data, re_error, '.', color="red")
            ax.plot(f_data, im_error, '.-', color="blue")

        if gtype == "ReImCorrect" or gtype == "ReCorrect" or gtype == "ImCorrect":
            ax.set_ylabel("Om")
            if gtype == "ReImCorrect" or gtype == "ReCorrect":
                ax.plot(f_data, re_corr, '-', color="red")
            if gtype == "ReImCorrect" or gtype == "ImCorrect":
                ax.plot(f_data, im_corr, '-', color="blue")

        if gtype == "ReImRaw":
            ax.set_ylabel("Om")
            ax.plot(f_data, re_data, '-', color="red")
            ax.plot(f_data, im_data, '-', color="blue")

        if gtype == "C":
            ax.set_ylabel("pF")
            ax.plot(f_data, arr_C, '-', color="red")

        if gtype == "L":
            ax.set_ylabel("uH")
            ax.plot(f_data, arr_L, '-', color="red")

        if gtype == "ampIV":
            ax.set_ylabel("Amplithude I V")
            ax.plot(f_data, amp_V, '-', color="red")
            ax.plot(f_data, amp_I, '-', color="blue")
        pass
コード例 #10
0
ファイル: plot.py プロジェクト: barons2015/rlc-meter-balmer
	def plotFreq(self, fileName):
		gtype = self.gtype
		ax = self.axes
		jout = jplot.readJson(fileName)
		jfreq = jout['freq']

		f_data = []
		re_data = []
		im_data = []
		dfi_data = []
		re_error = []
		im_error = []
		re_corr = []
		im_corr = []
		arr_L = []
		arr_C = []

		amp_I = []
		amp_V = []
		fiV_data = []
		fiI_data = []

		if gtype=="ReImRaw":
			corr = None
		else:
			corr = jplot.Corrector()

		for jf in jfreq:
			if corr:
				res = corr.calculateJson(jf)
				Zx = res['Zx']
			else:
				res = jplot.calculateJson(jf)
				Zx = res['R']

			#if res['period']<3*96:#quick fix
			#	continue

			F = res['F']
			f_data.append(F)

			#re_data.append(math.fabs(res['R'].real))
			#im_data.append(abs(res['R']))
			re_data.append(res['R'].real)
			#im_data.append(math.fabs(res['R'].imag))
			im_data.append(res['R'].imag)
			re_error.append(jf['summary']['V']['square_error'])
			im_error.append(jf['summary']['I']['square_error'])

			gain_I = jf['attr']["gain_I"]
			gain_V = jf['attr']["gain_V"]
			#re_error.append(math.sqrt(jf['summary']['V']['sin']**2+jf['summary']['V']['cos']**2)/gain_V)
			#im_error.append(math.sqrt(jf['summary']['I']['sin']**2+jf['summary']['I']['cos']**2)/gain_I)
			#re_error.append(gain_V)
			#im_error.append(gain_I)
			#re_error.append(jf['attr']["gain_index_V"])
			#im_error.append(jf['attr']["gain_index_I"])

			#amp_I.append(abs(complex(jf['summary']['I']['sin']/gain_I, jf['summary']['I']['cos']/gain_I)))
			#amp_V.append(abs(complex(jf['summary']['V']['sin']/gain_V, jf['summary']['V']['cos']/gain_V)))
			amp_I.append(abs(complex(jf['summary']['I']['sin'], jf['summary']['I']['cos'])))
			amp_V.append(abs(complex(jf['summary']['V']['sin'], jf['summary']['V']['cos'])))


			if gtype=='dfic':
				dfi_data.append(cmath.phase(Zx)*180/math.pi)
			if gtype=='dfi':
				dfi_data.append(cmath.phase(res['R'])*180/math.pi)
				#dfi_data.append((cmath.phase(res['R'])-cmath.phase(Zx))*180/math.pi) #dfi error
			
			fiV_data.append(res['fiV'])
			fiI_data.append(res['fiI'])

			if self.serial:
				re_corr.append(Zx.real)
				#im_corr.append(math.fabs(Zx.imag))
				im_corr.append(Zx.imag)
				
				if Zx.imag>0:
					L = Zx.imag/(2*math.pi*F)
				else:
					L = 0

				if Zx.imag<-1e-10:
					C = -1/(2*math.pi*F*Zx.imag)
					#C = min(C, 1e-6)
				else:
					C = 0
				arr_L.append(L*1e6)
				arr_C.append(C*1e12)

			if not self.serial: #parrallel
				Yx = 1/Zx

				im_max = 1e10
				if Yx.real < 1/im_max:
					re_corr.append(im_max)
				else:
					re_corr.append(1/Yx.real)

				if math.fabs(Yx.imag)*im_max>1:
					im_corr.append(1/Yx.imag)
				else:
					if Yx.imag>0:
						im_corr.append(im_max)
					else:
						im_corr.append(-im_max)

				C = Yx.imag/(2*math.pi*F)
				C = min(C, 1e-6)
				C = max(C, -1e-6)
				arr_C.append(C*1e12)

				if Yx.imag<0:
					L = -1/(2*math.pi*F*Yx.imag)
				else:
					L = 0
				arr_L.append(L*1e6)



		#ax.set_title("1 uF 160 V")
		ax.set_xscale('log')
		#ax.set_yscale('log')
		ax.set_xlabel("Hz")

		#ax.set_ylabel("Om")
		#ax.plot (f_data, fiV_data, '-', color="red")
		#ax.plot (f_data, fiI_data, '-', color="blue")

		if gtype=="dfi" or gtype=="dfic":
			ax.plot (f_data, dfi_data, '-', color="green")

		if gtype=="error":
			ax.plot (f_data, re_error, '.', color="red")
			ax.plot (f_data, im_error, '.-', color="blue")

		if gtype=="ReImCorrect" or gtype=="ReCorrect" or gtype=="ImCorrect":
			ax.set_ylabel("Om")
			if gtype=="ReImCorrect" or gtype=="ReCorrect":
				ax.plot (f_data, re_corr, '-', color="red")
			if gtype=="ReImCorrect" or gtype=="ImCorrect":
				ax.plot (f_data, im_corr, '-', color="blue")

		if gtype=="ReImRaw":
			ax.set_ylabel("Om")
			ax.plot (f_data, re_data, '-', color="red")
			ax.plot (f_data, im_data, '-', color="blue")

		if gtype=="C":
			ax.set_ylabel("pF")
			ax.plot (f_data, arr_C, '-', color="red")

		if gtype=="L":
			ax.set_ylabel("uH")
			ax.plot (f_data, arr_L, '-', color="red")

		if gtype=="ampIV":
			ax.set_ylabel("Amplithude I V")
			ax.plot (f_data, amp_V, '-', color="red")
			ax.plot (f_data, amp_I, '-', color="blue")
		pass