当前位置: 首页>>代码示例>>C#>>正文


C# Circuit.analyze方法代码示例

本文整理汇总了C#中Circuit.analyze方法的典型用法代码示例。如果您正苦于以下问题:C# Circuit.analyze方法的具体用法?C# Circuit.analyze怎么用?C# Circuit.analyze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Circuit的用法示例。


在下文中一共展示了Circuit.analyze方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DFlipFlopTest

        public void DFlipFlopTest()
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var dflip0 = sim.Create<DFlipFlop>();

            var logicOut0 = sim.Create<LogicOutput>();
            var logicOut1 = sim.Create<LogicOutput>();

            sim.Connect(logicIn0.leadOut, dflip0.leadD);
            sim.Connect(logicIn1.leadOut, dflip0.leadCLK);

            sim.Connect(logicOut0.leadIn, dflip0.leadQ);
            sim.Connect(logicOut0.leadIn, dflip0.leadQL);

            sim.doTicks(200);

            Debug.Log();
            Debug.Log("D  ", dflip0.getLeadVoltage(0));
            Debug.Log("CLK", dflip0.getLeadVoltage(3));
            Debug.Log(" Q ", dflip0.getLeadVoltage(1));
            Debug.Log("|Q ", dflip0.getLeadVoltage(2));
            Debug.Log();

            logicIn0.toggle();
            logicIn1.toggle();
            sim.analyze();
            sim.doTicks(200);

            Debug.Log();
            Debug.Log("D  ", dflip0.getLeadVoltage(0));
            Debug.Log("CLK", dflip0.getLeadVoltage(3));
            Debug.Log(" Q ", dflip0.getLeadVoltage(1));
            Debug.Log("|Q ", dflip0.getLeadVoltage(2));
            Debug.Log();

            logicIn0.toggle();
            logicIn1.toggle();
            sim.analyze();
            sim.doTicks(200);

            Debug.Log();
            Debug.Log("D  ", dflip0.getLeadVoltage(0));
            Debug.Log("CLK", dflip0.getLeadVoltage(3));
            Debug.Log(" Q ", dflip0.getLeadVoltage(1));
            Debug.Log("|Q ", dflip0.getLeadVoltage(2));
            Debug.Log();

            Assert.Ignore();
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:53,代码来源:ChipTest.cs

示例2: AnalogSwitchTest

        public void AnalogSwitchTest()
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var analogSwitch0 = sim.Create<AnalogSwitch>();

            var grnd = sim.Create<Ground>();

            sim.Connect(logicIn0.leadOut, analogSwitch0.leadIn);
            sim.Connect(logicIn1.leadOut, analogSwitch0.leadSwitch);
            sim.Connect(analogSwitch0.leadOut, grnd.leadIn);

            logicIn0.toggle();
            logicIn1.toggle();

            sim.doTicks(100);
            Assert.AreEqual(0.25, Math.Round(grnd.getCurrent(), 12));

            logicIn1.toggle();
            sim.analyze();
            sim.doTicks(100);
            Assert.AreEqual(5E-10, Math.Round(grnd.getCurrent(), 12));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:26,代码来源:SimpleTest.cs

