Ejemplo n.º 1
0
 def OnWriteFlash(self):
     corrector = jplot.Corrector()
     maxAmplitude = jplot.MaxAmplitude()
     usb_commands.FlashCorrector(corrector, maxAmplitude)
     QtGui.QMessageBox.about(
         self, TITLE, u"Запись корректирующих коэффициэнтов окончена.")
     pass
Ejemplo n.º 2
0
def main():
    if not initDevice():
        return

    if True:
        #period = HARDWARE_CORRECTOR_PERIODS[1]
        period = 3 * 96
        #period = periodToFreqency(3864)
        #period = periodToFreqency(10)

        if True:
            corrector = None
            maxAmplitude = None
        else:
            corrector = jplot.Corrector()
            maxAmplitude = jplot.MaxAmplitude()
        #FlashCorrector(corrector)
        #return

        #if corrector:
        #    setCorrector(corrector, period, maxAmplitude)
        #setCorrector2x(corrector, period)
        #setCorrectorOpen(corrector, period, maxAmplitude=maxAmplitude)
        #dwrite(struct.pack("=BBBBI", COMMAND_SET_CORRECTOR_PERIOD, 0,0,0, period))
        #data = dread()
        #assert(data[0]==COMMAND_SET_CORRECTOR_PERIOD)

        soft = True
        setSerial(False)
        setContinuousMode(False)
        adcSynchro(period, inAmplitude=DEFAULT_DAC_AMPLITUDE)
        #adcSynchro(period, inAmplitude=0)

        if soft:
            setLowPass(False)
            if False:
                setGainAuto()
                #setGainAuto(predefinedRes=3)
            else:
                setResistor(0)
                setSetGain(1, 0)  #V
                setSetGain(0, 0)  #I
        time.sleep(0.1)
        #adcSynchroJson(soft=soft, corrector=corrector, count=10)
        adcSynchroJson(soft=True, count=1)
    else:
        #allFreq(amplitude=DEFAULT_DAC_AMPLITUDE/2, resistorIndex=0, VIndex=0, IIndex=1, fileName='cor/R0V0I1_100Om.json')
        allFreq(amplitude=DEFAULT_DAC_AMPLITUDE,
                resistorIndex=0,
                VIndex=0,
                IIndex=0,
                fileName='cor/R0V0I0_open.json')
        #allFreq(fileName='freq_short_100.json')
    pass
Ejemplo n.º 3
0
    def __init__(self, title, parent=None):
        super(FormMeasure, self).__init__(parent)
        self.setWindowTitle(title)
        self.serial = True
        self.createMainFrame()

        self.corr = jplot.Corrector()
        self.maxAmplitude = jplot.MaxAmplitude()

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.UsbQuant)
        self.timer.start(100)
        pass
Ejemplo n.º 4
0
    def __init__(self, title, parent=None):
        super(FormMeasure, self).__init__(parent)
        self.setWindowTitle(title)
        self.serial = True
        self.end_thread = False
        self.createMainFrame()

        self.corr = jplot.Corrector()
        self.maxAmplitude = jplot.MaxAmplitude()

        self.th = threading.Thread(target=self.UsbThread)
        self.th.start()
        pass
Ejemplo n.º 5
0
    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