Exemple #1
0
def measure_freq(e):
	w = e.widget
	tag =w.find_closest(e.x, e.y)
	item = w.itemcget(tag,'tag')
	target = int(item.split()[0])
	if e.x < LPWIDTH/2 and e.y < OFFSET and 2 < target < 8:	 # Selected IN1, IN2, SEN, SQR1 or SQR2
		freq = p.get_frequency(target)
		if freq > 0.5:
			r2f = p.r2ftime(target, target)*1.0e-6
			msg(_('%4s : Freq = %5.3f. Duty Cycle = %5.1f %%') %(sources[target-1], freq, r2f*freq*100))
			s=_('%4s\n%5.3f Hz\n%5.1f %%')%(sources[target-1], freq, r2f*freq*100)
			g.disp(s)
		else:
			msg(_('No squarewave detected on %4s') %(sources[target-1]))
	elif e.x > LPWIDTH/2 and e.y > OFFSET and target < 3:	 # Selected CH1, CH2 or CH3
		if chan4[target][CHSRC] != 0 and chan4[target+1][CHSRC] != 0:  # both channels active
			fa = eyemath.fit_sine(chan4[target][TDATA],chan4[target][VDATA])
			fb = eyemath.fit_sine(chan4[target+1][TDATA],chan4[target+1][VDATA])
			if fa != None and fb != None:
				v1 = fa[1][0]
				v2 = fb[1][0]
				f1 = fa[1][1]*1000	# millisecond x-axis gives frequency in kHz, convert it
				f2 = fb[1][1]*1000
				p1 = fa[1][2]
				p2 = fb[1][2]
				s = _('%s: %5.3f V, %5.2f Hz | %s: %5.2f V, %5.3f Hz | Phase difference = %5.1f degree') \
				    % (channels[target], v1, f1, channels[target+1],v2, f2, (p2-p1)*180/3.1416)
				msg(s)
				s=_('%4s\n%5.3f Hz\n%5.1f %%')%(sources[target-1], freq, r2f*freq*100)
				g.disp(s)
			else:
				msg(_('Fitting of data failed. Try with Xmgrace'))
		else:
			msg(_('Selected channel and the next one should have data'), 'red')
Exemple #2
0
def update():
    global NP, delay, chanmask, measure, chan
    s = ''
    if chanmask == 8:  # SENSOR
        t, v = p.capture(4, NP, delay)
        g.delete_lines()
        g.line(t, v, 3)
        if measure == 1:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                pa = fa[1]
                s = _('Vpeak = %5.2f V | Freq = %5.2f Hz') % (abs(
                    pa[0]), pa[1] * 1000)
    elif chanmask == 4:  # A2
        t, v = p.capture(2, NP, delay)
        g.delete_lines()
        g.line(t, v, 2)
        if measure == 1:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                pa = fa[1]
                s = _('Vpeak = %5.2f V | Freq = %5.2f Hz') % (abs(
                    pa[0]), pa[1] * 1000)
            msgwin.config(text=s)
    elif chanmask == 1 or chanmask == 2:
        t, v = p.capture(chanmask - 1, NP, delay)
        g.delete_lines()
        g.line(t, v, chanmask - 1)
        if measure == 1:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                pa = fa[1]
                s = _('Vpeak = %5.2f V | Freq = %5.2f Hz') % (abs(
                    pa[0]), pa[1] * 1000)
            msgwin.config(text=s)
    elif chanmask == 3:
        t, v, tt, vv = p.capture01(NP, delay)
        g.delete_lines()
        g.line(t, v)
        g.line(tt, vv, 1)
        if measure == 1:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                pa = fa[1]
                s = _('CH0 Vp = %5.2f V | Freq = %5.2f Hz ') % (abs(
                    pa[0]), pa[1] * 1000)
            fb = eyemath.fit_sine(tt, vv)
            if fb != None:
                pb = fb[1]
                s = s + _('CH1 Vp = %5.2f V | Freq = %5.2f Hz') % (abs(
                    pb[0]), pb[1] * 1000)
            msgwin.config(text=s)
    else:
        g.delete_lines()
    root.after(10, update)
