コード例 #1
0
        /// <summary>Performs necessary initialization of the device, like mapping to the equation system.</summary>
        /// <param name="adapter">The equation system builder.</param>
        /// <param name="context">Context of current simulation.</param>
        public override void Initialize(IEquationSystemAdapter adapter, ISimulationContext context)
        {
            stamper.Register(adapter, bprimeNode, cprimeNode, eprimeNode);

            voltageBc.Register(adapter, bprimeNode, cprimeNode);
            voltageBe.Register(adapter, bprimeNode, eprimeNode);
            voltageCs.Register(adapter, cprimeNode, Substrate);

            capacbe.Register(adapter, bprimeNode, eprimeNode);
            capacbc.Register(adapter, bprimeNode, cprimeNode);
            capaccs.Register(adapter, cprimeNode, Substrate);

            chargebe = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();
            chargebc = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();
            chargecs = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();

            gb.Register(adapter, bprimeNode, Base);
            gc.Register(adapter, cprimeNode, Collector);
            ge.Register(adapter, eprimeNode, Emitter);

            vT = PhysicalConstants.Boltzmann *
                 PhysicalConstants.CelsiusToKelvin(Parameters.NominalTemperature) /
                 PhysicalConstants.DevicearyCharge;

            VoltageBaseEmitter = DeviceHelpers.PnCriticalVoltage(Parameters.SaturationCurrent, vT);
        }
コード例 #2
0
        public void LaunchSite()
        {
            driver.CleanBrowser();
            DeviceHelpers dh = new DeviceHelpers(tb);

            dh.InitializeChrome();

            driver.GoToUrl(tb.getProperties("site"));
        }
