Package examples.circuit

Source Code of examples.circuit.LogicalTest

/* ==============================================
* Simtools : The tools library used in JSynoptic
* ==============================================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 1999-2008, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: LogicalTest.java,v 1.2 2008/10/24 15:50:51 ogor Exp $
*
* Changes
* -------
* 08-Sep-2008 : Initial public release (RO);
*
*/
package examples.circuit;

import jsynoptic.plugins.circuit.CircuitConnection;
import jsynoptic.plugins.circuit.CircuitGate;

public class LogicalTest {
   
    AndComponent and1;
    OrComponent or1, or2;
    LogicalEmiter e1, e2, e3;
   
    public LogicalTest(){
        // create a circuit for test
        and1 = new AndComponent(1, 20, 20, 20);
        or1 = new OrComponent(2, 20, 20, 20);
        or2 = new OrComponent(3, 20, 20, 20);
       

        e1 = new LogicalEmiter(20, 20, 20, 20);
        e2 = new LogicalEmiter(20, 20, 20, 20);
        e3 = new LogicalEmiter(20, 20, 20, 20);
  
        // connections
        CircuitConnection c1 = new CircuitConnection(1, 0, 0, 0);
        CircuitConnection c2 = new CircuitConnection(2, 0, 0, 0);
        CircuitConnection c3 = new CircuitConnection(3, 0, 0, 0);
        CircuitConnection c4 = new CircuitConnection(4, 0, 0, 0);
        CircuitConnection c5 = new CircuitConnection(5, 0, 0, 0);
        CircuitConnection c6 = new CircuitConnection(4, 0, 0, 0);

        c1.connect(e1.out, true);
        c1.connect(and1.in1, false);
       
        c2.connect(e2.out, true);
        c2.connect(or1.in1, false);
       
        c3.connect(or1.out, true);
        c3.connect(or2.in1, false);
       
        c4.connect(and1.out, true);
        c4.connect(or2.in2, false);
       
        c5.connect(or2.out, true);
        c5.connect(and1.in2, false);
       
        c6.connect(e3.out, true);
        c6.connect(or1.in2, false);
     
        e3.emitASignal(false);
        e1.emitASignal(true);
       
        System.out.println("All shall be false:");
        System.out.println( ((LogicalSignal)((CircuitGate)or2.out).getCurrentSignal()));
       
        e2.emitASignal(true);
        System.out.println(((LogicalSignal)((CircuitGate)or2.out).getCurrentSignal()));
       
        e2.emitASignal(false);
        System.out.println( ((LogicalSignal)((CircuitGate)or2.out).getCurrentSignal()));
       
        e1.emitASignal(true);
        System.out.println(((LogicalSignal)((CircuitGate)or2.out).getCurrentSignal()));
       
        e1.emitASignal(false);
        System.out.println(((LogicalSignal)((CircuitGate)or2.out).getCurrentSignal()));
    }
   
    public static void main(String[] args){
        new LogicalTest();
    }
}
TOP

Related Classes of examples.circuit.LogicalTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.