Exemple #3
0
def update():
	global NP, delay, chanmask, measure, chan
	s = ''
	if chanmask == 8:		# SENSOR
		t,v = p.capture(4,NP,delay)
		g.delete_lines()
		g.line(t,v,3)
		if measure == 1:
			fa = eyemath.fit_sine(t,v)
			if fa != None:
				pa = fa[1]
				s = _('Vpeak = %5.2f V | Freq = %5.2f Hz')%(abs(pa[0]), pa[1]*1000)
	elif chanmask == 4:		# A2
		t,v = p.capture(2,NP,delay)
		g.delete_lines()
		g.line(t,v,2)
		if measure == 1:
			fa = eyemath.fit_sine(t,v)
			if fa != None:
				pa = fa[1]
				s = _('Vpeak = %5.2f V | Freq = %5.2f Hz')%(abs(pa[0]), pa[1]*1000)
			msgwin.config(text = s)
	elif chanmask == 1 or chanmask == 2:
		t,v = p.capture(chanmask-1,NP,delay)
		g.delete_lines()
		g.line(t,v,chanmask-1)
		if measure == 1:
			fa = eyemath.fit_sine(t,v)
			if fa != None:
				pa = fa[1]
				s = _('Vpeak = %5.2f V | Freq = %5.2f Hz')%(abs(pa[0]), pa[1]*1000)
			msgwin.config(text = s)
	elif chanmask == 3:
		t,v,tt,vv = p.capture01(NP,delay)
		g.delete_lines()
		g.line(t,v)
		g.line(tt,vv,1)
		if measure == 1:
			fa = eyemath.fit_sine(t,v)
			if fa != None:
				pa = fa[1]
				s = _('CH0 Vp = %5.2f V | Freq = %5.2f Hz ')%(abs(pa[0]), pa[1]*1000)
			fb = eyemath.fit_sine(tt,vv)
			if fb != None:
				pb = fb[1]
				s = s + _('CH1 Vp = %5.2f V | Freq = %5.2f Hz')%(abs(pb[0]), pb[1]*1000)
			msgwin.config(text = s)
	else:
		g.delete_lines()
	root.after(10,update)
def update():
	global data, looping, NP, delay
	if looping == False:
		return
	data = []
	if NP <= 900:
		t,v = p.capture_hr(1,NP,delay)
		t2,v2 = p.capture_hr(2,NP,delay)
	else:
		t,v = p.capture(1,NP,delay)
		t2,v2 = p.capture(2,NP,delay)
	g.delete_lines()
	g.line(t,v)
	g.line(t2,v2)
	data.append([t,v])
	fa = eyemath.fit_sine(t, v)
	if fa != None:
		#g.line(t,fa[0], 8)
		rms = p.rms(v)
		f0 = fa[1][1] * 1000
		s = _('Freq = %5.0f Hz')%(fa[1][1]*1000)
	else:
		s = _('No Signal')
	msgwin.config(text=s)			# CRO part over	
	root.after(TIMER, update)	
def measure_phase():
	global data, NP, delay
	data = []
	phsum = 0.0
	n = 0
	try:
		fr = float(Freq.get())
		fs = p.set_sqr1(fr)
	except:
		msgwin.config(text=_('Invalid Frequency'))
		return	
	p.enable_wait_rising(6)
	for k in range(5):
		t,v = p.capture_hr(1,NP,delay)
		fa = eyemath.fit_sine(t, v)
		if fa != None:
			phsum += fa[1][2]
			n += 1
		else:
			msgwin.config(text=_('No Signal'))
	p.set_sqr1(-1)
	if n < 1:
		msgwin.config(text=_('Measurement failed'))
		return

	phase = phsum/n * (180.0/math.pi)
	print n,phase	
	s = _('Freq = %5.0f Hz Phase = %5.0f deg')%(fs, phase)
	msgwin.config(text=s)			
	data.append([t,v])
	g.delete_lines()
	g.line(t,v)
	p.disable_actions()
Exemple #6
0
def measure_phase():
    global data, NP, delay
    data = []
    phsum = 0.0
    n = 0
    try:
        fr = float(Freq.get())
        fs = p.set_sqr1(fr)
    except:
        msgwin.config(text=_('Invalid Frequency'))
        return
    p.enable_wait_rising(6)
    for k in range(5):
        t, v = p.capture_hr(1, NP, delay)
        fa = eyemath.fit_sine(t, v)
        if fa != None:
            phsum += fa[1][2]
            n += 1
        else:
            msgwin.config(text=_('No Signal'))
    p.set_sqr1(-1)
    if n < 1:
        msgwin.config(text=_('Measurement failed'))
        return

    phase = phsum / n * (180.0 / math.pi)
    #print n,phase
    s = _('Freq = %5.0f Hz Phase = %5.0f deg') % (fs, phase)
    msgwin.config(text=s)
    data.append([t, v])
    g.delete_lines()
    g.line(t, v)
    p.disable_actions()
Exemple #7
0
    def curveFit(self, t, v, tt=None, vv=None):
        """
        Curve fitting routine
        @param t : abscissa vector
        @param v : ordinate vector
        @param tt: abscissa vector
        @param vv: ordinate vector
        """
        if not self.measure:
            return
        if not EYEMATH:
            self.showhelp(
                'python-scipy not installed. Required for data fitting', 'red')
            return
        s = ''
        if self.chanmask in (1, 2):
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                rms = self.eye.rms(v)
                f0 = fa[1][1] * 1000
                s = 'CH%d: %5.2f V, F= %5.2f Hz' % (self.chanmask >> 1, rms,
                                                    f0)
            else:
                s = 'CH%d: nosig ' % (self.chanmask >> 1)

        elif self.chanmask == 3:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                rms = self.eye.rms(v)
                f0 = fa[1][1] * 1000
                ph0 = fa[1][2]
                s += 'CH0: %5.2f V, F= %5.2f Hz' % (rms, f0)
            else:
                s += 'CH0: no signal'
            fb = eyemath.fit_sine(tt, vv)
            if fb != None:
                rms = self.eye.rms(vv)
                f1 = fb[1][1] * 1000
                ph1 = fb[1][2]
                s = s + '<br/>CH1: %5.2f V, F= %5.2f Hz' % (rms, f1)
                if fa != None and abs(f0 - f1) < f0 * 0.1:
                    s = s + '<br/>dphi= %5.1f' % (
                        (ph1 - ph0) * 180.0 / math.pi)
            else:
                s += '<br/>CH1:no signal'
        self.showhelp(s, 'blue')
        return
