コード例 #1
0
ファイル: frmMain.cs プロジェクト: fdecaire/LogicLibrary
        private void SRLatchPaint()
        {
            Graphics g = this.CreateGraphics();

            g.FillRectangle(Brushes.White, 0, 0, Width, Height);

            int leftOffset  = 120;
            int topOffset   = 100;
            int spacing     = 80;
            int timingWidth = 4;

            var fontFamily = new FontFamily("Arial");
            var font       = new Font(fontFamily, 20, FontStyle.Regular, GraphicsUnit.Pixel);

            g.DrawString("S", font, Brushes.Black, 5, Height - 20 - (topOffset + spacing * 3));
            g.DrawString("R", font, Brushes.Red, 5, Height - 20 - (topOffset + spacing * 2));
            g.DrawString("Q", font, Brushes.Blue, 5, Height - 20 - (topOffset + spacing * 1));
            g.DrawString("QBar", font, Brushes.Green, 5, Height - 20 - topOffset);

            for (int i = 1; i < 200; i++)
            {
                // inputs
                g.DrawLine(Pens.Black,
                           i * timingWidth + leftOffset,
                           Height - ((float)srLatch.S.Output(i - 1) * 5 + topOffset + spacing * 3),
                           i * timingWidth + timingWidth + leftOffset,
                           Height - ((float)srLatch.S.Output(i) * 5 + topOffset + spacing * 3));

                g.DrawLine(Pens.Red,
                           i * timingWidth + leftOffset,
                           Height - ((float)srLatch.R.Output(i - 1) * 5 + topOffset + spacing * 2),
                           i * timingWidth + timingWidth + leftOffset,
                           Height - ((float)srLatch.R.Output(i) * 5 + topOffset + spacing * 2));

                // outputs
                g.DrawLine(Pens.Blue,
                           i * timingWidth + leftOffset,
                           Height - ((float)srLatch.Q(i - 1) * 5 + topOffset + spacing * 1),
                           i * timingWidth + timingWidth + leftOffset,
                           Height - ((float)srLatch.Q(i) * 5 + topOffset + spacing * 1));

                g.DrawLine(Pens.Green,
                           i * timingWidth + leftOffset,
                           Height - ((float)srLatch.QBar(i - 1) * 5 + topOffset + spacing * 0),
                           i * timingWidth + timingWidth + leftOffset,
                           Height - ((float)srLatch.QBar(i) * 5 + topOffset + spacing * 0));

                // grid

                /*
                 * g.DrawLine(Pens.Gray,
                 *      i*timingWidth + leftOffset,
                 *      Height - 50 - (i%10 == 0 ? 30 : 0),
                 *      i*timingWidth + leftOffset,
                 *      Height);
                 */
            }
        }
コード例 #2
0
        public void sr_latch_circuit_reset()
        {
            var srLatch = new SRLatch(TTLGateTypeEnum.Perfect);

            srLatch.S.Add(0);
            srLatch.R.Add(5);
            srLatch.RunCircuit();

            Assert.True(srLatch.CircuitCompletedSuccessfully);
            Assert.Equal(5, srLatch.Q(0));
            Assert.Equal(0, srLatch.QBar(0));
        }