static void Main(string[] args) { ILever a = new Lever(true); ILever b = new Lever(true); IGate gate = new NandGate(a, b); Console.WriteLine(gate.State); }
public void Write_HighPosEdge_High() { var uut = new NandGate(); 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.High); }
public void Result_NotAllInputsTrue_ShouldReturnTrue() { // Arrange NandGate Gate = new NandGate(); Gate.In = new INode[] { HighStartPoint, LowStartPoint }; // Act bool output = Gate.Result(); // Assert Assert.IsTrue(output); }
public void perfect_gate_one_unknown_input() { var nandGate = new NandGate(TTLGateTypeEnum.Perfect, 2); // if any input is zero, then the output is high nandGate.Inputs[0].InputSample.Add(new InputSignal { Timing = 0, Voltage = 0, Unknown = false }); var result = nandGate.Output(0); Assert.Equal(5, result); }
public void perfect_gate_logic_test(double input1, double input2, double expectedOutput) { var nandGate = new NandGate(TTLGateTypeEnum.Perfect, 2); nandGate.Inputs[0].InputSample.Add(new InputSignal { Timing = 0, Voltage = input1, Unknown = false }); nandGate.Inputs[1].InputSample.Add(new InputSignal { Timing = 0, Voltage = input2, Unknown = false }); var result = nandGate.Output(0); Assert.Equal(expectedOutput, result); }
public void Write_HighHighHighHigh_Low() { var uut = new NandGate(); 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.Low); }
public SRLatch(TTLGateTypeEnum gateType) { var nandGate1 = new NandGate(gateType, 2); var nandGate2 = new NandGate(gateType, 2); Gates.Add(nandGate1); Gates.Add(nandGate2); // C0 Connections.Add(new Connection { Source = nandGate1, Termination = nandGate2.Inputs[0] }); // C1 Connections.Add(new Connection { Source = nandGate2, Termination = nandGate1.Inputs[1] }); // C2 Connections.Add(new Connection { Source = S, Termination = nandGate1.Inputs[0] }); // C3 Connections.Add(new Connection { Source = R, Termination = nandGate2.Inputs[1] }); }
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); }
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()); }
public JKMasterSlave(TTLGateTypeEnum gateType) { var nandGate1 = new NandGate(gateType, 2) { CircuitName = "G1" }; var nandGate2 = new NandGate(gateType, 2) { CircuitName = "G2" }; var nandGate3 = new NandGate(gateType, 2) { CircuitName = "G3" }; var nandGate4 = new NandGate(gateType, 2) { CircuitName = "G4" }; var nandGate5 = new NandGate(gateType, 2) { CircuitName = "G5" }; var nandGate6 = new NandGate(gateType, 2) { CircuitName = "G6" }; var nandGate7 = new NandGate(gateType, 3) { CircuitName = "G7" }; var nandGate8 = new NandGate(gateType, 3) { CircuitName = "G8" }; var inverter = new Inverter(gateType) { CircuitName = "G9" }; Gates.Add(nandGate1); Gates.Add(nandGate2); Gates.Add(nandGate3); Gates.Add(nandGate4); Gates.Add(nandGate5); Gates.Add(nandGate6); Gates.Add(nandGate7); Gates.Add(nandGate8); Gates.Add(inverter); // C0 Connections.Add(new Connection { Source = J, Termination = nandGate7.Inputs[1], Name = "C0" }); // C1 Connections.Add(new Connection { Source = Clk, Termination = nandGate7.Inputs[2], Name = "C1" }); // C2 Connections.Add(new Connection { Source = Clk, Termination = nandGate8.Inputs[0], Name = "C2" }); // C3 Connections.Add(new Connection { Source = K, Termination = nandGate8.Inputs[1], Name = "C3" }); // C4 Connections.Add(new Connection { Source = nandGate7, Termination = nandGate5.Inputs[0], Name = "C4" }); // C5 Connections.Add(new Connection { Source = nandGate8, Termination = nandGate6.Inputs[1], Name = "C5" }); // C6 Connections.Add(new Connection { Source = nandGate6, Termination = nandGate5.Inputs[1], Name = "C6" }); // C7 Connections.Add(new Connection { Source = nandGate5, Termination = nandGate6.Inputs[0], Name = "C7" }); // C8 Connections.Add(new Connection { Source = nandGate5, Termination = nandGate3.Inputs[0], Name = "C8" }); // C9 Connections.Add(new Connection { Source = nandGate6, Termination = nandGate4.Inputs[1], Name = "C9" }); // C10 Connections.Add(new Connection { Source = inverter, Termination = nandGate3.Inputs[1], Name = "C10" }); // C11 Connections.Add(new Connection { Source = inverter, Termination = nandGate4.Inputs[0], Name = "C11" }); // C12 Connections.Add(new Connection { Source = nandGate3, Termination = nandGate1.Inputs[0], Name = "C12" }); // C13 Connections.Add(new Connection { Source = nandGate4, Termination = nandGate2.Inputs[1], Name = "C13" }); // C14 Connections.Add(new Connection { Source = nandGate2, Termination = nandGate1.Inputs[1], Name = "C14" }); // C15 Connections.Add(new Connection { Source = nandGate1, Termination = nandGate2.Inputs[0], Name = "C15" }); // C16 Connections.Add(new Connection { Source = nandGate1, Termination = nandGate8.Inputs[2], Name = "C16" }); // C17 Connections.Add(new Connection { Source = Clk, Termination = inverter.Inputs[0], Name = "C17" }); // C18 Connections.Add(new Connection { Source = nandGate2, Termination = nandGate7.Inputs[0], Name = "C18" }); }
public JKFlipFlop(TTLGateTypeEnum gateType) { var nandGate1 = new NandGate(gateType, 2) { CircuitName = "G1" }; var nandGate2 = new NandGate(gateType, 2) { CircuitName = "G2" }; var nandGate3 = new NandGate(gateType, 3) { CircuitName = "G3" }; var nandGate4 = new NandGate(gateType, 3) { CircuitName = "G4" }; Gates.Add(nandGate1); Gates.Add(nandGate2); Gates.Add(nandGate3); Gates.Add(nandGate4); // C0 Connections.Add(new Connection { Source = J, Termination = nandGate3.Inputs[1], Name = "C0" }); // C1 Connections.Add(new Connection { Source = Clk, Termination = nandGate3.Inputs[2], Name = "C1" }); // C2 Connections.Add(new Connection { Source = nandGate2, // QNot Termination = nandGate3.Inputs[0], Name = "C2" }); // C3 Connections.Add(new Connection { Source = K, Termination = nandGate4.Inputs[1], Name = "C3" }); // C4 Connections.Add(new Connection { Source = Clk, Termination = nandGate4.Inputs[0], Name = "C4" }); // C5 Connections.Add(new Connection { Source = nandGate1, // Q Termination = nandGate4.Inputs[2], Name = "C5" }); // C6 Connections.Add(new Connection { Source = nandGate1, Termination = nandGate2.Inputs[0], Name = "C6" }); // C7 Connections.Add(new Connection { Source = nandGate2, Termination = nandGate1.Inputs[1], Name = "C7" }); // C8 Connections.Add(new Connection { Source = nandGate3, Termination = nandGate1.Inputs[0], Name = "C8" }); // C9 Connections.Add(new Connection { Source = nandGate4, Termination = nandGate2.Inputs[1], Name = "C9" }); }