Exemple #8
0
    def curveFit(self, t, v, tt=None, vv=None):
        """
        Curve fitting routine
        @param t : abscissa vector
        @param v : ordinate vector
        @param tt: abscissa vector
        @param vv: ordinate vector
        """
        if not self.measure:
            return
        if not EYEMATH:
            self.showhelp("python-scipy not installed. Required for data fitting", "red")
            return
        s = ""
        if self.chanmask in (1, 2):
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                rms = self.eye.rms(v)
                f0 = fa[1][1] * 1000
                s = "CH%d: %5.2f V, F= %5.2f Hz" % (self.chanmask >> 1, rms, f0)
            else:
                s = "CH%d: nosig " % (self.chanmask >> 1)

        elif self.chanmask == 3:
            fa = eyemath.fit_sine(t, v)
            if fa != None:
                rms = self.eye.rms(v)
                f0 = fa[1][1] * 1000
                ph0 = fa[1][2]
                s += "CH0: %5.2f V, F= %5.2f Hz" % (rms, f0)
            else:
                s += "CH0: no signal"
            fb = eyemath.fit_sine(tt, vv)
            if fb != None:
                rms = self.eye.rms(vv)
                f1 = fb[1][1] * 1000
                ph1 = fb[1][2]
                s = s + "<br/>CH1: %5.2f V, F= %5.2f Hz" % (rms, f1)
                if fa != None and abs(f0 - f1) < f0 * 0.1:
                    s = s + "<br/>dphi= %5.1f" % ((ph1 - ph0) * 180.0 / math.pi)
            else:
                s += "<br/>CH1:no signal"
        self.showhelp(s, "blue")
        return
Exemple #9
0
def measure_freq(e):
    w = e.widget
    tag = w.find_closest(e.x, e.y)
    item = w.itemcget(tag, 'tag')
    target = int(item.split()[0])
    if e.x < LPWIDTH / 2 and e.y < OFFSET and 2 < target < 8:
        # Selected IN1, IN2, SEN, SQR1 or SQR2
        freq = p.get_frequency(target)
        if freq > 0.5:
            r2f = p.r2ftime(target, target) * 1.0e-6
            msg(
                _('%4s : Freq = %5.3f. Duty Cycle = %5.1f %%') %
                (sources[target - 1], freq, r2f * freq * 100))
            s = _('%4s\n%5.3f Hz\n%5.1f %%') % (sources[target - 1], freq,
                                                r2f * freq * 100)
            g.disp(s)
        else:
            msg(_('No squarewave detected on %4s') % (sources[target - 1]))
    elif e.x > LPWIDTH / 2 and e.y > OFFSET and target < 3:
        # Selected CH1, CH2 or CH3
        if chan4[target][CHSRC] != 0 and chan4[
                target + 1][CHSRC] != 0:  # both channels active
            fa = eyemath.fit_sine(chan4[target][TDATA], chan4[target][VDATA])
            fb = eyemath.fit_sine(chan4[target + 1][TDATA],
                                  chan4[target + 1][VDATA])
            if fa != None and fb != None:
                v1 = fa[1][0]
                v2 = fb[1][0]
                f1 = fa[1][1] * 1000
                # millisecond x-axis gives frequency in kHz, convert it
                f2 = fb[1][1] * 1000
                p1 = fa[1][2]
                p2 = fb[1][2]
                s = _('%s: %5.3f V, %5.2f Hz | %s: %5.2f V, %5.3f Hz | Phase difference = %5.1f degree') \
                    % (channels[target], v1, f1, channels[target+1],v2, f2, (p2-p1)*180/3.1416)
                msg(s)
                s=_('%4s\n%5.3f Hz\n%5.1f %%') \
                   % (sources[target-1], freq, r2f*freq*100)
                g.disp(s)
            else:
                msg(_('Fitting of data failed. Try with Xmgrace'))
        else:
            msg(_('Selected channel and the next one should have data'), 'red')
Exemple #10
0
def show_ftr(ch):
	fa = eyemath.fit_sine(chan4[ch][TDATA],chan4[ch][VDATA])	# get frequency to decide suitable 'dt'
	if fa != None:
		fr = fa[1][1]*1000			# frequency in Hz
		dt = int(1.e6/ (20 * fr))	# dt in usecs, 20 samples per cycle
		t,v = p.capture(chan4[ch][CHSRC], 1800, dt)
		xa,ya = eyemath.fft(v,dt)
		eyeplot.plot(xa*1000,ya, title = _('Fourier Transform,power spectrum'), xl = _('Freq'), yl = _('Amp'))
		msg(_('%s Fourier transform done, Data saved to "fft.dat"') %(channels[seltag]))
		p.save([[xa,ya]],'fft.dat')
