private void CreateInternals() { this.backAnd = new AndGate(this.PinA, this.PinB); this.backOr = new OrGate(this.PinA, this.PinB); this.frontAnd = new AndGate(); this.notGate = new NotGate(); }
public FullSubtractor() { input0 = new Bit(); input1 = new Bit(); inputB = new Bit(); outputS = new Bit(); outputB = new Bit(); input0.Draggable = false; input1.Draggable = false; inputB.Draggable = false; outputS.Draggable = false; outputB.Draggable = false; input0.Deletable = false; input1.Deletable = false; inputB.Deletable = false; outputS.Deletable = false; outputB.Deletable = false; input0.Bittype = Bit.BitType.Input; input1.Bittype = Bit.BitType.Input; inputB.Bittype = Bit.BitType.Input; outputS.Bittype = Bit.BitType.Output; outputB.Bittype = Bit.BitType.Output; xor1 = new XOrGate(); xor2 = new XOrGate(); and1 = new AndGate(); and2 = new AndGate(); or1 = new OrGate(); not1 = new NotGate(); not2 = new NotGate(); Connections.CrossConnect(input0.OutputPoint, xor1.InputPoint0); Connections.CrossConnect(input1.OutputPoint, xor1.InputPoint1); Connections.CrossConnect(input0.OutputPoint, not1.InputPoint); Connections.CrossConnect(not1.OutputPoint, and1.InputPoint0); Connections.CrossConnect(input1.OutputPoint, and1.InputPoint1); Connections.CrossConnect(xor1.OutputPoint, xor2.InputPoint0); Connections.CrossConnect(inputB.OutputPoint, xor2.InputPoint1); Connections.CrossConnect(xor1.OutputPoint, not2.InputPoint); Connections.CrossConnect(not2.OutputPoint, and2.InputPoint0); Connections.CrossConnect(inputB.OutputPoint, and2.InputPoint1); Connections.CrossConnect(xor2.OutputPoint, outputS.InputPoint); Connections.CrossConnect(and1.OutputPoint, or1.InputPoint0); Connections.CrossConnect(and2.OutputPoint, or1.InputPoint1); Connections.CrossConnect(or1.OutputPoint, outputB.InputPoint); this.Controls.Add(input0); this.Controls.Add(input1); this.Controls.Add(inputB); this.Controls.Add(outputS); this.Controls.Add(outputB); this.ContextMenuStrip = cms; }
static void Main(string[] args) { var test = new NeuralNet(2, 1, 3, 5); var andGate = new AndGate(); var notGate = new NotGate(); var orGate = new OrGate(); test.TrainWithData(orGate, 10000); }
public void AndGateTest03() { var g = new AndGate(); g.Inputs.Add(new DigitalSignal(true)); g.Outputs.Add(new DigitalSignal()); g.Calculate(); Assert.AreEqual(false, g.Outputs.First().State); }
public void test_one_input_and_gate(int input, int output) { var andGate = new AndGate(TTLGateTypeEnum.Perfect, 1); andGate.Inputs[0].InputSample.Add(new InputSignal { Timing = 0, Voltage = input, Unknown = false }); Assert.Equal(output, andGate.Output(0)); }
public AndGate Build() { var gate = new AndGate(); foreach (var input in _inputs) { gate.AddInput(input); } return(gate); }
public void Write_HighPosEdge_Low() { var uut = new AndGate(); var input1 = uut.AddInput().CreateConnection(); var input2 = uut.AddInput().CreateConnection(); var output = uut.Output.CreateConnection(); input1.Write(DigitalLevel.High); input2.Write(DigitalLevel.PosEdge); uut.Output.Level.Should().Be(DigitalLevel.Low); }
public void Result_NotAllInputsTrue_ShouldReturnFalse() { // Arrange AndGate Gate = new AndGate(); Gate.In = new INode[] { HighStartPoint, LowStartPoint }; // Act bool output = Gate.Result(); // Assert Assert.IsFalse(output); }
public void ttl_and_gate_logic_tests(double input1, double input2, double expectedOutput) { var andGate = new AndGate(TTLGateTypeEnum.Perfect, 2); andGate.Inputs[0].InputSample.Add(new InputSignal { Timing = 0, Voltage = input1, Unknown = false }); andGate.Inputs[1].InputSample.Add(new InputSignal { Timing = 0, Voltage = input2, Unknown = false }); Assert.Equal(expectedOutput, andGate.Output(0)); }
public void Test_RemoveComponent() { Circuit circuit = new Circuit(); var and_gate = new AndGate(); var true_const = new TrueConst(); circuit.AddComponent(and_gate); circuit.AddComponent(true_const); circuit.Connect(true_const, 0, and_gate, 0); circuit.Connect(and_gate, 0, and_gate, 1); circuit.RemoveComponent(and_gate); circuit.RemoveComponent(true_const); }
public void AndGateTest00() { var g = new AndGate(); Assert.IsNotNull(g); Assert.IsNotNull(g.Inputs); Assert.IsNotNull(g.Outputs); Assert.IsNotNull(g.Pins); Assert.IsTrue(g.Inputs.Count == 0); Assert.IsTrue(g.Outputs.Count == 0); Assert.IsTrue(g.Pins.Count == 0); }
public void TestAnd() { AutoResetEvent autoResetEvent = new AutoResetEvent(false); bool result = false; // Create the elements var source1 = new LogicEmitter(); var source2 = new LogicEmitter(); var gate = new AndGate(); var sink = new LogicActionInvoker(value => { result = value; autoResetEvent.Set(); }); // Build the graph source1.AttachOutput(gate.Input1); source2.AttachOutput(gate.Input2); gate.AttachOutput(sink); // Start processing source1.StartProcessing(); source2.StartProcessing(); gate.StartProcessing(); // Test initial state Assert.IsFalse(result); const int timeout = Timeout.Infinite; // Emit and test source1.EmitTrue(); source2.EmitTrue(); Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout"); Assert.IsTrue(result); // Emit and test source1.EmitTrue(); source2.EmitFalse(); Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout"); Assert.IsFalse(result); // Emit and test source1.EmitFalse(); source2.EmitTrue(); Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout"); Assert.IsFalse(result); // Emit and test source1.EmitFalse(); source2.EmitFalse(); Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout"); Assert.IsFalse(result); }
public void test_two_inputs_one_inverted(double input1, double input2, double expectedOutput) { // input 2 is inverted var andGate = new AndGate(TTLGateTypeEnum.Perfect, 2); andGate.Inputs[0].InputSample.Add(new InputSignal { Timing = 0, Voltage = input1, Unknown = false }); andGate.Inputs[1].InputSample.Add(new InputSignal { Timing = 0, Voltage = input2, Unknown = false }); andGate.Inputs[1].InputInverted = true; Assert.Equal(expectedOutput, andGate.Output(0)); }
public void Write_HighHighHighHigh_High() { var uut = new AndGate(); var input1 = uut.AddInput().CreateConnection(); var input2 = uut.AddInput().CreateConnection(); var input3 = uut.AddInput().CreateConnection(); var input4 = uut.AddInput().CreateConnection(); var output = uut.Output.CreateConnection(); input1.Write(DigitalLevel.High); input2.Write(DigitalLevel.High); input3.Write(DigitalLevel.High); input4.Write(DigitalLevel.High); uut.Output.Level.Should().Be(DigitalLevel.High); }
// can be removed; just trying out stuff public void BasicComposite_NoBuilders() { var notGate = new NotGate(); notGate.SetInput(Generator.AnInactiveSignal()); var orGate = new OrGate(); orGate.AddInput(Generator.AnInactiveSignal()); orGate.AddInput(Generator.AnActiveSignal()); var andGate = new AndGate(); andGate.AddInput(notGate); andGate.AddInput(orGate); Assert.True(andGate.Output()); }
public void TestMethod1() { var engine = new SimulationEngine(); var input = new TestInput(engine, 2, 2); var output = new TestOutput(engine, 2); var gate = new AndGate(engine, 2, 2); input.Connect(gate.In); output.Connect(gate.Out); input.SetValues(DataValue.Unsigned(1, 2), DataValue.Unsigned(1, 2)); for (var i = 0; i < 10; i++) { engine.Tick(); } output.ValidateValues(DataValue.Unsigned(1, 2)); }
public And4() { input0 = new Nibble(); input1 = new Nibble(); output0 = new Nibble(); input0.Deletable = false; input1.Deletable = false; output0.Deletable = false; input0.Draggable = false; input1.Draggable = false; output0.Draggable = false; and0 = new AndGate(); and1 = new AndGate(); and2 = new AndGate(); and3 = new AndGate(); Connections.CrossConnect(input0.OutputPoint0, and0.InputPoint0); Connections.CrossConnect(input0.OutputPoint1, and1.InputPoint0); Connections.CrossConnect(input0.OutputPoint2, and2.InputPoint0); Connections.CrossConnect(input0.OutputPoint3, and3.InputPoint0); Connections.CrossConnect(input1.OutputPoint0, and0.InputPoint1); Connections.CrossConnect(input1.OutputPoint1, and1.InputPoint1); Connections.CrossConnect(input1.OutputPoint2, and2.InputPoint1); Connections.CrossConnect(input1.OutputPoint3, and3.InputPoint1); Connections.CrossConnect(and0.OutputPoint, output0.InputPoint0); Connections.CrossConnect(and1.OutputPoint, output0.InputPoint1); Connections.CrossConnect(and2.OutputPoint, output0.InputPoint2); Connections.CrossConnect(and3.OutputPoint, output0.InputPoint3); this.Controls.Add(input0); this.Controls.Add(input1); this.Controls.Add(output0); this.ContextMenuStrip = cms; }
public void AndGateConstructor() { AndGate gate = new AndGate(); Assert.IsNotNull(gate.A); Assert.IsNotNull(gate.B); Assert.AreEqual(gate.A.Emitter, gate.B.Collector); gate.SetInput(0, false); gate.SetInput(1, false); Assert.AreEqual(gate.GetOutput(), false); gate.SetInput(0, true); gate.SetInput(1, false); Assert.AreEqual(gate.GetOutput(), false); gate.SetInput(0, false); gate.SetInput(1, true); Assert.AreEqual(gate.GetOutput(), false); gate.SetInput(0, true); gate.SetInput(1, true); Assert.AreEqual(gate.GetOutput(), true); }
private static void Main() { var a = new Switch(); var b = new Switch(); var c = new Switch(); #region AndGate Console.WriteLine("AND Gate Test"); Console.WriteLine("------------------------"); var inv = new Inverter(); b.AttachTo(inv, 0); var andGate = new AndGate(); a.AttachTo(andGate, 0); inv.AttachTo(andGate, 1); a.State = true; b.State = true; Console.WriteLine(andGate); b.State = false; Console.WriteLine(andGate); #endregion #region 8 bit input Console.WriteLine("\n8 bit input"); Console.WriteLine("------------------------"); var inp = new EightBitInput { State = 200 }; Console.WriteLine(inp); #endregion #region FullAdder Console.WriteLine("\nFull Adder"); Console.WriteLine("------------------------"); a.State = false; b.State = false; var add = new FullAdder(); a.AttachTo(add, 0); b.AttachTo(add, 1); c.AttachTo(add, 2); a.State = true; Console.WriteLine(add); b.State = true; Console.WriteLine(add); b.State = false; c.State = true; Console.WriteLine(add); #endregion #region 8 bit Adder Console.WriteLine("\n8 bit Adder"); Console.WriteLine("------------------------"); var in1 = new EightBitInput(); var in2 = new EightBitInput(); var add1 = new EightBitAdder(); in1.AttachTo(add1); in2.AttachTo(add1, 8); in1.State = 10; in2.State = 5; Console.WriteLine(add1); var display = new EightBitDisplay(); add1.AttachToAll(display); Console.WriteLine(display); #endregion #region Dual 8 bit adder Console.WriteLine("\nDual 8 bit Adder"); Console.WriteLine("------------------------"); var in3 = new EightBitInput(); var in4 = new EightBitInput(); var add2 = new EightBitAdder(); in3.AttachTo(add2); in4.AttachTo(add2, 8); in3.State = 4; in4.State = 11; var add3 = new EightBitAdder(); add1.AttachToAll(add3); add2.AttachToAll(add3, 8); var display2 = new EightBitDisplay(); add3.AttachToAll(display2); Console.WriteLine(display2); #endregion #region D FlipFlop with pseudo clock Console.WriteLine("\nD FlipFlop with pseudo clock"); Console.WriteLine("------------------------"); var d = new DFlipFlop(); var val = new Switch(); var clk = new Switch(); val.AttachTo(d, 0); clk.AttachTo(d, 1); val.State = true; clk.State = true; Console.WriteLine(d); val.State = false; clk.State = false; clk.State = true; Console.WriteLine(d); #endregion #region D Flip Flop with real clock Console.WriteLine("\nD Flip Flop with real clock"); Console.WriteLine("------------------------"); var clk1 = new Clock(1.Hz()); clk1.AttachTo(d, 1); val.State = true; Console.WriteLine(d); Thread.Sleep(2000); Console.WriteLine(d); val.State = false; Console.WriteLine(d); Thread.Sleep(2000); Console.WriteLine(d); #endregion #region SR Flip Flop with pseudo clock Console.WriteLine("\nSR Flip Flop with pseudo clock"); Console.WriteLine("------------------------"); var sr = new SRFlipFlop(); var sr1 = new Switch(); var sr2 = new Switch(); var sr3 = new Switch(); sr1.AttachTo(sr, 0); sr2.AttachTo(sr, 1); sr3.AttachTo(sr, 2); sr1.State = true; sr3.State = true; sr3.State = false; Console.WriteLine(sr); sr2.State = true; sr3.State = true; sr3.State = false; Console.WriteLine(sr); sr1.State = false; sr3.State = true; sr3.State = false; Console.WriteLine(sr); #endregion }
public void TestInitialize() { // Arrange TopLevelEvent topLevelEvent = new TopLevelEvent { Title = "top_level_event" }; AndGate andGate1 = new AndGate { Title = "and_gate_1" }; Event event1 = new Event { Title = "event_1" }; Event event2 = new Event { Title = "event_2" }; OrGate orGate1 = new OrGate { Title = "or_gate_1" }; OrGate orGate2 = new OrGate { Title = "or_gate_2" }; BasicEvent basicEvent1 = new BasicEvent { Title = "basic_event_1", Lambda = 0.2 }; BasicEvent basicEvent2 = new BasicEvent { Title = "basic_event_2", Lambda = 0.1 }; BasicEvent basicEvent3 = new BasicEvent { Title = "basic_event_3", Lambda = 0.3 }; BasicEvent basicEvent4 = new BasicEvent { Title = "basic_event_4", Lambda = 0.1 }; Connection connection1 = new Connection { From = topLevelEvent, To = andGate1 }; Connection connection2 = new Connection { From = andGate1, To = event1 }; Connection connection3 = new Connection { From = andGate1, To = event2 }; Connection connection4 = new Connection { From = event1, To = orGate1 }; Connection connection5 = new Connection { From = orGate1, To = basicEvent1 }; Connection connection6 = new Connection { From = orGate1, To = basicEvent2 }; Connection connection7 = new Connection { From = event2, To = orGate2 }; Connection connection8 = new Connection { From = orGate2, To = basicEvent3 }; Connection connection9 = new Connection { From = orGate2, To = basicEvent4 }; topLevelEvent.Children.Add(andGate1); andGate1.Parents.Add(topLevelEvent); andGate1.Children.Add(event1); andGate1.Children.Add(event2); event1.Parents.Add(andGate1); event1.Children.Add(orGate1); event2.Parents.Add(andGate1); event2.Children.Add(orGate2); orGate1.Parents.Add(event1); orGate1.Children.Add(basicEvent1); orGate1.Children.Add(basicEvent2); orGate2.Parents.Add(event2); orGate2.Children.Add(basicEvent3); orGate2.Children.Add(basicEvent4); basicEvent1.Parents.Add(orGate1); basicEvent2.Parents.Add(orGate1); basicEvent3.Parents.Add(orGate2); basicEvent4.Parents.Add(orGate2); project = new Project { Title = "TestProject", FaultTree = new FaultTree { Elements = new ObservableCollection <Element> { topLevelEvent, andGate1, event1, event2, orGate1, orGate2, basicEvent1, basicEvent2, basicEvent3, basicEvent4 }, Connections = new ObservableCollection <Connection> { connection1, connection2, connection3, connection4, connection5, connection6, connection7, connection8, connection9 } } }; }
private void CreateInternals() { this.andGate = new AndGate(this.PinA, this.PinB); this.notGate = new NotGate(); }
static void Main(string[] args) { NandGate nand = new NandGate(); AndGate and = new AndGate(); OrGate or = new OrGate(); XorGate xor = new XorGate(); Gate[] gates = { nand, and, or, xor }; foreach (Gate gate in gates) { Console.WriteLine(gate.ToTable()); } NandGate nand3 = new NandGate(); NandGate nand5 = new NandGate(); AndGate and1 = new AndGate(); AndGate and9 = new AndGate(); AndGate and7 = new AndGate(); OrGate or2 = new OrGate(); OrGate or6 = new OrGate(); OrGate or10 = new OrGate(); XorGate xor4 = new XorGate(); XorGate xor8 = new XorGate(); StringBuilder sb = new StringBuilder(); bool[] opts = { true, false }; sb.AppendLine("A B C D O"); foreach (bool A in opts) { foreach (bool B in opts) { foreach (bool C in opts) { foreach (bool D in opts) { and1.Set(A, A); and1.Latch(); or2.Set(A, B); or2.Latch(); nand3.Set(B, C); nand3.Latch(); xor4.Set(C, nand3.getOutput()); xor4.Latch(); nand5.Set(and1.getOutput(), or2.getOutput()); nand5.Latch(); or6.Set(and1.getOutput(), nand5.getOutput()); or6.Latch(); and7.Set(or2.getOutput(), xor4.getOutput()); and7.Latch(); xor8.Set(D, xor4.getOutput()); xor8.Latch(); and9.Set(or6.getOutput(), and7.getOutput()); and9.Latch(); or10.Set(and9.getOutput(), xor8.getOutput()); or10.Latch(); sb.AppendLine(Convert.ToInt16(A) + " " + Convert.ToInt16(B) + " " + Convert.ToInt16(C) + " " + Convert.ToInt16(D) + " " + Convert.ToInt16(or10.getOutput())); } } } } Console.WriteLine(sb.ToString()); }
private void CreateInternals() { this.xorGate = new XorGate(this.PinA, this.PinB); this.andGate = new AndGate(this.PinA, this.PinB); }
public void Test_CircuitSimulate_SmallTree() { LogicComponent true_constant1 = new TrueConst(); LogicComponent true_constant2 = new TrueConst(); LogicComponent false_constant = new FalseConst(); LogicComponent and_gate = new AndGate(); LogicComponent or_gate = new OrGate(); LogicComponent true_constant1_connection = new Connection(); LogicComponent true_constant2_connection = new Connection(); LogicComponent false_constant_connection = new Connection(); LogicComponent and_gate_connection = new Connection(); Circuit circuit = new Circuit(); /* Test will be 2 TRUEs connected to an AND gate. * This AND gate and a FALSE will then be connected to the OR gate. */ circuit.AddComponent(true_constant1); circuit.AddComponent(true_constant2); circuit.AddComponent(false_constant); circuit.AddComponent(and_gate); circuit.AddComponent(or_gate); circuit.AddComponent(true_constant1_connection); circuit.AddComponent(true_constant2_connection); circuit.AddComponent(false_constant_connection); circuit.AddComponent(and_gate_connection); circuit.Connect(true_constant1, 0, true_constant1_connection, 0); circuit.Connect(true_constant2, 0, true_constant2_connection, 0); circuit.Connect(true_constant1_connection, 0, and_gate, 0); circuit.Connect(true_constant2_connection, 0, and_gate, 1); circuit.Connect(and_gate, 0, and_gate_connection, 0); circuit.Connect(false_constant, 0, false_constant_connection, 0); circuit.Connect(and_gate_connection, 0, or_gate, 0); circuit.Connect(false_constant_connection, 0, or_gate, 1); // Try first step: the output of the connections from the constants should change. circuit.Simulate(); Assert.AreEqual(true_constant1_connection.Outputs, new List <bool>() { true }); Assert.AreEqual(true_constant2_connection.Outputs, new List <bool>() { true }); // Try second step: the output from the and gate should change. circuit.Simulate(); Assert.AreEqual(and_gate.Outputs, new List <bool>() { true }); // Try third step: the output of the connections from the and gate should change. circuit.Simulate(); Assert.AreEqual(and_gate_connection.Outputs, new List <bool>() { true }); // Try fourth step: the output of the or gate should change. circuit.Simulate(); Assert.AreEqual(or_gate.Outputs, new List <bool>() { true }); // Ensure the state has stabilized into the expected state: for (int i = 0; i < 100; i++) { circuit.Simulate(); Assert.AreEqual(true_constant1_connection.Outputs, new List <bool>() { true }); Assert.AreEqual(true_constant2_connection.Outputs, new List <bool>() { true }); Assert.AreEqual(and_gate.Outputs, new List <bool>() { true }); Assert.AreEqual(and_gate_connection.Outputs, new List <bool>() { true }); Assert.AreEqual(or_gate.Outputs, new List <bool>() { true }); } }
public void GalieloStringTest1() { // Arrange TopLevelEvent topLevelEvent = new TopLevelEvent { Title = "top_level_event" }; AndGate andGate1 = new AndGate { Title = "and_gate_1" }; Event event1 = new Event { Title = "event_1" }; Event event2 = new Event { Title = "event_2" }; OrGate orGate1 = new OrGate { Title = "or_gate_1" }; OrGate orGate2 = new OrGate { Title = "or_gate_2" }; BasicEvent basicEvent1 = new BasicEvent { Title = "basic_event_1", Lambda = 0.2 }; BasicEvent basicEvent2 = new BasicEvent { Title = "basic_event_2", Lambda = 0.1 }; BasicEvent basicEvent3 = new BasicEvent { Title = "basic_event_3", Lambda = 0.3 }; BasicEvent basicEvent4 = new BasicEvent { Title = "basic_event_4", Lambda = 0.1 }; Connection connection1 = new Connection { From = topLevelEvent, To = andGate1 }; Connection connection2 = new Connection { From = andGate1, To = event1 }; Connection connection3 = new Connection { From = andGate1, To = event2 }; Connection connection4 = new Connection { From = event1, To = orGate1 }; Connection connection5 = new Connection { From = orGate1, To = basicEvent1 }; Connection connection6 = new Connection { From = orGate1, To = basicEvent2 }; Connection connection7 = new Connection { From = event2, To = orGate2 }; Connection connection8 = new Connection { From = orGate2, To = basicEvent3 }; Connection connection9 = new Connection { From = orGate2, To = basicEvent4 }; Project project = new Project { Title = "TestProject", FaultTree = new FaultTree { Elements = new ObservableCollection <Element> { topLevelEvent, andGate1, event1, event2, orGate1, basicEvent1, basicEvent2, orGate2, basicEvent3, basicEvent4 }, Connections = new ObservableCollection <Connection> { connection1, connection2, connection3, connection4, connection5, connection6, connection7, connection8, connection9 } } }; string expected = "toplevel top_level_event;" + "top_level_event and event_1 event_2;" + "basic_event_1 lambda = 0.2 dorm = 0;" + "basic_event_2 lambda = 0.1 dorm = 0;" + "basic_event_3 lambda = 0.3 dorm = 0;" + "basic_event_4 lambda = 0.1 dorm = 0;" + "event_1 or basic_event_1 basic_event_2;" + "event_2 or basic_event_3 basic_event_4;"; // Act string actual = project.FaultTree.GetGalileoString(); // Assert Assert.AreEqual(expected, actual, "Galileo string is ot correct."); }
private void InitializeCommands() { AddItemToCanvasCommand = new RelayCommand <Point>((Point p) => { switch (SelectedElement.DisplayTitle) { case "Event": Event addEvent = new Event { Title = "event_" + ++eventCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addEvent); SelectedCanvasElement = addEvent; break; case "Basic event": BasicEvent addLeafEvent = new BasicEvent { Title = "basic_event_" + ++basicEventCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addLeafEvent); SelectedCanvasElement = addLeafEvent; break; case "AND gate": AndGate addAndGate = new AndGate { Title = "and_gate_" + ++andGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addAndGate); SelectedCanvasElement = addAndGate; break; case "OR gate": OrGate addOrGate = new OrGate { Title = "or_gate_" + ++orGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addOrGate); SelectedCanvasElement = addOrGate; break; case "Vote gate": VoteGate addVoteGate = new VoteGate { Title = "vote_gate_" + ++voteGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addVoteGate); SelectedCanvasElement = addVoteGate; break; case "Priority AND gate": PriorityAndGate addPriorityAndGate = new PriorityAndGate { Title = "priority_and_gate_" + ++priorityAndGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addPriorityAndGate); SelectedCanvasElement = addPriorityAndGate; break; case "Priority OR gate": PriorityOrGate addPriorityOrGate = new PriorityOrGate { Title = "priority_or_gate_" + ++priorityOrGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addPriorityOrGate); SelectedCanvasElement = addPriorityOrGate; break; case "Warm spare gate": WarmSpareGate addWarmSpareGate = new WarmSpareGate { Title = "warm_spare_gate_" + ++warmSpareGateCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addWarmSpareGate); SelectedCanvasElement = addWarmSpareGate; break; case "Functional dependency": FunctionalDependency addFunctionalDependency = new FunctionalDependency { Title = "functional_dependency_" + ++functionalDependencyCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addFunctionalDependency); SelectedCanvasElement = addFunctionalDependency; break; case "Probabilistic dependency": ProbabilisticDependency addProbabilisticDependency = new ProbabilisticDependency { Title = "probabilistic_dependency_" + ++probabilisticDependencyCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addProbabilisticDependency); SelectedCanvasElement = addProbabilisticDependency; break; case "Sequence enforcer": SequenceEnforcer addSequenceEnforcer = new SequenceEnforcer { Title = "sequence_enforcer_" + ++sequenceEnforcerCounter, X = p.X, Y = p.Y, }; Project.FaultTree.Elements.Add(addSequenceEnforcer); SelectedCanvasElement = addSequenceEnforcer; break; default: break; } }); GenerateOutputCommand = new RelayCommand(() => { OutputText = Project.FaultTree.GetGalileoString(); }); ShowJSONCommand = new RelayCommand(() => { OutputText = GetJsonString(); }); ListConnectionsCommand = new RelayCommand(() => { OutputText = Project.FaultTree.ListConnections(); }); DeleteElementCommand = new RelayCommand(() => { var tempElement = SelectedCanvasElement; if (tempElement.DisplayTitle == "Top level event") { return; } Project.FaultTree.RemoveElement(tempElement); if (Project.FaultTree.Elements.Count > 0) { SelectedCanvasElement = Project.FaultTree.Elements[0]; } else { SelectedCanvasElement = null; } }); RemoveConnectionsCommand = new RelayCommand(() => { Project.FaultTree.RemoveConnections(SelectedCanvasElement); }); CopyCommand = new RelayCommand(() => { dataPackage.SetText(OutputText); Clipboard.SetContent(dataPackage); }); ClearCommand = new RelayCommand(() => { OutputText = string.Empty; }); ToGalileoCommand = new RelayCommand(async() => { await SaveToFileAsync(Project.FaultTree.GetGalileoString()); }); ToJsonCommand = new RelayCommand(async() => { await SaveToFileAsync(GetJsonString()); }); }
protected override void Awake() { base.Awake(); LogicComponent = new AndGate(); Canvas.Circuit.AddComponent(LogicComponent); }
//private Wire wi1, wi2; //here we initialize and connect all the components, as in Figure 5.9 in the book public CPU16() { wi1 = new Wire(); wi2 = new Wire(); and_D = new AndGate(); and_MW = new AndGate(); and_JM0 = new AndGate(); and_JM1 = new AndGate(); and_JM2 = new AndGate(); and_JMP = new AndGate(); not_Zero = new NotGate(); not_Neg = new NotGate(); not_A = new NotGate(); J_0 = new Wire(); JGT = new Wire(); JEQ = new Wire(); JGE = new Wire(); JLT = new Wire(); JNE = new Wire(); JLE = new Wire(); J_1 = new Wire(); JMP = new WireSet(3); or_A = new OrGate(); or_JMP = new OrGate(); Size = 16; Instruction = new WireSet(Size); MemoryInput = new WireSet(Size); MemoryOutput = new WireSet(Size); MemoryAddress = new WireSet(Size); InstructionAddress = new WireSet(Size); MemoryWrite = new Wire(); Reset = new Wire(); m_gALU = new ALU(Size); m_rPC = new Counter(Size); m_rA = new MultiBitRegister(Size); m_rD = new MultiBitRegister(Size); m_gAMux = new BitwiseMux(Size); m_gMAMux = new BitwiseMux(Size); m_gAMux.ConnectInput1(Instruction); m_gAMux.ConnectInput2(m_gALU.Output); m_rA.ConnectInput(m_gAMux.Output); m_gMAMux.ConnectInput1(m_rA.Output); m_gMAMux.ConnectInput2(MemoryInput); m_gALU.InputY.ConnectInput(m_gMAMux.Output); m_gALU.InputX.ConnectInput(m_rD.Output); m_rD.ConnectInput(m_gALU.Output); MemoryOutput.ConnectInput(m_gALU.Output); MemoryAddress.ConnectInput(m_rA.Output); InstructionAddress.ConnectInput(m_rPC.Output); m_rPC.ConnectInput(m_rA.Output); m_rPC.ConnectReset(Reset); //now, we call the code that creates the control unit ConnectControls(); }
static void HalfAdderTest() { var signalGenerator1 = new SignalGenerator(); var signalGenerator2 = new SignalGenerator(); bool signalHigh = true; bool longSignalHigh = true; for (int i = 0; i < 200; i++) { if (i % 20 == 0) { signalHigh = !signalHigh; } if (i % 40 == 0) { longSignalHigh = !longSignalHigh; } signalGenerator1.AddSample(signalHigh ? 5 : 0); signalGenerator2.AddSample(longSignalHigh ? 5 : 0); } var xorGate = new XorGate(TTLGateTypeEnum.Normal, 2); var andGate = new AndGate(TTLGateTypeEnum.Normal, 2); var circuit = new Circuit(); circuit.Gates.Add(xorGate); circuit.Gates.Add(andGate); circuit.Gates.Add(signalGenerator1); circuit.Gates.Add(signalGenerator2); circuit.Connections.Add(new Connection { Source = signalGenerator1, Termination = xorGate.Inputs[0] }); circuit.Connections.Add(new Connection { Source = signalGenerator2, Termination = xorGate.Inputs[1] }); circuit.Connections.Add(new Connection { Source = signalGenerator1, Termination = andGate.Inputs[0] }); circuit.Connections.Add(new Connection { Source = signalGenerator2, Termination = andGate.Inputs[1] }); circuit.RunCircuit(); for (int i = 0; i < 200; i++) { _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)} S:{xorGate.Output(i)} C:{andGate.Output(i)}"); } }
public AndGate(AndGate target) { targetGate = target; target.parentGate = this; }
private void ConnectControls() { or = new OrGate(); muxArray = new MuxGate[9]; NotGate not = new NotGate(); JGT = new AndGate(); JGE = new OrGate(); JLE = new OrGate(); JNE = new NotGate(); notArray = new NotGate[2]; for (int i = 0; i < notArray.Length; i++) { notArray[i] = new NotGate(); } m_gJumpMux = new BitwiseMultiwayMux(1, 3); jump = new WireSet(3); andForPCLoad = new AndGate(); Wire PCLoad = new Wire(); //1. m_gAMux.ConnectControl(Instruction[Type]); //2. connect control to mux 2 (selects A or M entrance to the ALU) m_gMAMux.ConnectControl(Instruction[A]); //3. consider all instruction bits only if C type instruction (MSB of instruction is 1) for (int i = 0; i < muxArray.Length; i++) { muxArray[i] = new MuxGate(); muxArray[i].ConnectInput1(new Wire()); muxArray[i].ConnectInput2(Instruction[i + 3]); muxArray[i].ConnectControl(Instruction[Type]); } //4. connect ALU control bits m_gALU.ZeroX.ConnectInput(muxArray[C1 - 3].Output); m_gALU.NotX.ConnectInput(muxArray[C2 - 3].Output); m_gALU.ZeroY.ConnectInput(muxArray[C3 - 3].Output); m_gALU.NotY.ConnectInput(muxArray[C4 - 3].Output); m_gALU.F.ConnectInput(muxArray[C5 - 3].Output); m_gALU.NotOutput.ConnectInput(muxArray[C6 - 3].Output); //5. connect control to register D (very simple) m_rD.Load.ConnectInput(muxArray[D2 - 3].Output); //6. connect control to register A (a bit more complicated) not.ConnectInput(Instruction[Type]); or.ConnectInput1(not.Output); or.ConnectInput2(muxArray[D1 - 3].Output); m_rA.Load.ConnectInput(or.Output); //7. connect control to MemoryWrite MemoryWrite.ConnectInput(muxArray[D3 - 3].Output); //8. create inputs for jump mux notArray[0].ConnectInput(m_gALU.Zero); notArray[1].ConnectInput(m_gALU.Negative); //JGT: JGT.ConnectInput1(notArray[0].Output); JGT.ConnectInput2(notArray[1].Output); //JGE: JGE.ConnectInput1(m_gALU.Zero); JGE.ConnectInput2(notArray[1].Output); //JNE: JNE.ConnectInput(notArray[0].Output); //JLE: JLE.ConnectInput1(m_gALU.Zero); JLE.ConnectInput2(m_gALU.Negative); WireSet JGTOut = new WireSet(1); WireSet JEQOut = new WireSet(1); WireSet JLTOut = new WireSet(1); WireSet JGEOut = new WireSet(1); WireSet JNEOut = new WireSet(1); WireSet JLEOut = new WireSet(1); JGTOut[0].ConnectInput(JGT.Output); JEQOut[0].ConnectInput(m_gALU.Zero); JLTOut[0].ConnectInput(m_gALU.Negative); JGEOut[0].ConnectInput(JGE.Output); JNEOut[0].ConnectInput(JNE.Output); JLEOut[0].ConnectInput(JLE.Output); //9. connect jump mux (this is the most complicated part) jump[0].ConnectInput(Instruction[J3]); jump[1].ConnectInput(Instruction[J2]); jump[2].ConnectInput(Instruction[J1]); m_gJumpMux.ConnectControl(jump); m_gJumpMux.ConnectInput(0, new WireSet(1)); m_gJumpMux.ConnectInput(1, JGTOut); m_gJumpMux.ConnectInput(2, JEQOut); m_gJumpMux.ConnectInput(3, JGEOut); m_gJumpMux.ConnectInput(4, JLTOut); m_gJumpMux.ConnectInput(5, JNEOut); m_gJumpMux.ConnectInput(6, JLEOut); m_gJumpMux.Inputs[7].Value = 1; //10. connect PC load control andForPCLoad.ConnectInput1(m_gJumpMux.Output[0]); andForPCLoad.ConnectInput2(Instruction[Type]); m_rPC.ConnectLoad(andForPCLoad.Output); }
private LightComponent duplicateAt(Type type, Vector2Int position, int rotation, bool flipped) { //makes a duplicate of the component passed in LightComponent result = null; if (type == typeof(AndGate)) { result = new AndGate(position, rotation, flipped); } else if (type == typeof(OrGate)) { result = new OrGate(position, rotation, flipped); } else if (type == typeof(NotGate)) { result = new NotGate(position, rotation, flipped); } else if (type == typeof(BufferGate)) { result = new BufferGate(position, rotation, flipped); } else if (type == typeof(NandGate)) { result = new NandGate(position, rotation, flipped); } else if (type == typeof(XorGate)) { result = new XorGate(position, rotation, flipped); } else if (type == typeof(XnorGate)) { result = new XnorGate(position, rotation, flipped); } else if (type == typeof(NorGate)) { result = new NorGate(position, rotation, flipped); } else if (type == typeof(Splitter)) { result = new Splitter(position, rotation, flipped); } else if (type == typeof(Reflector)) { result = new Reflector(position, rotation, flipped); } else if (type == typeof(GraphOutput)) { result = new GraphOutput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND)); } else if (type == typeof(GraphInput)) { result = new GraphInput(position, rotation, flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE)); } else { throw new System.Exception(type + " was not found when selecting the from the logic graph editor"); } return(result); }
private void ConnectControls() { //1. connect control of mux 1 (selects entrance to register A) m_gAMux.ConnectControl(Instruction[Type]); // opcode //2. connect control to mux 2 (selects A or M entrance to the ALU) m_gMAMux.ConnectControl(Instruction[A]); // a/m //3. consider all instruction bits only if C type instruction (MSB of instruction is 1) //4. connect ALU control bits m_gALU.ZeroX.ConnectInput(Instruction[C1]); m_gALU.NotX.ConnectInput(Instruction[C2]); m_gALU.ZeroY.ConnectInput(Instruction[C3]); m_gALU.NotY.ConnectInput(Instruction[C4]); m_gALU.F.ConnectInput(Instruction[C5]); m_gALU.NotOutput.ConnectInput(Instruction[C6]); //5. connect control to register D (very simple) and = new AndGate(); and.ConnectInput1(Instruction[Type]); and.ConnectInput2(Instruction[D2]); m_rD.Load.ConnectInput(and.Output); //6. connect control to register A (a bit more complicated) orOfA = new OrGate(); // shortcut for what we did in lesson "instead using and & not gates" // to implement as in lecture andOfA = new AndGate(); notOfA = new NotGate(); notOfA.ConnectInput(Instruction[Type]); andOfA.ConnectInput1(Instruction[Type]); andOfA.ConnectInput2(Instruction[D1]); orOfA.ConnectInput1(andOfA.Output); orOfA.ConnectInput2(notOfA.Output); m_rA.Load.ConnectInput(orOfA.Output); //7. connect control to MemoryWritea andOfMemoryWrite = new AndGate(); andOfMemoryWrite.ConnectInput1(Instruction[Type]); andOfMemoryWrite.ConnectInput2(Instruction[D3]); MemoryWrite.ConnectInput(andOfMemoryWrite.Output); //8. create inputs for jump mux Wire on = new Wire(); on.Value = 1; Wire off = new Wire(); off.Value = 0; m_gJumpMux = new BitwiseMultiwayMux(1, 3); // so i'm gonna use it as jump box in lesson jumpOr1 = new OrGate(); jumpOr1.ConnectInput1(m_gALU.Zero); jumpOr1.ConnectInput2(m_gALU.Negative); jumpNot1 = new NotGate(); jumpNot1.ConnectInput(jumpOr1.Output); jumpNot2 = new NotGate(); jumpNot2.ConnectInput(m_gALU.Negative); jumpNot3 = new NotGate(); jumpNot3.ConnectInput(m_gALU.Zero); jumpOr2 = new OrGate(); jumpOr2.ConnectInput1(m_gALU.Zero); jumpOr2.ConnectInput2(m_gALU.Negative); Wire input1 = off; // we did somthing like this in practical session Wire input2 = jumpNot1.Output; Wire input3 = m_gALU.Zero; Wire input4 = jumpNot2.Output; Wire input5 = m_gALU.Negative; Wire input6 = jumpNot3.Output; Wire input7 = jumpOr2.Output; Wire input8 = on; //9. connect jump mux (this is the most complicated part m_gJumpMux.Inputs[0][0].ConnectInput(input1); m_gJumpMux.Inputs[1][0].ConnectInput(input2); m_gJumpMux.Inputs[2][0].ConnectInput(input3); m_gJumpMux.Inputs[3][0].ConnectInput(input4); m_gJumpMux.Inputs[4][0].ConnectInput(input5); m_gJumpMux.Inputs[5][0].ConnectInput(input6); m_gJumpMux.Inputs[6][0].ConnectInput(input7); m_gJumpMux.Inputs[7][0].ConnectInput(input8); m_gJumpMux.Control[0].ConnectInput(Instruction[J3]); m_gJumpMux.Control[1].ConnectInput(Instruction[J2]); m_gJumpMux.Control[2].ConnectInput(Instruction[J1]); //10. connect PC load control andOfpc = new AndGate(); andOfpc.ConnectInput1(Instruction[Type]); andOfpc.ConnectInput2(m_gJumpMux.Output[0]); m_rPC.ConnectLoad(andOfpc.Output); }