本文整理汇总了C#中Circuit类的典型用法代码示例。如果您正苦于以下问题:C# Circuit类的具体用法?C# Circuit怎么用?C# Circuit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Circuit类属于命名空间,在下文中一共展示了Circuit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimulationSchematic
public SimulationSchematic(Circuit.Schematic Schematic)
: base(Schematic)
{
InitializeComponent();
CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete_Executed, Delete_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAll_Executed, SelectAll_CanExecute));
Focusable = true;
Cursor = Cursors.Cross;
Tool = new ProbeTool(this);
int pad = Grid * 2;
int align = Grid * 10;
Circuit.Coord lb = Schematic.LowerBound;
Circuit.Coord ub = Schematic.UpperBound;
lb = Floor(lb - pad, align);
ub = Ceiling(ub + pad, align);
Width = ub.x - lb.x;
Height = ub.y - lb.y;
Origin = -lb;
}
示例2: SchematicEditor
public SchematicEditor(Circuit.Schematic Schematic)
: base(Schematic)
{
InitializeComponent();
CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed));
CommandBindings.Add(new CommandBinding(ApplicationCommands.SaveAs, SaveAs_Executed));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete_Executed, Delete_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, Cut_Executed, Cut_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, Copy_Executed, Copy_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, Paste_Executed, Paste_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAll_Executed, SelectAll_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, Undo_Executed, Undo_CanExecute));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, Redo_Executed, Redo_CanExecute));
Focusable = true;
Cursor = Cursors.Cross;
edits = new EditStack();
Tool = new SelectionTool(this);
Width = 1600;
Height = 1600;
Origin = SnapToGrid(new Circuit.Coord((int)Width / 2, (int)Height / 2));
}
示例3: IC
/// <summary>
/// Define an IC based on a circuit with identified input and output ports.
/// Ports must be a member of the circuit.
/// </summary>
/// <param name="circuit"></param>
/// <param name="inputs"></param>
/// <param name="outputs"></param>
/// <param name="name"></param>
public IC(Circuit circuit, UserInput[] inputs, UserOutput[] outputs, string name)
: base(inputs.Length, outputs.Length)
{
foreach (UserInput p in inputs)
if (!circuit.Contains(p))
throw new ArgumentException("not all inputs part of circuit");
// we wire up the output ports so that any internal
// change in the circuit results in
// passing notification up the chain
// this is not needed for input because
// any input change will cause compute to be called
// automatically
foreach (UserOutput p in outputs)
{
p.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(p_PropertyChanged);
if (!circuit.Contains(p))
throw new ArgumentException("not all outputs part of circuit");
}
_inputs = inputs;
_outputs = outputs;
_circuit = circuit;
_name = name;
RunCompute();
}
示例4: execute
public override void execute(Circuit sim)
{
if(!pins[1].value && lastClock) {
bool q = pins[3].value;
if(pins[0].value) {
if(pins[2].value) {
q = !q;
} else {
q = true;
}
} else if(pins[2].value) {
q = false;
}
pins[3].value = q;
pins[4].value = !q;
}
lastClock = pins[1].value;
if(hasResetPin) {
if(pins[5].value) {
pins[3].value = false;
pins[4].value = true;
}
}
}
示例5: TwoToOneMuxTest
public void TwoToOneMuxTest(int int0, int int1, int int2, bool out0)
{
Circuit sim = new Circuit();
var logicIn0 = sim.Create<LogicInput>();
var logicIn1 = sim.Create<LogicInput>();
var logicIn2 = sim.Create<LogicInput>();
var logicOut0 = sim.Create<LogicOutput>();
var tri0 = sim.Create<TriStateBuffer>();
var tri1 = sim.Create<TriStateBuffer>();
var invert0 = sim.Create<Inverter>();
sim.Connect(logicIn0.leadOut, tri0.leadIn);
sim.Connect(logicIn1.leadOut, tri1.leadIn);
sim.Connect(logicIn2.leadOut, tri0.leadGate);
sim.Connect(logicIn2.leadOut, invert0.leadIn);
sim.Connect(invert0.leadOut, tri1.leadGate);
sim.Connect(tri0.leadOut, tri1.leadOut);
logicIn0.setPosition(int0);
logicIn1.setPosition(int1);
logicIn2.setPosition(int2);
sim.doTicks(100);
Debug.Log(out0, tri0.getLeadVoltage(1), tri1.getLeadVoltage(1));
Assert.AreEqual(out0, logicOut0.isHigh());
}
示例6: InductorFrequencyTest
public void InductorFrequencyTest(double frequency, double current)
{
Circuit sim = new Circuit();
var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
source0.frequency = frequency;
source0.phaseShift = 90;
var resistor0 = sim.Create<Resistor>(100);
var induct0 = sim.Create<InductorElm>(0.4);
sim.Connect(source0, 1, resistor0, 0);
sim.Connect(resistor0, 1, induct0, 0);
sim.Connect(induct0, 1, source0, 0);
var inductScope = sim.Watch(induct0);
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(inductScope.Max((f) => f.current), 12));
}
示例7: 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));
}
示例8: 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));
}
示例9: 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));
}
示例10: execute
public override void execute(Circuit sim)
{
if(pins[0].value && !modestate) {
modestate = true;
data = 0;
if(pins[2].value) data += 128;
if(pins[3].value) data += 64;
if(pins[4].value) data += 32;
if(pins[5].value) data += 16;
if(pins[6].value) data += 8;
if(pins[7].value) data += 4;
if(pins[8].value) data += 2;
if(pins[9].value) data += 1;
} else if(pins[1].value && !clockstate) {
clockstate = true;
if((data & 1) == 0) {
pins[10].value = false;
} else {
pins[10].value = true;
}
data = (byte)(data >> 1);
}
if(!pins[0].value)
modestate = false;
if(!pins[1].value)
clockstate = false;
}
示例11: GetCircuitStatistics
public virtual CircuitStatistics GetCircuitStatistics(Circuit circuit)
{
var races = _raceRepository.GetRacesAllAtCircuit(circuit);
var lastRace = races.OrderBy(x => x.StartDate).LastOrDefault(x => x.Entries.Count() > 0);
var previousWinner = new DriverContract { Driver = new Driver() { AtomicName = "* None *", Name = "* None *" } };
if (lastRace != null) {
var previousWinningResult = lastRace.GetRaceResults().FirstOrDefault(x => x.Position == 1);
if (previousWinningResult != null) {
previousWinner = previousWinningResult.Entrant;
}
}
// Qualifying Record
var record = decimal.MaxValue;
var qualifyingRecordHolder = new DriverContract { Driver = new Driver() { AtomicName = "* None *", Name = "* None *" } };
foreach (var race in races) {
var polePosition = race.GetQualificationResults().Where(x => x.LapTime > 0).OrderBy(x => x.LapTime).FirstOrDefault();
if (polePosition != null) {
if (polePosition.LapTime < record) {
record = polePosition.LapTime;
qualifyingRecordHolder = polePosition.Entrant;
}
}
}
return new CircuitStatistics(circuit, previousWinner, record, qualifyingRecordHolder);
}
示例12: 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));
}
示例13: stamp
public override void stamp(Circuit sim)
{
int vn = sim.nodeCount + pins[2].voltSource;
sim.stampNonLinear(vn);
sim.stampNonLinear(0);
sim.stampNonLinear(lead_node[2]);
}
示例14: MouseUp
public override void MouseUp(Circuit.Coord At)
{
b = At;
Target.Select();
if (a == b)
{
Circuit.Node node = Simulation.NodeAt(At);
IEnumerable<Circuit.Element> at = Target.AtPoint(a);
IEnumerable<Circuit.Symbol> probes = ProbesOf(at);
if (!probes.Any() && node != null)
{
Probe probe = Simulation.Probes.FirstOrDefault(i => i.ConnectedTo == node);
if (probe != null)
{
// There's already a probe on this node, move the probe here.
((Circuit.Symbol)probe.Tag).Position = a;
}
else
{
// Make a new probe connected to this node.
probe = new Probe(Colors.ArgMin(i => Simulation.Probes.Count(j => j.Color == i)));
Target.Schematic.Add(new Circuit.Symbol(probe) { Position = a });
}
}
else
{
Target.Select(probes.FirstOrDefault());
}
}
}
示例15: execute
public override void execute(Circuit sim)
{
if(pins[loadPin].value && !lastLoad)
for(int i = 0; i != bits; i++)
pins[i + bits].value = pins[i].value;
lastLoad = pins[loadPin].value;
}