/// <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); }
/// <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); } } }