public void Clock() { Gates.IOGates.Clock clk = new Gates.IOGates.Clock(500); Gates.IOGates.Clock.CalculatePrecession(); int cnt = 0; bool oldval = false; DateTime start = DateTime.Now; while (DateTime.Now - start < new TimeSpan(0, 0, 10)) { if (clk.Output[0] != oldval) { oldval = clk.Output[0]; cnt++; } } // 10 seconds at half a second period, two clicks per period ~ 40 clicks if (cnt < 38 || cnt > 42) { Assert.Fail("Unacceptable count = " + cnt.ToString()); } }
public Clock(Gates.IOGates.Clock gate) : base(gate, new TerminalID[] { new TerminalID(false, 0, Position.TOP) }) { _clock = gate; Rectangle r = new Rectangle(); r.Margin = new System.Windows.Thickness(5, 17, 5, 17); r.Width = this.Width - 10; r.Height = this.Height - 34; r.Stroke = Brushes.Black; r.StrokeThickness = 2; r.Fill = Brushes.White; myCanvas.Children.Add(r); Path ph = new Path(); ph.Data = StreamGeometry.Parse("M 10,22 h 5 v 5 h -5 v 5 h 5 v 5 h -5 v 5 h 5"); ph.Stroke = Brushes.Black; ph.StrokeThickness = 2; ph.Fill = Brushes.White; myCanvas.Children.Add(ph); nval = new TextBox(); // green team : // set event handler to call GotFocus() nval.GotFocus += new RoutedEventHandler(nval_GotFocus); nval.Margin = new System.Windows.Thickness(20, 23, 10, 23); nval.FontFamily = new FontFamily("Courier New"); nval.FontSize = 12; nval.TextAlignment = TextAlignment.Center; nval.Width = 34; nval.Height = 18; nval.Background = Brushes.AntiqueWhite; Binding bind = new Binding("Milliseconds"); bind.Source = _clock; bind.FallbackValue = "0"; bind.Mode = BindingMode.TwoWay; bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; bind.ValidatesOnExceptions = true; nval.SetBinding(TextBox.TextProperty, bind); Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message"); bindve.Source = nval; bindve.Mode = BindingMode.OneWay; bindve.FallbackValue = "Clock period in milliseconds"; nval.SetBinding(TextBox.ToolTipProperty, bindve); myCanvas.Children.Add(nval); }
public Clock(Gates.IOGates.Clock gate) : base(gate, new TerminalID[] { new TerminalID(false, 0, Position.TOP) }) { _clock = gate; Rectangle r = new Rectangle(); r.Margin = new System.Windows.Thickness(5, 17, 5, 17); r.Width = this.Width - 10; r.Height = this.Height - 34; r.Stroke = Brushes.Black; r.StrokeThickness = 2; r.Fill = Brushes.White; myCanvas.Children.Add(r); Path ph = new Path(); ph.Data = StreamGeometry.Parse("M 10,22 h 5 v 5 h -5 v 5 h 5 v 5 h -5 v 5 h 5"); ph.Stroke = Brushes.Black; ph.StrokeThickness = 2; ph.Fill = Brushes.White; myCanvas.Children.Add(ph); nval = new TextBox(); nval.Margin = new System.Windows.Thickness(20, 23, 10, 23); nval.FontFamily = new FontFamily("Courier New"); nval.FontSize = 12; nval.TextAlignment = TextAlignment.Center; nval.Width = 34; nval.Height = 18; nval.Background = Brushes.AntiqueWhite; Binding bind = new Binding("Milliseconds"); bind.Source = _clock; bind.FallbackValue = "0"; bind.Mode = BindingMode.TwoWay; bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; bind.ValidatesOnExceptions = true; nval.SetBinding(TextBox.TextProperty, bind); Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message"); bindve.Source = nval; bindve.Mode = BindingMode.OneWay; bindve.FallbackValue = "Clock period in milliseconds"; nval.SetBinding(TextBox.ToolTipProperty, bindve); myCanvas.Children.Add(nval); }
static void TestClock() { Circuit c = new Circuit(); Gates.IOGates.Clock clk1 = new Gates.IOGates.Clock(1000); Gates.IOGates.Clock clk2 = new Gates.IOGates.Clock(250); Gates.BasicGates.And mand = new Gates.BasicGates.And(); c.Add(clk1); c.Add(clk2); c.Add(mand); mand.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mand2_PropertyChanged); //mand[1] = true; c[new Terminal(0, mand)] = new Terminal(0, clk1); c[new Terminal(1, mand)] = new Terminal(0, clk2); }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) cname = UpdateICNames[cname]; return icl.GetIC(cname).AbGate.Clone(); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
//Modified method from CircuitXML.CreateGate Method private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) { numInputs = int.Parse(gate.Attribute("NumInputs").Value); } switch (gate.Attribute("Type").Value) { case "And": return(new Gates.BasicGates.And(numInputs)); case "Not": return(new Gates.BasicGates.Not()); case "Or": return(new Gates.BasicGates.Or(numInputs)); case "Nand": return(new Gates.BasicGates.Nand(numInputs)); case "Nor": return(new Gates.BasicGates.Nor(numInputs)); case "Xor": return(new Gates.BasicGates.Xor()); case "Xnor": return(new Gates.BasicGates.Xnor()); case "Buffer": return(new Gates.BasicGates.Buffer()); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return(ui); case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return(uo); case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return(ni); case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); return(no); case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return(clk); case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) { cname = UpdateICNames[cname]; } return(icl.GetIC(cname).AbGate.Clone()); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return(cmt); } throw new ArgumentException("unknown gate"); }