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


C# Circuit.Connect方法代码示例

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


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

示例1: 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

示例2: CapacitorFrequencyTest

        public void CapacitorFrequencyTest(double frequency, double current)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            source0.frequency = frequency;

            var resistor0 = sim.Create<Resistor>(200);
            var cap0 = sim.Create<CapacitorElm>(3E-5);

            sim.Connect(source0, 1, resistor0, 0);
            sim.Connect(resistor0, 1, cap0, 0);
            sim.Connect(cap0, 1, source0, 0);

            var capScope = sim.Watch(cap0);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:25,代码来源:ACVoltageTest.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: CapacitorCapacitanceTest

        public void CapacitorCapacitanceTest(double capacitance, double current)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
            source0.frequency = 80;

            var resistor0 = sim.Create<Resistor>(200);
            var cap0 = sim.Create<CapacitorElm>(capacitance);

            sim.Connect(source0, 1, resistor0, 0);
            sim.Connect(resistor0, 1, cap0, 0);
            sim.Connect(cap0, 1, source0, 0);

            var capScope = sim.Watch(cap0);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            double charge = cap0.capacitance * cap0.getVoltageDelta();

            Debug.Log(charge); // F = I x L
            Debug.Log(cap0.getCurrent(), charge / cap0.capacitance); // I = F / L
            Debug.Log(cap0.capacitance, charge / cap0.getCurrent()); // L = F / I

            Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:31,代码来源:ACVoltageTest.cs

示例5: LawOfResistorsInSeriesTest

        public void LawOfResistorsInSeriesTest(int in0)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<DCVoltageSource>();
            var volt1 = sim.Create<DCVoltageSource>();
            var resCompare = sim.Create<Resistor>(in0 * 100);

            List<Resistor> resistors = new List<Resistor>();
            for(int i = 0; i < in0; i++)
                resistors.Add(sim.Create<Resistor>());

            sim.Connect(volt0.leadPos, resistors.First().leadIn);

            for(int i = 1; i < in0 - 1; i++)
                sim.Connect(resistors[i - 1].leadOut, resistors[i].leadIn);

            sim.Connect(volt0.leadNeg, resistors.Last().leadOut);

            sim.Connect(volt1.leadPos, resCompare.leadIn);
            sim.Connect(resCompare.leadOut, volt1.leadNeg);

            sim.doTicks(100);

            Assert.AreEqual(Math.Round(resistors.Last().getCurrent(), 12), Math.Round(resCompare.getCurrent(), 12));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:26,代码来源:ResistorTest.cs

示例6: 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

示例7: DarlingtonPairTest

        public void DarlingtonPairTest(bool In0, double i0)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<VoltageInput>();

            var res0 = sim.Create<Resistor>(2000000);
            var res1 = sim.Create<Resistor>(300);

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

            var npn0 = sim.Create<Transistor>(false);
            var npn1 = sim.Create<Transistor>(false);

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

            sim.Connect(volt0.leadPos, res0.leadIn);
            sim.Connect(volt0.leadPos, res1.leadIn);

            sim.Connect(switch0, 0, res0, 1);

            sim.Connect(npn0, 0, switch0, 1);
            sim.Connect(npn0.leadCollector, res1.leadOut);
            sim.Connect(npn0.leadEmitter, npn1.leadBase);

            sim.Connect(npn1.leadCollector, res1.leadOut);
            sim.Connect(npn1.leadEmitter, groun0.leadIn);

            if(In0) switch0.toggle();

            sim.doTicks(100);

            Assert.AreEqual(i0, Math.Round(groun0.getCurrent(), 12));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:34,代码来源:TransistorTest.cs

示例8: 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