Exemple #11
0
def show_ftr(ch):
    fa = eyemath.fit_sine(chan4[ch][TDATA],chan4[ch][VDATA])	# get frequency to decide suitable 'dt'
    if fa != None:
        fr = fa[1][1]*1000        # frequency in Hz
        dt = int(1.e6/ (20 * fr)) # dt in usecs, 20 samples per cycle
        t,v = p.capture(chan4[ch][CHSRC], 1800, dt)
        xa,ya = eyemath.fft(v,dt)
        eyeplot.plot(xa*1000,ya,
                     title = _('Fourier Transform,power spectrum'),
                     xl = _('Freq'), yl = _('Amp'))
        msg(_('%s Fourier transform done, Data saved to "fft.dat"')
            % (channels[seltag]))
        p.save([[xa,ya]],'fft.dat')
Exemple #12
0
def capture():
    global data, outmask, looping, NP, delay
    if looping == True:
        msgwin.config(text=_('Already Running'))
        return
    p.write_outputs(outmask)
    time.sleep(0.5)
    t, v = p.capture(0, NP, delay)
    p.write_outputs(0)
    g.delete_lines()
    g.line(t, v)
    data = t, v
    fa = eyemath.fit_sine(t, v)
    if fa != None:
        rms = p.rms(v)
        pa = fa[1]
        s = _('CH0 : %5.1f V , %5.1f Hz ') % (rms, pa[1] * 1000)
        msgwin.config(text=s)
Exemple #13
0
def capture():
	global data, outmask, looping, NP, delay
	if looping == True: 
		msgwin.config(text = _('Already Running'))
		return
	p.write_outputs(outmask)
	time.sleep(0.5)
	t, v = p.capture(0,NP,delay)
	p.write_outputs(0)
	g.delete_lines()
	g.line(t,v)
	data = t,v
	fa = eyemath.fit_sine(t,v)
	if fa != None:
		rms = p.rms(v)
		pa = fa[1]
		s = _('CH0 : %5.1f V , %5.1f Hz ') %(rms, pa[1]*1000)
		msgwin.config(text = s)
Exemple #14
0
def update():
	global data, looping, NP, delay
	if looping == False:
		return
	data = []
	t,v = p.capture(0,NP,delay)
	g.delete_lines()
	g.line(t,v)
	data.append([t,v])
	fa = eyemath.fit_sine(t, v)
	if fa != None:
		#g.line(t,fa[0], 8)
		rms = p.rms(v)
		f0 = fa[1][1] * 1000
		s = _('Freq = %5.0f Hz')%(fa[1][1]*1000)
	else:
		s = _('No Signal')
	msgwin.config(text=s)			# CRO part over	
	root.after(TIMER, update)	
Exemple #15
0
def update():
	global data, looping, NP, delay
	data = []
	if looping == False:
		return
	t,v,tt,vv = p.capture01(NP,delay)
	for k in range(len(vv)): vv[k] -= 2.5
	g.delete_lines()
	g.line(t,v)
	g.line(tt,vv,1)
	data.append([t,v])
	data.append([tt,vv])
	fa = eyemath.fit_sine(t, v)
	if fa != None:
		#g.line(t,fa[0], 8)
		rms = p.rms(v)
		f0 = fa[1][1] * 1000
		s = _('Phase = %5.0f deg')%(fa[1][2]*180/math.pi)
	else:
		s = _('No Signal')
	msgwin.config(text=s)			# CRO part over	
	root.after(TIMER, update)	
def update():
    global data, looping, NP, delay
    data = []
    if looping == False:
        return
    t, v, tt, vv = p.capture01(NP, delay)
    for k in range(len(vv)):
        vv[k] -= 2.5
    g.delete_lines()
    g.line(t, v)
    g.line(tt, vv, 1)
    data.append([t, v])
    data.append([tt, vv])
    fa = eyemath.fit_sine(t, v)
    if fa != None:
        #g.line(t,fa[0], 8)
        rms = p.rms(v)
        f0 = fa[1][1] * 1000
        s = _('Phase = %5.0f deg') % (fa[1][2] * 180 / math.pi)
    else:
        s = _('No Signal')
    msgwin.config(text=s)  # CRO part over
    root.after(TIMER, update)
