/// <summary> /// Calculates the time. /// </summary> /// <returns>The time.</returns> /// <param name="timebase">Timebase.</param> /// <param name="marker1">Marker1.</param> /// <param name="marker2">Marker2.</param> /// <param name="frame">Frame.</param> public static double CalculateTime(TimeBase timebase, Marker marker1, Marker marker2, Grid frame) { var pixelsPerDiv = frame.Width / frame.HorizontalDivs; var distance = Math.Abs(marker1.Value - marker2.Value); var divs = distance / pixelsPerDiv; var result = divs * TimeBaseConverter.ToSeconds(timebase); return(result); }
private void UpdateVoltTimeIndicator() { if (_ScopeView.ScalingTime) { _VoltTimeIndicator.Text = TimeBaseConverter.ToString(Oscilloscope.TimeBase); } else { _VoltTimeIndicator.Text = VoltsPerDivisionConverter.ToString(Oscilloscope.Channels [_ScopeView.SelectedChannel].VoltsPerDivision, Oscilloscope.Channels [_ScopeView.SelectedChannel].AttenuationFactor); } }
/// <summary> /// Registers the pinch recognizer. /// </summary> private void RegisterPinchRecognizer() { float startDistance; startDistance = 0.0f; pinchGesture = new UIPinchGestureRecognizer((pg) => { if (pg.State == UIGestureRecognizerState.Began) { if (pg.NumberOfTouches == 2) { CGPoint firstPoint = pg.LocationOfTouch(0, this); CGPoint secondPoint = pg.LocationOfTouch(1, this); startDistance = CalculateDistance(firstPoint, secondPoint); } VoltTimeIndicator.Hidden = false; } else if (pg.State == UIGestureRecognizerState.Changed) { float distance; if (pg.NumberOfTouches == 2) { CGPoint firstPoint = pg.LocationOfTouch(0, this); CGPoint secondPoint = pg.LocationOfTouch(1, this); distance = CalculateDistance(firstPoint, secondPoint); if (PointsAreHorizontal(firstPoint, secondPoint)) { if (distance > startDistance + 50) { startDistance = distance; wfs210.TimeBase = wfs210.TimeBase.Cycle(-1); } else if (distance < startDistance - 50) { startDistance = distance; wfs210.TimeBase = wfs210.TimeBase.Cycle(1); } VoltTimeIndicator.Text = TimeBaseConverter.ToString(wfs210.TimeBase); } else { if (distance > startDistance + 50) { startDistance = distance; Service.Execute(new NextVoltsPerDivisionCommand(SelectedChannel)); } else if (distance < startDistance - 50) { startDistance = distance; Service.Execute(new PreviousVoltsPerDivisionCommand(SelectedChannel)); } VoltTimeIndicator.Text = VoltsPerDivisionConverter.ToString(wfs210.Channels [SelectedChannel].VoltsPerDivision, wfs210.Channels [SelectedChannel].AttenuationFactor); } } } else if (pg.State == UIGestureRecognizerState.Ended) { VoltTimeIndicator.Hidden = true; ApplyMarkerValuesToScope(); OnNewData(null); Update(); } }); this.AddGestureRecognizer(pinchGesture); }
/// <summary> /// Generates a signal. /// </summary> /// <param name="channel">Channel.</param> /// <param name="addNoise">If set to <c>true</c> add noise.</param> public void GenerateSignal(Channel channel, bool addNoise = true) { Oscilloscope oscilloscope = channel.DeviceContext.Device; Random random = new Random(); double randomPhase = random.Next(0, 628) / 100; if (!oscilloscope.Hold) { channel.Samples.Overflow = false; for (int i = 0; i < channel.Samples.Count; i++) { double gnd = 1, input = 0; double tl = oscilloscope.Trigger.Level; switch (channel.InputCoupling) { case InputCoupling.AC: gnd = 1; input = 0; break; case InputCoupling.DC: gnd = 1; input = 1; break; case InputCoupling.GND: gnd = 0; input = 0; break; } double samplesPerVolt = 25 / VoltsPerDivisionConverter.ToVolts(channel.VoltsPerDivision, channel.AttenuationFactor); double a = Amplitude * samplesPerVolt; double o = input * Offset * samplesPerVolt; double samplesPerDiv; switch (oscilloscope.TimeBase) { case TimeBase.Tdiv1us: samplesPerDiv = 10; break; case TimeBase.Tdiv2us: samplesPerDiv = 20; break; default: samplesPerDiv = 50; break; } double t = i * TimeBaseConverter.ToSeconds(oscilloscope.TimeBase) / samplesPerDiv; if ((Math.Floor(a) == 0) || (Math.Floor(gnd) == 0)) { Phase = 0; } else if ((tl < (channel.YPosition - (o + a))) || (tl > (channel.YPosition + (o + a)))) { Phase = randomPhase; } else if (oscilloscope.Trigger.Slope == TriggerSlope.Rising) { Phase = Math.Asin(((channel.YPosition - o) - tl) / a); } else { Phase = Math.PI - Math.Asin((tl - (channel.YPosition - o)) / a); } int value = (int)Math.Round(channel.YPosition - gnd * (o + a * Math.Sin(2 * Math.PI * Frequency * t + Phase))); channel.Samples [i] = (byte)value.LimitToRange(0, 255); } if (addNoise) { GenerateNoise(channel); } } }
void UpdateTimeBaseText() { lblTimebase.Text = TimeBaseConverter.ToString(Oscilloscope.TimeBase); }