示例9: VoltageDividerTest

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

            var volt0 = sim.Create<DCVoltageSource>();
            volt0.maxVoltage = 10;

            var res0 = sim.Create<Resistor>(10000);
            var res1 = sim.Create<Resistor>(10000);

            sim.Connect(volt0, 1, res0,  0);
            sim.Connect(res0,  1, res1,  0);
            sim.Connect(res1,  1, volt0, 0);

            var res2 = sim.Create<Resistor>(10000);
            var res3 = sim.Create<Resistor>(10000);
            var res4 = sim.Create<Resistor>(10000);
            var res5 = sim.Create<Resistor>(10000);

            sim.Connect(volt0, 1, res2,  0);
            sim.Connect(res2,  1, res3,  0);
            sim.Connect(res3,  1, res4,  0);
            sim.Connect(res4,  1, res5,  0);
            sim.Connect(res5,  1, volt0, 0);

            var out0 = sim.Create<Output>();
            var out1 = sim.Create<Output>();
            var out2 = sim.Create<Output>();
            var out3 = sim.Create<Output>();

            sim.Connect(out0, 0, res0, 1);
            sim.Connect(out1, 0, res2, 1);
            sim.Connect(out2, 0, res3, 1);
            sim.Connect(out3, 0, res4, 1);

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

            TestUtils.Compare(res0.getVoltageDelta(), 5.0, 8);
            TestUtils.Compare(res1.getVoltageDelta(), 5.0, 8);
            TestUtils.Compare(res2.getVoltageDelta(), 2.5, 8);
            TestUtils.Compare(res3.getVoltageDelta(), 2.5, 8);
            TestUtils.Compare(res4.getVoltageDelta(), 2.5, 8);
            TestUtils.Compare(res5.getVoltageDelta(), 2.5, 8);

            TestUtils.Compare(out0.getVoltageDelta(), 5.0, 8);
            TestUtils.Compare(out1.getVoltageDelta(), 7.5, 8);
            TestUtils.Compare(out2.getVoltageDelta(), 5.0, 8);
            TestUtils.Compare(out3.getVoltageDelta(), 2.5, 8);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:50,代码来源:ResistorTest.cs

