public DialogOscilloscope(CircuitRunner circuitRunner) { this.CircuitRunner = circuitRunner; this.CircuitRunner.DialogOscilloscope = this; this.oscilloscope = new Oscilloscope(this.CircuitRunner); this.GraphWidth = CircuitRunner.HistorySize * Oscillogram.DX; this.GraphHeight = 3 * Oscillogram.DY; this.DataContext = this; foreach (string probe in this.oscilloscope.Probes) { this.oscillograms.Add(new Oscillogram(probe, this.oscilloscope[probe])); } this.InitializeComponent(); this.timer = new Timer(new TimerCallback(this.TimerTick), null, TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(1.0 / 20.0)); }
public Oscilloscope(CircuitRunner circuitRunner) { foreach (FunctionProbe probe in circuitRunner.CircuitState.Probes) { if (probe.BitWidth == 1) { this.probes.Add(probe.Label); this.history.Add(probe.Label, new State[CircuitRunner.HistorySize]); } else { List <string> list = new List <string>(); this.probeLabels.Add(probe.Label, list); for (int i = 0; i < probe.BitWidth; i++) { string label = probe.Label + "[" + i + "]"; list.Add(label); this.probes.Add(label); this.history.Add(label, new State[CircuitRunner.HistorySize]); } } } this.probes.Sort(); }
private void Run() { PropertyChangedEventHandler editorPropertyChanged = null; try { this.running = true; this.Editor.Mainframe.Status = Properties.Resources.PowerOn; this.CircuitState = this.RootMap.Apply(CircuitRunner.HistorySize); this.CircuitState.FunctionUpdated += new EventHandler(this.OnFunctionUpdated); this.HasProbes = this.CircuitState.HasProbes; this.Editor.Mainframe.Dispatcher.Invoke(new Action(() => this.RootMap.TurnOn())); this.Editor.ActualFrequency = this.Editor.Frequency; if (this.Oscilloscoping && this.CircuitState.HasProbes) { Tracer.Assert(this.DialogOscilloscope == null); this.Editor.Mainframe.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(this.ShowOscilloscope)); } else { this.Oscilloscoping = false; } this.refreshingThread = new Thread(new ThreadStart(this.MonitorUI)); this.refreshingThread.IsBackground = true; this.refreshingThread.Name = "RefreshingThread"; this.refreshingThread.Priority = ThreadPriority.BelowNormal; using (this.evaluationGate = new AutoResetEvent(false)) { using (this.refreshingGate = new AutoResetEvent(false)) { using (PreciseTimer timer = new PreciseTimer(this.TimerTick, CircuitRunner.HalfPeriod(this.Editor.Project.Frequency))) { editorPropertyChanged = new PropertyChangedEventHandler((s, e) => { switch (e.PropertyName) { case "Frequency": timer.Period = CircuitRunner.HalfPeriod(this.Editor.Project.Frequency); break; case "IsMaximumSpeed": this.isMaxSpeed = this.Editor.Project.IsMaximumSpeed; if (this.isMaxSpeed) { AutoResetEvent resetEvent = this.evaluationGate; if (resetEvent != null) { resetEvent.Set(); } } break; } }); this.Editor.PropertyChanged += editorPropertyChanged; this.refreshingThread.Start(); this.flipCount = 1; timer.Start(); this.RunCircuit(); } } } } catch (ThreadAbortException) { // Do nothing } catch (Exception exception) { this.Editor.Mainframe.ReportException(exception); } finally { this.running = false; if (this.refreshingThread != null) { this.refreshingThread.Abort(); } if (editorPropertyChanged != null) { this.Editor.PropertyChanged -= editorPropertyChanged; } if (this.DialogOscilloscope != null) { this.DialogOscilloscope.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(this.DialogOscilloscope.Close) ); } if (this.RootMap != null) { while (this.updatingUI) { ; } this.Editor.Mainframe.Dispatcher.BeginInvoke( new Action(() => this.RootMap.Circuit.CircuitProject.InTransaction(() => this.RootMap.TurnOff())), DispatcherPriority.ApplicationIdle ); } this.Editor.Mainframe.Status = Properties.Resources.PowerOff; } }