static IC Nor() { Circuit nor = new Circuit(); Gates.BasicGates.And mand = new Gates.BasicGates.And(); Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not(); Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not(); Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput(); Gates.IOGates.UserInput in2 = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput(); nor.Add(mand); nor.Add(mnot1); nor.Add(mnot2); nor.Add(in1); nor.Add(in2); nor.Add(out1); nor[new Terminal(0, mnot1)] = new Terminal(0, in1); nor[new Terminal(0, mnot2)] = new Terminal(0, in2); nor[new Terminal(0, mand)] = new Terminal(0, mnot1); nor[new Terminal(1, mand)] = new Terminal(0, mnot2); nor[new Terminal(0, out1)] = new Terminal(0, mand); return(new IC(nor, new Gates.IOGates.UserInput[] { in1, in2 }, new Gates.IOGates.UserOutput[] { out1 }, "Nor")); }
static IC SRLatch() { Circuit sr = new Circuit(); IC nor1 = Nor(); IC nor2 = Nor(); Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput(); Gates.IOGates.UserInput in2 = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput(); Gates.IOGates.UserOutput out2 = new Gates.IOGates.UserOutput(); sr.Add(nor1); sr.Add(nor2); sr.Add(in1); sr.Add(in2); sr.Add(out1); sr.Add(out2); nor1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(nor_PropertyChanged); sr[new Terminal(0, nor1)] = new Terminal(0, in1); sr[new Terminal(1, nor2)] = new Terminal(0, in2); sr[new Terminal(1, nor1)] = new Terminal(0, nor2); sr[new Terminal(0, nor2)] = new Terminal(0, nor1); sr[new Terminal(0, out1)] = new Terminal(0, nor1); sr[new Terminal(0, out2)] = new Terminal(0, nor2); return(new IC(sr, new Gates.IOGates.UserInput[] { in1, in2 }, new Gates.IOGates.UserOutput[] { out1, out2 }, "SRLatch")); }
public UserOutput(Gates.IOGates.UserOutput gate) : base(gate, new TerminalID[] { new TerminalID(true, 0, Position.LEFT) }) { Ellipse r = new Ellipse(); r.Margin = new System.Windows.Thickness(15); r.Width = 34; r.Height = 34; r.Stroke = Brushes.Black; r.StrokeThickness = 2; r.Fill = Brushes.White; myCanvas.Children.Add(r); _r = new Ellipse(); _r.Margin = new System.Windows.Thickness(20); _r.Width = 24; _r.Height = 24; _r.Stroke = Brushes.Black; _r.StrokeThickness = 2; SetFill(); myCanvas.Children.Add(_r); myCanvas.Children.Add(txtName); myCanvas.Children.Add(txtFirstLetter); }
private Gates.IC CreateAndChain(int len) { Gates.Circuit andc = new Gates.Circuit(); andc.Start(); Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput(); andc.Add(in1); Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput(); andc.Add(out1); if (len > 1) { Gates.IC cand1 = CreateAndChain(len / 2); Gates.IC cand2 = CreateAndChain(len / 2); andc.Add(cand1); andc.Add(cand2); andc[new Gates.Terminal(0, cand1)] = new Gates.Terminal(0, in1); andc[new Gates.Terminal(0, cand2)] = new Gates.Terminal(0, cand1); andc[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, cand2); } else { Gates.BasicGates.And mand = new Gates.BasicGates.And(); andc.Add(mand); andc[new Gates.Terminal(0, mand)] = new Gates.Terminal(0, in1); andc[new Gates.Terminal(1, mand)] = new Gates.Terminal(0, in1); andc[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, mand); } return(new Gates.IC(andc, new Gates.IOGates.UserInput[] { in1 }, new Gates.IOGates.UserOutput[] { out1 }, "AndChain")); }
Gates.IC CreateSRLatch() { Gates.Circuit sr = new Gates.Circuit(); sr.Start(); Gates.IC nor1 = CreateNor(); Gates.IC nor2 = CreateNor(); Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput(); Gates.IOGates.UserInput in2 = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput(); Gates.IOGates.UserOutput out2 = new Gates.IOGates.UserOutput(); sr.Add(nor1); sr.Add(nor2); sr.Add(in1); sr.Add(in2); sr.Add(out1); sr.Add(out2); sr[new Gates.Terminal(0, nor1)] = new Gates.Terminal(0, in1); sr[new Gates.Terminal(1, nor2)] = new Gates.Terminal(0, in2); sr[new Gates.Terminal(1, nor1)] = new Gates.Terminal(0, nor2); sr[new Gates.Terminal(0, nor2)] = new Gates.Terminal(0, nor1); sr[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, nor1); sr[new Gates.Terminal(0, out2)] = new Gates.Terminal(0, nor2); return(new Gates.IC(sr, new Gates.IOGates.UserInput[] { in1, in2 }, new Gates.IOGates.UserOutput[] { out1, out2 }, "SRLatch")); }
static void uo_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { Gates.IOGates.UserOutput uo = (Gates.IOGates.UserOutput)sender; if (e.PropertyName == "Value") { Console.Out.WriteLine("UO NOTIFY: " + uo.Value.ToString()); } }
public void UserOutput() { Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo[0] = false; Assert.AreEqual(uo.Value, false); uo[0] = true; Assert.AreEqual(uo.Value, true); }
static void TestIC2() { Circuit c = new Circuit(); Gates.IOGates.UserInput ui_r = new Gates.IOGates.UserInput(); Gates.IOGates.UserInput ui_s = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); IC latch = SRLatch(); c.Add(ui_r); c.Add(ui_s); c.Add(uo); c.Add(latch); c[new Terminal(0, latch)] = new Terminal(0, ui_r); c[new Terminal(1, latch)] = new Terminal(0, ui_s); c[new Terminal(0, uo)] = new Terminal(0, latch); uo.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(uo_PropertyChanged); while (true) { Console.WriteLine("Ready for input (S = set, R = reset, X = hold, I = illegal)"); string val = Console.In.ReadLine(); if (val == "S") { ui_r.Value = false; ui_s.Value = true; } if (val == "R") { ui_s.Value = false; ui_r.Value = true; } if (val == "X") { ui_s.Value = false; ui_r.Value = false; } if (val == "I") { ui_s.Value = true; ui_r.Value = true; } } }
public void SRLatch() { Gates.Circuit c = new Gates.Circuit(); c.Start(); Gates.IOGates.UserInput ui_r = new Gates.IOGates.UserInput(); Gates.IOGates.UserInput ui_s = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); Gates.IC latch = CreateSRLatch(); c.Add(ui_r); c.Add(ui_s); c.Add(uo); c.Add(latch); c[new Gates.Terminal(0, latch)] = new Gates.Terminal(0, ui_r); c[new Gates.Terminal(1, latch)] = new Gates.Terminal(0, ui_s); c[new Gates.Terminal(0, uo)] = new Gates.Terminal(0, latch); for (int i = 0; i < 4; i++) { // SET ui_r.Value = false; ui_s.Value = true; Gates.PropagationThread.Instance.WaitOnPropagation(); Assert.AreEqual(true, uo.Value); // HOLD ui_r.Value = false; ui_s.Value = false; Gates.PropagationThread.Instance.WaitOnPropagation(); Assert.AreEqual(true, uo.Value); // RESET ui_r.Value = true; ui_s.Value = false; Gates.PropagationThread.Instance.WaitOnPropagation(); Assert.AreEqual(false, uo.Value); // HOLD ui_r.Value = false; ui_s.Value = false; Gates.PropagationThread.Instance.WaitOnPropagation(); Assert.AreEqual(false, uo.Value); } }
static void TestUserIO() { Circuit c = new Circuit(); Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not(); Gates.BasicGates.And mand = new Gates.BasicGates.And(); Gates.BasicGates.Not mnot3 = new Gates.BasicGates.Not(); Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not(); Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); c.Add(mnot1); c.Add(mnot2); c.Add(mand); c.Add(mnot3); c.Add(ui); c.Add(uo); uo.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(uo_PropertyChanged); c[new Terminal(0, mand)] = new Terminal(0, mnot2); c[new Terminal(0, mnot3)] = new Terminal(0, mand); c[new Terminal(0, mnot1)] = new Terminal(0, mnot3); c[new Terminal(0, mnot2)] = new Terminal(0, mnot1); c[new Terminal(1, mand)] = new Terminal(0, ui); c[new Terminal(0, uo)] = new Terminal(0, mnot3); do { Console.Out.WriteLine("Ready for X"); Console.In.ReadLine(); ui.Value = !ui.Value; } while (true); }
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"); }