Exemple #17
0
    def routine_work(self):
        global NP, delay, chanmask, measure, lissa, EYEMATH
        s = ''
        self.trace = []
        # In the final stage, move this to a Try block.
        if lissa == True:
            t, v, tt, vv = self.eye.capture01(NP, delay)
            g.delete_lines()
            g.setWorld(-5, -5, 5, 5, 'mS', 'V')
            g.line(v, vv)
            self.trace.append([v, vv])
        elif chanmask == 1 or chanmask == 2:  # Waveform display code
            t, v = self.eye.capture(chanmask - 1, NP, delay)
            g.delete_lines()
            g.line(t, v, chanmask - 1)
            self.trace.append([t, v])
        elif chanmask == 3:
            t, v, tt, vv = self.eye.capture01(NP, delay)
            g.delete_lines()
            g.line(t, v)
            g.line(tt, vv, 1)
            self.trace.append([t, v])
            self.trace.append([tt, vv])
        if measure == 1 and EYEMATH == False:
            showhelp('python-scipy not installed. Required for data fitting',
                     'red')
        if measure == 1 and lissa == False and EYEMATH == True:  # Curve Fitting
            if chanmask == 1 or chanmask == 2:
                fa = eyemath.fit_sine(t, v)
                if fa != None:
                    #g.line(t,fa[0], 8)
                    rms = self.eye.rms(v)
                    f0 = fa[1][1] * 1000
                    s = 'CH%d: %5.2f V, F= %5.2f Hz' % (chanmask >> 1, rms, f0)
                else:
                    s = 'CH%d: nosig' % (chanmask >> 1)

            elif chanmask == 3:
                fa = eyemath.fit_sine(t, v)
                if fa != None:
                    #g.line(t,fa[0],8)
                    rms = self.eye.rms(v)
                    f0 = fa[1][1] * 1000
                    ph0 = fa[1][2]
                    s += 'CH0: %5.2f V, %5.2f Hz' % (rms, f0)
                else:
                    s += 'CH0: no signal '
                fb = eyemath.fit_sine(tt, vv)
                if fb != None:
                    #g.line(tt,fb[0],8)
                    rms = self.eye.rms(vv)
                    f1 = fb[1][1] * 1000
                    ph1 = fb[1][2]
                    s = s + ' | CH1: %5.2f V, %5.2f Hz' % (rms, f1)
                    if fa != None and abs(f0 - f1) < f0 * 0.1:
                        s = s + ' | dphi= %5.1f' % (
                            (ph1 - ph0) * 180.0 / math.pi)
                else:
                    s += '| CH1:no signal '
        msgwin.config(text=s)  # CRO part over

        v = self.eye.get_voltage(6)  # CS voltage
        self.labset(27, '%5.3f V' % v)
        v = self.eye.get_voltage(0)  # A0
        self.labset(26, '%5.3f V' % v)
        v = self.eye.get_voltage(1)  # A1
        self.labset(25, '%5.3f V' % v)
        v = self.eye.get_voltage(2)  # A2
        self.labset(24, '%5.3f V' % v)
        v = self.eye.get_voltage(4)  # SENSOR
        self.labset(23, '%5.3f V' % v)

        res = self.eye.read_inputs()  # Set the color based on Input Levels
        if res & 1:  # ID0
            self.tw[1].config(bg=pgreen)
        else:
            self.tw[1].config(bg='gray')
        if res & 2:  # ID1
            self.tw[2].config(bg=pgreen)
        else:
            self.tw[2].config(bg='gray')
        if res & 4:  # T15 input
            self.tw[15].config(bg=pgreen)
        else:
            self.tw[15].config(bg='gray')
        if res & 8:  # Sensor Input
            self.tw[22].config(bg=pgreen)
        else:
            self.tw[22].config(bg='gray')

        if self.NOSQR2 == False:
            freq = self.eye.get_sqr2()
            if freq > 0:
                self.labset(8, '%5.1f Hz' % freq)
            else:
                self.labset(8, '0 Hz')
                self.NOSQR2 = True

        if self.NOSF == False:
            freq = self.eye.sensor_frequency()
            if freq > 0:
                self.labset(22, '%5.1f Hz' % freq)
            else:
                self.labset(22, '0 Hz')
                self.NOSF = True