示例10: NANDTest

        public void NANDTest(bool in0, bool in1, bool in2, double in3)
        {
            Circuit sim = new Circuit();

            var volt0 = sim.Create<VoltageInput>();
            var res0 = sim.Create<Resistor>(5000);
            var nmos0 = sim.Create<NMosfet>();
            var nmos1 = sim.Create<NMosfet>();
            var logicIn0 = sim.Create<LogicInput>();
            var logicIn1 = sim.Create<LogicInput>();
            var logicOut0 = sim.Create<LogicOutput>();
            var grnd0 = sim.Create<Ground>();

            sim.Connect(volt0.leadPos, res0.leadIn);
            sim.Connect(res0.leadOut, nmos0.leadDrain);

            sim.Connect(logicOut0.leadIn, nmos0.leadDrain);
            sim.Connect(nmos0.leadGate, logicIn0.leadOut);

            sim.Connect(nmos0.leadSrc, nmos1.leadDrain);

            sim.Connect(nmos1.leadGate, logicIn1.leadOut);
            sim.Connect(nmos1.leadSrc, grnd0.leadIn);

            if(in0) logicIn0.toggle();
            if(in1) logicIn1.toggle();

            sim.doTicks(100);

            Assert.AreEqual(in2, logicOut0.isHigh());
            Assert.AreEqual(in3, Math.Round(grnd0.getCurrent(), 3));
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:32,代码来源:NMOSTest.cs

示例11: InductorTest

        public void InductorTest(double inductance)
        {
            Circuit sim = new Circuit();

            var source0 = sim.Create<DCVoltageSource>();
            var inductor0 = sim.Create<InductorElm>(inductance);

            sim.Connect(source0.leadPos, inductor0.leadIn);
            sim.Connect(inductor0.leadOut, source0.leadNeg);

            double cycleTime = 1 / source0.frequency;
            double quarterCycleTime = cycleTime / 4;

            sim.doTicks((int)(cycleTime / sim.timeStep));

            double flux = inductor0.inductance * inductor0.getCurrent();	// F = I x L
            Assert.AreEqual(inductor0.getCurrent(), flux / inductor0.inductance); // I = F / L
            Assert.AreEqual(inductor0.inductance, flux / inductor0.getCurrent()); // L = F / I
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:19,代码来源:SimpleTest.cs

示例12: ACWaveTest

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

            var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);

            var res0 = sim.Create<Resistor>();
            var ground0 = sim.Create<Ground>();

            sim.Connect(voltage0.leadPos, res0.leadIn);
            sim.Connect(res0.leadOut, ground0.leadIn);

            var resScope0 = sim.Watch(res0);

            double cycleTime = 1 / voltage0.frequency;
            double quarterCycleTime = cycleTime / 4;

            int steps = (int)(cycleTime / sim.timeStep);
            for(int x = 1; x <= steps; x++)
                sim.doTick();

            double voltageHigh = resScope0.Max((f) => f.voltage);
            int voltageHighNdx = resScope0.FindIndex((f) => f.voltage == voltageHigh);

            TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
            TestUtils.Compare(resScope0[voltageHighNdx].time, quarterCycleTime, 4);

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

            TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
            TestUtils.Compare(resScope0[voltageLowNdx].time, quarterCycleTime * 3, 4);

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

            double currentLow = resScope0.Min((f) => f.current);
            int currentLowNdx = resScope0.FindIndex((f) => f.current == currentLow);
            Debug.Log(Math.Round(currentLow, 4), "currentLow");
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:41,代码来源:VoltageWaveTest.cs

示例13: LeastResistanceTest

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

            var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            var res0 = sim.Create<Resistor>( 100);
            var res1 = sim.Create<Resistor>(1000);
            var ground0 = sim.Create<Ground>();
            var ground1 = sim.Create<Ground>();

            sim.Connect(volt0, 0, res0,    0);
            sim.Connect(volt0, 0, res1,    0);
            sim.Connect(res0,  1, ground0, 0);
            sim.Connect(res1,  1, ground1, 0);

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

            TestUtils.Compare(ground0.getCurrent(), 0.05, 8);
            TestUtils.Compare(ground1.getCurrent(), 0.005, 8);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:21,代码来源:ResistorTest.cs

示例14: NPNTransistorTest

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

            var npn0 = sim.Create<Transistor>(false);

            var baseVoltage = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            baseVoltage.maxVoltage = 0.7025;

            var collectorVoltage = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            collectorVoltage.maxVoltage = 2;

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

            var baseWire = sim.Create<Wire>();
            var collectorWire = sim.Create<Wire>();
            var emitterWire = sim.Create<Wire>();

            sim.Connect(baseVoltage.leadPos, baseWire.leadIn);
            sim.Connect(baseWire.leadOut, npn0.leadBase);

            sim.Connect(collectorVoltage.leadPos, collectorWire.leadIn);
            sim.Connect(collectorWire.leadOut, npn0.leadCollector);

            sim.Connect(ground.leadIn, emitterWire.leadIn);
            sim.Connect(emitterWire.leadOut, npn0.leadEmitter);

            sim.doTicks(100);

            TestUtils.Compare(baseWire.getCurrent(), 0.00158254, 8);
            TestUtils.Compare(collectorWire.getCurrent(), 0.15825359, 8);
            TestUtils.Compare(emitterWire.getCurrent(), -0.15983612, 8);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:33,代码来源:TransistorTest.cs

示例15: CMOSInverterTest

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

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

            var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
            var grnd0 = sim.Create<Ground>();

            var pmosf0 = sim.Create<PMosfet>();
            var nmosf0 = sim.Create<NMosfet>();

            sim.Connect(logicIn0.leadOut, pmosf0.leadGate);
            sim.Connect(logicIn0.leadOut, nmosf0.leadGate);

            sim.Connect(pmosf0.leadSrc, volt0.leadPos);
            sim.Connect(pmosf0.leadDrain, nmosf0.leadDrain);
            sim.Connect(nmosf0.leadSrc, grnd0.leadIn);

            sim.Connect(logicOut0.leadIn, pmosf0.leadDrain);

            if(in0) logicIn0.toggle();

            sim.doTicks(1000);

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


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