コード例 #3
0
        /// <summary>
        /// Creates the default magnetic stripe reader.
        /// </summary>
        /// <returns>true if magnetic stripe reader is created. Otherwise returns false</returns>
        private async Task <bool> CreateDefaultMagneticStripeReaderObject()
        {
            if (_reader == null)
            {
                _reader = await DeviceHelpers.GetFirstMagneticStripeReaderAsync();

                if (_reader == null)
                {
                    rootPage.NotifyUser("Magnetic Stripe Reader not found. Please connect a Magnetic Stripe Reader.", NotifyType.ErrorMessage);
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        public void UpdateResource(IPluginOut ForPin, Device OnDevice)
        {
            //create device specific helpers on given device if not already present
            if (!FDeviceHelpers.ContainsKey(OnDevice))
            {
                var dh = new DeviceHelpers(
                    new Sprite(OnDevice),
                    new Texture(OnDevice, 1, 1, 1, Usage.Dynamic, Format.L8, Pool.Default));                     // Format.A8R8G8B8, Pool.Default)

                //need to fill texture white to be able to set color on sprite later
                DataRectangle tex = dh.Texture.LockRectangle(0, LockFlags.None);
                tex.Data.WriteByte(255);
                dh.Texture.UnlockRectangle(0);

                FDeviceHelpers.Add(OnDevice, dh);
            }
        }
コード例 #5
0
        public void DestroyResource(IPluginOut ForPin, Device OnDevice, bool OnlyUnManaged)
        {
            //dispose resources that were created on given device
            DeviceHelpers dh = null;

            if (FDeviceHelpers.TryGetValue(OnDevice, out dh))
            {
                dh.Dispose();

                var ids = FFonts.Where(kv => kv.Value.Tag == OnDevice).Select(kv => kv.Key).ToArray();
                foreach (var id in ids)
                {
                    RemoveFont(id);
                }

                FDeviceHelpers.Remove(OnDevice);
            }
        }
コード例 #6
0
            public override void ApplyModelValues(ISimulationContext context)
            {
                var Is = DefinitionDevice.Param.SaturationCurrent;
                var Vt = DefinitionDevice.Param.ThermalVoltage;
                var n  = DefinitionDevice.Param.IdealityCoefficient;

                var Vd = voltage.GetValue();

                // calculates current through the diode and it's derivative
                DeviceHelpers.PnJunction(Is, Vd, Vt * n, out var Id, out var Geq);
                Current = Id;

                // stamp the equivalent circuit
                var Ieq = Id - Geq * Vd;

                conductanceStamper.Stamp(Geq);
                currentStamper.Stamp(Ieq);
            }
コード例 #7
0
        /// <summary>This method is called each time an equation is solved.</summary>
        /// <param name="context">Context of current simulation.</param>
        public override void OnEquationSolution(ISimulationContext context)
        {
            var vcrit = DeviceHelpers.PnCriticalVoltage(Parameters.SaturationCurrent, vt);

            var(newvolt, limited) = DeviceHelpers.PnLimitVoltage(voltage.GetValue(), Voltage, vt, vcrit);

            var dVolt = newvolt - Voltage;
            var dCurr = Conductance * dVolt;

            var reltol = context.SimulationParameters.RelativeTolerance;
            var abstol = context.SimulationParameters.AbsoluteTolerance;

            if (limited || !MathHelper.InTollerance(Current, Current + dCurr, abstol, reltol))
            {
                context.ReportNotConverged(this);
            }

            Voltage = newvolt;
        }
コード例 #8
0
        /// <summary>This method is called each time an equation is solved.</summary>
        /// <param name="context">Context of current simulation.</param>
        public override void OnEquationSolution(ISimulationContext context)
        {
            var iS = Parameters.SaturationCurrent;

            var nF       = Parameters.ForwardEmissionCoefficient;
            var nR       = Parameters.ReverseEmissionCoefficient;
            var polarity = Parameters.IsPnp ? -1 : +1;

            // critical voltages to prevent numerical overflow
            var vbecrit = DeviceHelpers.PnCriticalVoltage(iS, nF * vT);
            var vbccrit = DeviceHelpers.PnCriticalVoltage(iS, nR * vT);

            var vvbe = voltageBe.GetValue() * polarity;
            var vvbc = voltageBc.GetValue() * polarity;

            var(vbe, limited)  = DeviceHelpers.PnLimitVoltage(vvbe, VoltageBaseEmitter, nF * vT, vbecrit);
            var(vbc, limited2) = DeviceHelpers.PnLimitVoltage(vvbc, VoltageBaseCollector, nR * vT, vbccrit);

            // calculate current deltas
            var delvbe = vbe - VoltageBaseEmitter;
            var delvbc = vbc - VoltageBaseCollector;
            var cchat  = CurrentCollector + (Transconductance + OutputConductance) * delvbe -
                         (OutputConductance + ConductanceMu) * delvbc;
            var cbhat = CurrentBase + ConductancePi * delvbe + ConductanceMu * delvbc;
            var cc    = CurrentCollector;
            var cb    = CurrentBase;

            var reltol = context.SimulationParameters.RelativeTolerance;
            var abstol = context.SimulationParameters.AbsoluteTolerance;

            // request another iteration if not converged
            if (limited || limited2 ||
                !MathHelper.InTollerance(cchat, cc, abstol, reltol) ||
                !MathHelper.InTollerance(cbhat, cb, abstol, reltol))
            {
                context.ReportNotConverged(this);
            }

            // update voltages
            VoltageBaseEmitter      = vbe;
            VoltageBaseCollector    = vbc;
            VoltageCollectorEmitter = vbc - vbe;
        }
コード例 #9
0
        /// <summary>Gets values for the device model based on voltage across the diode.</summary>
        /// <param name="vd">Voltage across the diode.</param>
        /// <returns></returns>
        private (double id, double geq, double cd) GetModelValues(double vd)
        {
            var m   = Parameters.JunctionGradingCoefficient;
            var vj  = Parameters.JunctionPotential;
            var fc  = Parameters.ForwardBiasDepletionCapacitanceCoefficient;
            var tt  = Parameters.TransitTime;
            var iss = Parameters.SaturationCurrent;
            var jc  = Parameters.JunctionCapacitance;
            var bv  = Parameters.ReverseBreakdownVoltage;

            double id, geq;

            if (vd >= smallBiasTreshold)
            {
                DeviceHelpers.PnJunction(iss, vd, vt, out id, out geq);
                id  += vd * gmin;
                geq += gmin;
            }
            else if (vd > -bv)
            {
                id  = -iss;
                geq = gmin;
            }
            else
            {
                id  = -iss * (Math.Exp(-(bv + vd) / vt) - 1 + bv / vt);
                geq = iss * Math.Exp(-(bv + vd) / vt) / vt;
            }

            var cd = -tt * geq;

            if (vd < capacitanceTreshold)
            {
                cd += jc / Math.Pow(1 - vd / vj, m);
            }
            else
            {
                cd += jc / Math.Pow(1 - fc, 1 + m) * (1 - fc * (1 + m) + m * vd / vj);
            }

            return(id, geq, cd);
        }
        private async Task <bool> FindReceiptPrinter()
        {
            if (printer == null)
            {
                rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
                printer = await DeviceHelpers.GetFirstReceiptPrinterAsync();

                if (printer != null)
                {
                    rootPage.NotifyUser("Got Printer with Device Id : " + printer.DeviceId, NotifyType.StatusMessage);
                    return(true);
                }
                else
                {
                    rootPage.NotifyUser("No Printer found", NotifyType.ErrorMessage);
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Find the first receipt printer and create two instances of it.
        /// </summary>
        /// <returns></returns>
        private async Task <bool> FindReceiptPrinterInstances()
        {
            if (printerInstance1 == null || printerInstance2 == null)
            {
                rootPage.NotifyUser("Finding printer", NotifyType.StatusMessage);
                printerInstance1 = await DeviceHelpers.GetFirstReceiptPrinterAsync();

                if (printerInstance1 != null)
                {
                    rootPage.NotifyUser("Got Printer Instance 1 with Device Id : " + printerInstance1.DeviceId, NotifyType.StatusMessage);

                    // Create another instance of the same printer.
                    if (printerInstance2 != null)
                    {
                        printerInstance2.Dispose();
                        printerInstance2 = null;
                    }
                    printerInstance2 = await PosPrinter.FromIdAsync(printerInstance1.DeviceId);

                    if (printerInstance2 != null)
                    {
                        rootPage.NotifyUser("Got Printer Instance 2 with Device Id : " + printerInstance2.DeviceId, NotifyType.StatusMessage);
                        return(true);
                    }
                    else
                    {
                        rootPage.NotifyUser("Couldn't create second instance of printer.", NotifyType.StatusMessage);
                    }
                    return(false);
                }
                else
                {
                    rootPage.NotifyUser("No Printer found", NotifyType.ErrorMessage);
                    return(false);
                }
            }

            return(true);
        }
コード例 #12
0
        public void Render(IDXLayerIO ForPin, Device OnDevice)
        {
            //concerning the cut characters in some fonts, especially when rendered italic see:
            //http://www.gamedev.net/community/forums/topic.asp?topic_id=441338
            //seems to be an official bug and we'd need to write our very own font rendering to fix that

            if (!FEnabledInput[0])
            {
                return;
            }

            //from the docs: D3DXSPRITE_OBJECTSPACE -> The world, view, and projection transforms are not modified.
            //for view and projection transforms this is exactly what we want: it allows placing the text within the
            //same world as all the other objects. however we don't want to work in object space but in world space
            //that's why we need to to set the world transform to a neutral value: identity
            OnDevice.SetTransform(TransformState.World, Matrix.Identity);
            FTransformIn.SetRenderSpace();

            //set states that are defined via upstream nodes
            FRenderStatePin.SetSliceStates(0);

            DeviceHelpers dh = FDeviceHelpers[OnDevice];

            dh.Sprite.Begin(SpriteFlags.ObjectSpace | SpriteFlags.DoNotAddRefTexture);
            try
            {
                int normalize = FNormalizeInput[0].Index;

                Matrix    preScale = Matrix.Scaling(1, -1, 1);
                Matrix    world;
                string    text;
                Rectangle tmpRect = new Rectangle(0, 0, 0, 0);
                int       hAlign, vAlign;
                float     x, y;
                int       width, height;

                for (int i = 0; i < FSpreadMax; i++)
                {
                    var font = CreateFont(OnDevice, i);

                    text = FTextInput[i];

                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }

                    DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs;

                    hAlign = FHorizontalAlignInput[i].Index;
                    switch (hAlign)
                    {
                    case 0: format |= DrawTextFormat.Left; break;

                    case 1: format |= DrawTextFormat.Center; break;

                    case 2: format |= DrawTextFormat.Right; break;
                    }

                    vAlign = FVerticalAlignInput[i].Index;
                    switch (vAlign)
                    {
                    case 0: format |= DrawTextFormat.Top; break;

                    case 1: format |= DrawTextFormat.VerticalCenter; break;

                    case 2: format |= DrawTextFormat.Bottom; break;
                    }

                    switch (FTextRenderingModeInput[i].Index)
                    {
                    case 0: format |= DrawTextFormat.SingleLine; break;

                    case 2: format |= DrawTextFormat.WordBreak; break;
                    }

                    tmpRect = new Rectangle(0, 0, FWidth[i], 0);
                    font.MeasureString(dh.Sprite, text, format, ref tmpRect);
                    width  = tmpRect.Width;
                    height = tmpRect.Height;

                    FSizeOutput[i] = new Vector2D(width, height);

                    switch (normalize)
                    {
                    case 1: preScale = Matrix.Scaling(1f / width, -1f / width, 1); break;
                    //"width" means that the texture width will have no influence on the width of the sprite. Width will be always 1.

                    case 2: preScale = Matrix.Scaling(1f / height, -1f / height, 1); break;
                    //"height" means that the texture height will have no influence on the height of the sprite. Height will be always 1.

                    case 3: preScale = Matrix.Scaling(1f / width, -1f / height, 1); break;
                        //"on" means that the particle will always be a unit quad. independant of texture size
                    }

                    FTransformIn.GetRenderWorldMatrix(i, out world);
                    dh.Sprite.Transform = preScale * world;

                    switch (vAlign)
                    {
                    case 1: y = height / 2; break;

                    case 2: y = height; break;

                    default: y = 0; break;
                    }

                    if (FShowBrush[i])
                    {
                        switch (hAlign)
                        {
                        case 1: x = width / 2; break;

                        case 2: x = width; break;

                        default: x = 0; break;
                        }
                        dh.Sprite.Draw(dh.Texture, new Rectangle(0, 0, width, height),
                                       new Vector3(x, y, -0.001f), null, new Color4(FBrushColor[i].Color.ToArgb()));
                    }

                    width = FWidth[i];
                    switch (hAlign)
                    {
                    case 1: x = width / 2; break;

                    case 2: x = width; break;

                    default: x = 0; break;
                    }
                    font.DrawString(dh.Sprite, text, new Rectangle((int)-x, (int)-y, width, height), format, (Color)FColorInput[i]);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
            finally
            {
                dh.Sprite.End();
            }
        }
コード例 #13
0
        /// <summary>
        ///   Applies device impact on the circuit equation system. If behavior of the device is nonlinear, this method is
        ///   called once every Newton-Raphson iteration.
        /// </summary>
        /// <param name="context">Context of current simulation.</param>
        public override void ApplyModelValues(ISimulationContext context)
        {
            // cache params
            vT = PhysicalConstants.Boltzmann *
                 PhysicalConstants.CelsiusToKelvin(Parameters.NominalTemperature) /
                 PhysicalConstants.DevicearyCharge;

            var iS  = Parameters.SaturationCurrent;
            var iSe = Parameters.EmitterSaturationCurrent;
            var iSc = Parameters.CollectorSaturationCurrent;

            var nF = Parameters.ForwardEmissionCoefficient;
            var nR = Parameters.ReverseEmissionCoefficient;
            var nE = Parameters.EmitterSaturationCoefficient;
            var nC = Parameters.CollectorSaturationCoefficient;

            var bF = Parameters.ForwardBeta;
            var bR = Parameters.ReverseBeta;

            var earlyVoltageForward = Parameters.ForwardEarlyVoltage;
            var earlyVolrateReverse = Parameters.ReverseEarlyVoltage;

            var iKf = Parameters.ForwardCurrentCorner;
            var iKr = Parameters.ReverseCurrentCorner;

            var gmin = Parameters.MinimalResistance ?? context.SimulationParameters.MinimalResistance;

            var polarity = Parameters.IsPnp ? -1 : +1;

            var ggb = Parameters.BaseResistance > 0 ? 1 / Parameters.BaseResistance : 0;
            var ggc = Parameters.CollectorResistance > 0 ? 1 / Parameters.CollectorResistance : 0;
            var gge = Parameters.EmitterCapacitance > 0 ? 1 / Parameters.EmitterCapacitance : 0;


            var vbe = VoltageBaseEmitter;
            var vbc = VoltageBaseCollector;

            // calculate junction currents
            var(ibe, gbe)   = DeviceHelpers.PnBJT(iS, vbe, nF * vT, gmin);
            var(iben, gben) = DeviceHelpers.PnBJT(iSe, vbe, nE * vT, 0);

            var(ibc, gbc)   = DeviceHelpers.PnBJT(iS, vbc, nR * vT, gmin);
            var(ibcn, gbcn) = DeviceHelpers.PnBJT(iSc, vbc, nC * vT, 0);

            // base charge calculation
            var q1 = 1 / (1 - vbc / earlyVoltageForward - vbe / earlyVolrateReverse);
            var q2 = ibe / iKf + ibc / iKr;

            var sqrt = Math.Sqrt(1 + 4 * q2);
            var qB   = q1 / 2 * (1 + sqrt);

            var dQdbUbe = q1 * (qB / earlyVolrateReverse + gbe / (iKf * sqrt));
            var dQbdUbc = q1 * (qB / earlyVoltageForward + gbc / (iKr * sqrt));

            // excess phase missing
            var ic  = (ibe - ibc) / qB - ibc / bR - ibcn;
            var ib  = ibe / bF + iben + ibc / bR + ibcn;
            var gpi = gbe / bF + gben;
            var gmu = gbc / bR + gbcn;
            var go  = (gbc + (ibe - ibc) * dQbdUbc / qB) / qB;
            var gm  = (gbe - (ibe - ibc) * dQdbUbe / qB) / qB - go;

            // terminal currents
            var ceqbe = polarity * (ic + ib - vbe * (gm + go + gpi) + vbc * go);
            var ceqbc = polarity * (-ic + vbe * (gm + go) - vbc * (gmu + go));

            CurrentBase          = ib;
            CurrentCollector     = ic;
            CurrentEmitter       = -ib - ic;
            CurrentBaseEmitter   = ibe;
            CurrentBaseCollector = ibc;
            Transconductance     = gm;
            OutputConductance    = go;
            ConductancePi        = gpi;
            ConductanceMu        = gmu;

            stamper.Stamp(gpi, gmu, gm, -go, ceqbe, ceqbc);
            gb.Stamp(ggb);
            ge.Stamp(gge);
            gc.Stamp(ggc);

            if (!(context.TimePoint > 0))
            {
                return;
            }

            var vcs = voltageCs.GetValue();

            var tf = Parameters.ForwardTransitTime;
            var tr = Parameters.ReverseTransitTime;

            var fc = Parameters.ForwardBiasDepletionCoefficient;

            var cje = Parameters.EmitterCapacitance;
            var mje = Parameters.EmitterExponentialFactor;
            var vje = Parameters.EmitterPotential;

            var cjc = Parameters.CollectorCapacitance;
            var mjc = Parameters.CollectorExponentialFactor;
            var vjc = Parameters.CollectorPotential;

            var cjs = Parameters.SubstrateCapacitance;
            var mjs = Parameters.SubstrateExponentialFactor;
            var vjs = Parameters.SubstratePotential;


            var cbe = DeviceHelpers.JunctionCapacitance(vbe, cje, mje, vje, gbe * tf, fc);
            var cbc = DeviceHelpers.JunctionCapacitance(vbc, cjc, mjc, vjc, gbc * tr, fc);
            var ccs = DeviceHelpers.JunctionCapacitance(vcs, cjs, mjs, vjs, 0, fc);

            // stamp capacitors

            double cieq;

            (cieq, cgeqbe) = chargebe.GetEquivalents(cbe / context.TimeStep);
            capacbe.Stamp(cieq, cgeqbe);

            (cieq, cgeqbc) = chargebe.GetEquivalents(cbc / context.TimeStep);
            capacbc.Stamp(cieq, cgeqbc);

            (cieq, cgeqcs) = chargebe.GetEquivalents(ccs / context.TimeStep);
            capaccs.Stamp(cieq, cgeqcs);
        }