def update():
    global delay, NP, delay, VPERDIV,data, CMERR, Freq
    # fix division results when using Python3
    NP=int(NP)
    delay=int(delay)
    if CMERR == True:
        CMERR = False 
        msg('')
    try:
        p.set_trig_source(1)
        t0, v0, t1, v1 = p.capture2_hr(1,2,NP,delay)
        g.delete_lines()
        vp.delete_lines()
        g.line(t0,v0,0)
        g.line(t1,v1,1)
        data[0][0] = t0
        data[0][1] = v0
        data[1][0] = t1
        data[1][1] = v1

        t2 = [0]*NP                # Calculate voltages A1 - A2
        v2 = [0]*NP
        for k in range(NP):
            t2[k] = t1[k]
            v2[k] = v0[k] - v1[k]
        g.line(t2,v2,2)
        data[2][0] = t2
        data[2][1] = v2
        # fitting
        fa = eyemath.fit_sine(t0,v0)
        fb = eyemath.fit_sine(t1,v1)
        fc = eyemath.fit_sine(t2,v2)
        if fa != None and fb != None and fc != None:
            rmsv0 = p.rms(v0)
            dv0 = 100 * abs( (rmsv0-p.rms(fa[0])) /rmsv0 )
            rmsv1 = p.rms(v1)
            dv1 = 100 * abs( (rmsv1-p.rms(fb[0])) /rmsv1 )
            a0 = fa[1][0]
            a1 = fb[1][0]
            a2 = fc[1][0]
            pd01 = math.atan(a2/a1)
            pd01_fit = fb[1][2]-fa[1][2]
            sign = pd01_fit / abs(pd01)
            pherr = abs(pd01) - abs(pd01_fit)
            pherr = abs(pherr/pd01) * 100
            #print 180./math.pi*pd01, 180./math.pi*pd01_fit, pherr
            if dv0 > 2.0 or dv1 > 2.0 or pherr > 100.0:                # Check for error in FIT
                g.line(t0, fa[0], col = 6)
                g.line(t1, fb[0], col = 5)
                msg(_('Error in Fit (A0: Black &Yellow, A1-Red & Green). Try Changing X-scale'))
            # Display even if there is an error in fitted results
            fr = fa[1][1]*1000                
            Fit0.config(text = _('Frequency = %5.1f Hz') %fr)
            Fit1.config(text = _('A1:Total voltage = %5.2f V') %(a0))
            Fit2.config(text = _('A2:Voltage across R = %5.2f V') %(a1))
            Fit3.config(text = _('A1-A2:Voltage across LC = %5.2f V') %(a2))
            Fit4.config(text = _('Phase Shift = %5.1f deg') %(pd01_fit*180./math.pi))
            #Fit5.config(text = _('arc tan(Vx/Vr)= %5.1f deg') %(pd01*180./math.pi))
            vp.line((0,0),(0, a1), col =1)
            rx = a0 * math.sin(pd01_fit)
            ry = a0 * math.cos(pd01_fit) 
            vp.line((0,rx),(0,ry))
            vp.line((0,sign*a2),(0, 0), col=2)
        else:
            msg(_('Curve Fitfing failed. Try changing X scale'))
    except:
        msg(_('Capture Error. Check input voltage levels.'),'red')
        CMERR = True
    root.after(10,update)
Exemple #19
0
def update():
	global delay, NP, delay, VPERDIV,data, CMERR, Freq
	if CMERR == True:
		CMERR = False 
		msg('')
	try:
		p.set_trig_source(1)
		t0,v0,t1,v1 = p.capture2_hr(1,2,NP,delay)
		g.delete_lines()
		vp.delete_lines()
		g.line(t0,v0,0)
		g.line(t1,v1,1)
		data[0][0] = t0
		data[0][1] = v0
		data[1][0] = t1
		data[1][1] = v1

		t2 = [0]*NP		# Calculate voltages A1 - A2
		v2 = [0]*NP
		for k in range(NP):
			t2[k] = t1[k]
			v2[k] = v0[k] - v1[k]
		g.line(t2,v2,2)
		data[2][0] = t2
		data[2][1] = v2
		# fitting
		fa = eyemath.fit_sine(t0,v0)
		fb = eyemath.fit_sine(t1,v1)
		fc = eyemath.fit_sine(t2,v2)
		if fa != None and fb != None and fc != None:
			rmsv0 = p.rms(v0)
			dv0 = 100 * abs( (rmsv0-p.rms(fa[0])) /rmsv0 )
			rmsv1 = p.rms(v1)
			dv1 = 100 * abs( (rmsv1-p.rms(fb[0])) /rmsv1 )
			a0 = fa[1][0]
			a1 = fb[1][0]
			a2 = fc[1][0]
			pd01 = math.atan(a2/a1)
			pd01_fit = fb[1][2]-fa[1][2]
			sign = pd01_fit / abs(pd01)
			pherr = abs(pd01) - abs(pd01_fit)
			pherr = abs(pherr/pd01) * 100
			#print 180./math.pi*pd01, 180./math.pi*pd01_fit, pherr
			if dv0 > 2.0 or dv1 > 2.0 or pherr > 100.0:		# Check for error in FIT
				g.line(t0, fa[0], col = 6)
				g.line(t1, fb[0], col = 5)
				msg(_('Error in Fit (A0: Black &Yellow, A1-Red & Green). Try Changing X-scale'))
			# Display even if there is an error in fitted results
			fr = fa[1][1]*1000		
			Fit0.config(text = _('Frequency = %5.1f Hz') %fr)
			Fit1.config(text = _('A1:Total voltage = %5.2f V') %(a0))
			Fit2.config(text = _('A2:Voltage across R = %5.2f V') %(a1))
			Fit3.config(text = _('A1-A2:Voltage across LC = %5.2f V') %(a2))
			Fit4.config(text = _('Phase Shift = %5.1f deg') %(pd01_fit*180./math.pi))
			#Fit5.config(text = _('arc tan(Vx/Vr)= %5.1f deg') %(pd01*180./math.pi))
			vp.line((0,0),(0, a1), col =1)
			rx = a0 * math.sin(pd01_fit)
			ry = a0 * math.cos(pd01_fit) 
			vp.line((0,rx),(0,ry))
			vp.line((0,sign*a2),(0, 0), col=2)
		else:
			msg(_('Curve Fitfing failed. Try changing X scale'))
	except:
		msg(_('Capture Error. Check input voltage levels.'),'red')
		CMERR = True
	root.after(10,update)