示例3: AndGateTest

        public void AndGateTest(int in0, int in1, bool out0)
        {
            /*string js = System.IO.File.ReadAllText(string.Format("./{0}.json", "AndGateTest"));
            Circuit sim = JsonSerializer.DeserializeFromString<Circuit>(js);
            var voltage0 = sim.getElm(0) as LogicInputElm;
            var voltage1 = sim.getElm(1) as LogicInputElm;
            var logicOut = sim.getElm(2) as LogicOutputElm;*/

            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicOut = sim.Create<LogicOutput>();

            var gate = sim.Create<AndGate>();

            sim.Connect(logicIn0, 0, gate, 0);
            sim.Connect(logicIn1, 0, gate, 1);
            sim.Connect(logicOut.leadIn, gate.leadOut);

            //string js = JsonSerializer.SerializeToString(sim);
            //System.IO.File.WriteAllText(string.Format("./{0}.json", "AndGateTest"), js);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:31,代码来源:GateTest.cs

示例4: InverterTest

        public void InverterTest(int in0, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var invert0 = sim.Create<Inverter>();
            var logicOut = sim.Create<LogicOutput>();

            sim.Connect(logicIn0.leadOut, invert0.leadIn);
            sim.Connect(invert0.leadOut, logicOut.leadIn);

            logicIn0.setPosition(in0);
            sim.analyze();

            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:18,代码来源:SimpleTest.cs

示例5: FullAdderTest

        public void FullAdderTest(int in0, int in1, int in2, int i0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicIn2 = sim.Create<LogicInput>();

            var chip0 = sim.Create<FullAdder>();

            var logicOut0 = sim.Create<LogicOutput>();
            var logicOut1 = sim.Create<LogicOutput>();

            sim.Connect(logicIn0.leadOut, chip0.leadIn0);
            sim.Connect(logicIn1.leadOut, chip0.leadIn1);
            sim.Connect(logicIn2.leadOut, chip0.leadIn2);

            sim.Connect(logicOut0.leadIn, chip0.leadOut1);
            sim.Connect(logicOut1.leadIn, chip0.leadOut2);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);
            logicIn2.setPosition(in2);
            sim.analyze();

            for(int x = 1; x <= 100; x++)
                sim.doTick();

            int i = 0;
            if(logicOut0.isHigh()) i += 1;
            if(logicOut1.isHigh()) i += 2;

            Assert.AreEqual(i0, i);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:34,代码来源:ChipTest.cs

示例6: FullAdderTest

        public void FullAdderTest(int in0, int in1, int in2, int i0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicIn2 = sim.Create<LogicInput>();

            var andGate0 = sim.Create<AndGate>();
            var andGate1 = sim.Create<AndGate>();

            var orGate0 = sim.Create<OrGate>();

            var xorGate0 = sim.Create<XorGate>();
            var xorGate1 = sim.Create<XorGate>();

            var logicOut0 = sim.Create<LogicOutput>();
            var logicOut1 = sim.Create<LogicOutput>();

            sim.Connect(logicIn0, 0, andGate1, 0);
            sim.Connect(logicIn0, 0, xorGate1, 0);

            sim.Connect(logicIn1, 0, andGate0, 0);
            sim.Connect(logicIn1, 0, xorGate0, 0);

            sim.Connect(logicIn2, 0, andGate0, 1);
            sim.Connect(logicIn2, 0, xorGate0, 1);

            sim.Connect(xorGate0, 2, andGate1, 1);
            sim.Connect(xorGate0, 2, xorGate1, 1);

            sim.Connect(orGate0, 0, andGate0, 2);
            sim.Connect(orGate0, 1, andGate1, 2);

            sim.Connect(logicOut0.leadIn, orGate0.leadOut);
            sim.Connect(logicOut1.leadIn, xorGate1.leadOut);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);
            logicIn2.setPosition(in2);

            sim.analyze();
            sim.doTicks(100);

            int i = 0;
            if(logicOut0.isHigh()) i += 2;
            if(logicOut1.isHigh()) i += 1;

            Assert.AreEqual(i0, i);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:50,代码来源:GateTest.cs

示例7: XorGateTest

        public void XorGateTest(int in0, int in1, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicOut = sim.Create<LogicOutput>();

            var gate = sim.Create<XorGate>();

            sim.Connect(logicIn0, 0, gate, 0);
            sim.Connect(logicIn1, 0, gate, 1);
            sim.Connect(logicOut.leadIn, gate.leadOut);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:22,代码来源:GateTest.cs

示例8: TwoToOneMuxTest

        public void TwoToOneMuxTest(int in0, int in1, int in2, bool out0)
        {
            Circuit sim = new Circuit();

            // tri-state buffer 0

            var volt0 = sim.Create<VoltageInput>();
            var logicIn0 = sim.Create<LogicInput>();
            var nand0 = sim.Create<NandGate>();
            var and0 = sim.Create<AndGate>();
            var invert0 = sim.Create<Inverter>();
            var pmos0 = sim.Create<PMosfet>();
            var nmos0 = sim.Create<NMosfet>();
            var grnd0 = sim.Create<Ground>();

            sim.Connect(nand0, 0, and0, 1);
            sim.Connect(nand0, 1, logicIn0, 0);
            sim.Connect(nand0, 1, invert0, 0);
            sim.Connect(invert0, 1, and0, 0);

            sim.Connect(logicIn0.leadOut, invert0.leadIn);

            sim.Connect(pmos0.leadGate, nand0.leadOut);
            sim.Connect(nmos0.leadGate, and0.leadOut);
            sim.Connect(volt0.leadPos, pmos0.leadSrc);
            sim.Connect(pmos0.leadDrain, nmos0.leadDrain);
            sim.Connect(nmos0.leadSrc, grnd0.leadIn);

            // tri-state buffer 1

            var volt1 = sim.Create<VoltageInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var nand1 = sim.Create<NandGate>();
            var and1 = sim.Create<AndGate>();
            var invert1 = sim.Create<Inverter>();
            var pmos1 = sim.Create<PMosfet>();
            var nmos1 = sim.Create<NMosfet>();
            var grnd1 = sim.Create<Ground>();

            sim.Connect(nand1, 0, and1, 1);
            sim.Connect(nand1, 1, logicIn1, 0);
            sim.Connect(nand1, 1, invert1, 0);
            sim.Connect(invert1, 1, and1, 0);

            sim.Connect(logicIn1.leadOut, invert1.leadIn);

            sim.Connect(pmos1.leadGate, nand1.leadOut);
            sim.Connect(nmos1.leadGate, and1.leadOut);
            sim.Connect(volt1.leadPos, pmos1.leadSrc);
            sim.Connect(pmos1.leadDrain, nmos1.leadDrain);
            sim.Connect(nmos1.leadSrc, grnd1.leadIn);

            //

            var invert2 = sim.Create<Inverter>();
            var logicIn2 = sim.Create<LogicInput>();
            var logicOut0 = sim.Create<LogicOutput>();

            var or0 = sim.Create<OrGate>();

            sim.Connect(invert2, 1, nand0, 0);
            sim.Connect(invert2, 1, and0, 1);
            sim.Connect(invert2, 0, nand1, 0);
            sim.Connect(invert2, 0, and1, 1);

            sim.Connect(logicIn2, 0, and1, 1);
            sim.Connect(or0, 0, nmos0, 2);
            sim.Connect(or0, 1, nmos1, 2);
            sim.Connect(or0.leadOut, logicOut0.leadIn);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);
            logicIn2.setPosition(in2);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut0.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:79,代码来源:GateTest.cs

示例9: OneOfFourDecoderTest

        public void OneOfFourDecoderTest(int in0, int in1, int i0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var invert0 = sim.Create<Inverter>();
            var invert1 = sim.Create<Inverter>();

            var and0 = sim.Create<AndGate>();
            var and1 = sim.Create<AndGate>();
            var and2 = sim.Create<AndGate>();
            var and3 = sim.Create<AndGate>();

            var logicOut0 = sim.Create<LogicOutput>();
            var logicOut1 = sim.Create<LogicOutput>();
            var logicOut2 = sim.Create<LogicOutput>();
            var logicOut3 = sim.Create<LogicOutput>();

            sim.Connect(logicIn0, 0, and0, 0);
            sim.Connect(logicIn0, 0, and1, 0);

            sim.Connect(logicIn0.leadOut, invert0.leadIn);
            sim.Connect(invert0, 1, and2, 0);
            sim.Connect(invert0, 1, and3, 0);

            sim.Connect(logicIn1, 0, and0, 1);
            sim.Connect(logicIn1, 0, and2, 1);

            sim.Connect(logicIn1.leadOut, invert1.leadIn);
            sim.Connect(invert1, 1, and1, 1);
            sim.Connect(invert1, 1, and3, 1);

            sim.Connect(and0.leadOut, logicOut0.leadIn);
            sim.Connect(and1.leadOut, logicOut1.leadIn);
            sim.Connect(and2.leadOut, logicOut2.leadIn);
            sim.Connect(and3.leadOut, logicOut3.leadIn);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            int i = 0;
            if(logicOut0.isHigh()) i += 4;
            if(logicOut1.isHigh()) i += 3;
            if(logicOut2.isHigh()) i += 2;
            if(logicOut3.isHigh()) i += 1;

            Assert.AreEqual(i0, i);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:53,代码来源:GateTest.cs

示例10: NandXorTest

        public void NandXorTest(int in0, int in1, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var nand0 = sim.Create<NandGate>();
            var nand1 = sim.Create<NandGate>();
            var nand2 = sim.Create<NandGate>();
            var nand3 = sim.Create<NandGate>();

            var logicOut = sim.Create<LogicOutput>();

            // upper input
            sim.Connect(logicIn0, 0, nand1, 0);
            sim.Connect(logicIn0, 0, nand0, 0);

            // lower input
            sim.Connect(logicIn1, 0, nand0, 1);
            sim.Connect(logicIn1, 0, nand2, 1);

            // connect 0
            sim.Connect(nand0, 2, nand1, 1);
            sim.Connect(nand0, 2, nand2, 0);

            // connect 3
            sim.Connect(nand1, 2, nand3, 0);
            sim.Connect(nand2, 2, nand3, 1);

            sim.Connect(logicOut, 0, nand3, 2);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:40,代码来源:GateTest.cs

示例11: MajorityLogicTest

        public void MajorityLogicTest(int in0, int in1, int in2, bool out0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicIn2 = sim.Create<LogicInput>();

            var nand0 = sim.Create<NandGate>();
            var nand1 = sim.Create<NandGate>();
            var nand2 = sim.Create<NandGate>();
            var nand3 = sim.Create<NandGate>();
            nand3.inputCount = 3;

            var logicOut = sim.Create<LogicOutput>();

            sim.Connect(logicIn0, 0, nand0, 0);
            sim.Connect(logicIn0, 0, nand2, 0);

            sim.Connect(logicIn1, 0, nand0, 1);
            sim.Connect(logicIn1, 0, nand1, 0);

            sim.Connect(logicIn2, 0, nand1, 1);
            sim.Connect(logicIn2, 0, nand2, 1);

            sim.Connect(nand3, 0, nand0, 2);
            sim.Connect(nand3, 1, nand1, 2);
            sim.Connect(nand3, 2, nand2, 2);

            sim.Connect(nand3, 4, logicOut, 0);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);
            logicIn2.setPosition(in2);

            sim.analyze();
            sim.doTicks(100);

            Assert.AreEqual(out0, logicOut.isHigh());
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:40,代码来源:GateTest.cs

示例12: HalfAdderTest

        public void HalfAdderTest(int in0, int in1, int i0)
        {
            Circuit sim = new Circuit();

            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();

            var andGate = sim.Create<AndGate>();
            var xorGate = sim.Create<XorGate>();

            var logicOut0 = sim.Create<LogicOutput>();
            var logicOut1 = sim.Create<LogicOutput>();

            sim.Connect(logicIn0, 0, andGate, 1);
            sim.Connect(logicIn0, 0, xorGate, 1);

            sim.Connect(logicIn1, 0, andGate, 0);
            sim.Connect(logicIn1, 0, xorGate, 0);

            sim.Connect(logicOut0.leadIn, andGate.leadOut);
            sim.Connect(logicOut1.leadIn, xorGate.leadOut);

            logicIn0.setPosition(in0);
            logicIn1.setPosition(in1);

            sim.analyze();
            sim.doTicks(100);

            int i = 0;
            if(logicOut0.isHigh()) i += 2;
            if(logicOut1.isHigh()) i += 1;

            Assert.AreEqual(i0, i);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:34,代码来源:GateTest.cs

示例13: CapacitorTest

        public void CapacitorTest()
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<DCVoltageSource>();
            var cap0 = sim.Create<CapacitorElm>(2E-4);
            var res0 = sim.Create<Resistor>();

            var switch0 = sim.Create<SwitchSPDT>();

            /*sim.Connect(volt0, 1, switch0, 1);
            sim.Connect(switch0, 1, switch0, 1);
            sim.Connect(switch0, 2, res0, 1);
            sim.Connect(cap0, 1, res0, 0);
            sim.Connect(res0, 1, volt0, 0);*/

            // leadNeg 0
            // leadPos 1

            sim.Connect(volt0, 1, switch0, 1);
            sim.Connect(switch0, 0, cap0, 0);
            sim.Connect(cap0, 1, res0, 0);
            sim.Connect(res0, 1, volt0, 0);
            sim.Connect(switch0, 2, volt0, 0);

            switch0.setPosition(0);

            var capScope0 = sim.Watch(cap0);

            for(int x = 1; x <= 28000; x++)
                sim.doTick();

            Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
            {
                double voltageHigh = capScope0.Max((f) => f.voltage);
                int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);

                Debug.Log("voltageHigh", voltageHigh, voltageHighNdx);

                double voltageLow = capScope0.Min((f) => f.voltage);
                int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);

                Debug.Log("voltageLow ", voltageLow, voltageLowNdx);

                double currentHigh = capScope0.Max((f) => f.current);
                int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
                Debug.Log("currentHigh", currentHigh, currentHighNdx);

                double currentLow = capScope0.Min((f) => f.current);
                int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);

                Debug.Log("currentLow ", currentLow, currentLowNdx);

                Assert.AreEqual(27999, voltageHighNdx);
                Assert.AreEqual(    0, voltageLowNdx);

                Assert.AreEqual(    0, currentHighNdx);
                Assert.AreEqual(27999, currentLowNdx);
            }

            switch0.setPosition(1);
            sim.analyze();
            capScope0.Clear();

            for(int x = 1; x <= 28000; x++)
                sim.doTick();

            Debug.Log();

            Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
            {
                double voltageHigh = capScope0.Max((f) => f.voltage);
                int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);

                Debug.Log("voltageHigh ", voltageHigh, voltageHighNdx);

                double voltageLow = capScope0.Min((f) => f.voltage);
                int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);

                Debug.Log("voltageLow  ", voltageLow, voltageLowNdx);

                double currentHigh = capScope0.Max((f) => f.current);
                int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
                Debug.Log("currentHigh", currentHigh, currentHighNdx);

                double currentLow = capScope0.Min((f) => f.current);
                int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);

                Debug.Log("currentLow ", currentLow, currentLowNdx);

                Assert.AreEqual(voltageHighNdx, currentLowNdx);
                Assert.AreEqual(voltageLowNdx, currentHighNdx);

                Assert.AreEqual(    0, voltageHighNdx);
                Assert.AreEqual(27999, voltageLowNdx);

                Assert.AreEqual(27999, currentHighNdx);
                Assert.AreEqual(    0, currentLowNdx);
            }
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:100,代码来源:DCVoltageTest.cs


注:本文中的Circuit.analyze方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。