from __future__ import print_function
'''
Connect pickup coil to A1 and Fit the sine wave for getting frequency.
From frequency of rotation of anemometer wind speed can be calculated
'''
import gettext
gettext.bindtextdomain("expeyes")
gettext.textdomain('expeyes')
_ = gettext.gettext

import expeyes.eyesj as ej
import expeyes.eyemath as em
from pylab import plot, show

p = ej.open()
t, v = p.capture(1, 400, 100)
try:
    vfit, par = em.fit_sine(t, v)
    print(par[1])  # second parameter is frequency
    print((t, v))
    plot(t, vfit)
    show()
except:
    print("No alternative signal, please make another try.")
Exemple #21
0
def update():
    global delay, NP, NC, VPERDIV, chan4, CMERR
    global NP, NC, delay,chan4
    chans = []                    # Update channel & color information
    index = []
    for m in range(len(chan4)):
        if chan4[m][0] > 0:
            chans.append(chan4[m][0])  # channel number
            index.append(m) # Store the used indices, for storing & fitting
    NC = len( chans)
    
    # force int types as NP and delay can come from float divisions
    # with Python3
    NP=int(NP)
    delay=int(delay)
    
    try:
        if NC == 1:
            chan4[index[0]][TDATA], \
                chan4[index[0]][VDATA] \
                =  p.capture_hr(chans[0], NP, delay)
            v1 = []
            for k in range(NP): v1.append(
                    chan4[index[0]][VDATA][k] +
                    chan4[index[0]][DOFFSET])
            g.delete_lines()
            g.line(chan4[index[0]][TDATA],v1, index[0])
        elif NC == 2:
            chan4[index[0]][TDATA],chan4[index[0]][VDATA], \
                chan4[index[1]][TDATA],chan4[index[1]][VDATA] = p.capture2_hr( chans[0],  chans[1], NP, delay)
            v1 = []
            v2 = []
            for k in range(NP): 
                v1.append(
                    chan4[index[0]][VDATA][k] +
                    chan4[index[0]][DOFFSET])
                v2.append(
                    chan4[index[1]][VDATA][k] +
                    chan4[index[1]][DOFFSET])
            g.delete_lines()
            g.line(chan4[index[0]][TDATA], v1, index[0])
            g.line(chan4[index[1]][TDATA], v2, index[1])
        elif NC == 3:
            chan4[index[0]][TDATA],chan4[index[0]][VDATA], chan4[index[1]][TDATA],chan4[index[1]][VDATA], \
                chan4[index[2]][TDATA],chan4[index[2]][VDATA] = p.capture3( chans[0], chans[1], chans[2], NP, delay)
            v1 = []
            v2 = []
            v3 = []
            for k in range(NP): 
                v1.append(
                    chan4[index[0]][VDATA][k] +
                    chan4[index[0]][DOFFSET])
                v2.append(
                    chan4[index[1]][VDATA][k] +
                    chan4[index[1]][DOFFSET])
                v3.append(
                    chan4[index[2]][VDATA][k] +
                    chan4[index[2]][DOFFSET])
            g.delete_lines()
            g.line(chan4[index[0]][TDATA], v1, index[0])
            g.line(chan4[index[1]][TDATA], v2, index[1])
            g.line(chan4[index[2]][TDATA], v3, index[2])
        elif NC == 4:
            chan4[index[0]][TDATA],chan4[index[0]][VDATA], chan4[index[1]][TDATA],chan4[index[1]][VDATA], \
                chan4[index[2]][TDATA],chan4[index[2]][VDATA], chan4[index[3]][TDATA],chan4[index[3]][VDATA] \
                = p.capture4( chans[0],  chans[1], chans[2], chans[3], NP, delay)
            v1 = []
            v2 = []
            v3 = []
            v4 = []
            for k in range(NP): 
                v1.append(
                    chan4[index[0]][VDATA][k] +
                    chan4[index[0]][DOFFSET])
                v2.append(
                    chan4[index[1]][VDATA][k] +
                    chan4[index[1]][DOFFSET])
                v3.append(
                    chan4[index[2]][VDATA][k] +
                    chan4[index[2]][DOFFSET])
                v4.append(
                    chan4[index[3]][VDATA][k] +
                    chan4[index[3]][DOFFSET])
            g.delete_lines()
            g.line(chan4[index[0]][TDATA], v1, index[0])
            g.line(chan4[index[1]][TDATA], v2, index[1])
            g.line(chan4[index[2]][TDATA], v3, index[2])
            g.line(chan4[index[3]][TDATA], v4, index[3])
        if CMERR == True: 
            CMERR = False
            msg('')
    except:
        msg(_('Communication Error. Check input voltage levels.'),
            'red')
        CMERR = True
	
    for k in range(4):
        if chan4[k][CHSRC] != 0 and chan4[k][FITFLAG] == 1:
            fa = eyemath.fit_sine(chan4[k][TDATA],chan4[k][VDATA])
            if fa != None:
                chan4[k][VFDAT] = fa[0]
                chan4[k][AMP] = abs(fa[1][0])
                chan4[k][FREQ] = fa[1][1]*1000
                chan4[k][PHASE] = fa[1][2] * 180/eyemath.pi
                s = _('%5.2f V, %5.1f Hz')\
                    %(chan4[k][AMP],chan4[k][FREQ])
                chan4[k][WFIT].config(text = s, fg= chancols[k])
    if looping.get() == '0':
        root.after(10,update)
Exemple #22
0
	def routine_work(self):
		global NP, delay, chanmask, measure, lissa, EYEMATH
		s = ''
		self.trace = []
								# In the final stage, move this to a Try block.
		if lissa == True:
			t,v,tt,vv = self.eye.capture01(NP,delay)
			g.delete_lines()
			g.setWorld(-5,-5,5,5,_('mS'),'V')
			g.line(v,vv)
			self.trace.append([v,vv])
		elif chanmask == 1 or chanmask == 2:				# Waveform display code 
			t, v = self.eye.capture(chanmask-1,NP,delay)
			g.delete_lines()
			g.line(t,v,chanmask-1)
			self.trace.append([t,v])
		elif chanmask == 3:
			t,v,tt,vv = self.eye.capture01(NP,delay)
			g.delete_lines()
			g.line(t,v)
			g.line(tt,vv,1)
			self.trace.append([t,v])
			self.trace.append([tt,vv])
		if measure == 1 and EYEMATH == False:
			showhelp(_('python-scipy not installed. Required for data fitting'),'red')
		if measure == 1 and lissa == False and EYEMATH == True:		# Curve Fitting
			if chanmask == 1 or chanmask == 2:			
				fa = eyemath.fit_sine(t, v)
				if fa != None:
					#g.line(t,fa[0], 8)
					rms = self.eye.rms(v)
					f0 = fa[1][1] * 1000
					s = 'CH%d %5.2f V , F= %5.2f Hz'%(chanmask>>1, rms, f0)
				else:
					s = _('CH%d nosig ')%(chanmask>>1)

			elif chanmask == 3:	
				fa = eyemath.fit_sine(t,v)
				if fa != None:
					#g.line(t,fa[0],8)
					rms = self.eye.rms(v)
					f0 = fa[1][1]*1000
					ph0 = fa[1][2]
					s += 'CH0 : %5.2f V , %5.2f Hz '%(rms, f0)
				else:
					s += _('CH0: no signal ')
				fb = eyemath.fit_sine(tt,vv)
				if fb != None:
					#g.line(tt,fb[0],8)
					rms = self.eye.rms(vv)
					f1 = fb[1][1]*1000
					ph1 = fb[1][2]
					s = s + '| CH1 %5.2f V , %5.2f Hz'%(rms, f1)
					if fa != None and abs(f0-f1) < f0*0.1:
						s = s + _(' | dphi= %5.1f')%( (ph1-ph0)*180.0/math.pi)
				else:
					s += _('| CH1:no signal ')
		msgwin.config(text=s)			# CRO part over	

		v = self.eye.get_voltage(6)			# CS voltage
		self.labset(27, '%5.3f V'%v)					
		v = self.eye.get_voltage(0)			# A0
		self.labset(26, '%5.3f V'%v)
		v = self.eye.get_voltage(1)			# A1
		self.labset(25, '%5.3f V'%v)
		v = self.eye.get_voltage(2)			# A2
		self.labset(24, '%5.3f V'%v)
		v = self.eye.get_voltage(4)			# SENSOR
		self.labset(23, '%5.3f V'%v)

		res = self.eye.read_inputs()		# Set the color based on Input Levels
		if res & 1:								# ID0
			self.tw[1].config(bg = pgreen)				
		else:
			self.tw[1].config(bg = 'gray')		
		if res & 2:								# ID1
			self.tw[2].config(bg = pgreen)		
		else:
			self.tw[2].config(bg = 'gray')	
		if res & 4:								# T15 input
			self.tw[15].config(bg = pgreen)		
		else:
			self.tw[15].config(bg = 'gray')	
		if res & 8:								# Sensor Input
			self.tw[22].config(bg = pgreen)		
		else:
			self.tw[22].config(bg = 'gray')	

		if self.NOSQR2 == False:
			freq = self.eye.get_sqr2()
			if freq > 0:
				self.labset(8,'%5.1f Hz'%freq)
			else:
				self.labset(8, '0 Hz')
				self.NOSQR2 = True

		if self.NOSF == False:
			freq = self.eye.sensor_frequency()
			if freq > 0:
				self.labset(22,'%5.1f Hz'%freq)
			else:
				self.labset(22, '0 Hz')
				self.NOSF = True
from __future__ import print_function

'''
Connect pickup coil to A1 and Fit the sine wave for getting frequency.
From frequency of rotation of anemometer wind speed can be calculated
'''
import gettext
gettext.bindtextdomain("expeyes")
gettext.textdomain('expeyes')
_ = gettext.gettext

import expeyes.eyesj as ej
import expeyes.eyemath as em
from pylab import plot, show

p = ej.open()
t,v= p.capture(1,400,100)
try:
    vfit, par = em.fit_sine(t,v)
    print (par[1]) # second parameter is frequency
    print((t,v))
    plot(t, vfit)
    show()
except:
    print("No alternative signal, please make another try.")