Our first plug-in will be a combinatorial component with 3 inputs and 3 outputs that simply copies its input to its output. The code is shown below:
package plugins.tutorial;
import dlsim.document.DLPlugIn;
/**
* Plugin0: sample plugin using default view
* 3 inputs, 3 outputs
* copies input to corresponding output
* Pins are number consecutively: 0, 1, 2 are input; 3, 4, 5 are output
*
* @author rms
*
*/
public class Plugin00 extends DLPlugIn {
public static PluginInfo info =
new PluginInfo("My First PlugIn",
"Writes input to output",
"3 bits");
/**
* Constructor must specify input and output size (default is 0)
*/
public Plugin00() {
super();
setInputSize(3);
setOutputSize(3);
}
/**
* evalState is called when an input state changes
* Parameters:
* source - pin number of input source that changed
* val - new state value (0 or 1)
*
* Output changes are propagated using putState(dest, val),
* where dest is the output pin number and val is the new state.
*
* Current input/output pin states are accessed using
* getState(pinNo).
*/
public void evalState(int source, int val) {
putState(source+getInputSize(), val);
}
}
As this is the simplest possible plug-in, it shows the API's minimal requirements and options. Note that Plugin00 extends DLPlugIn, which is an abstract class with a single abstract method, evalState. evalState is the call-back method for any change of input value. It is the heart of the plug-in.
Pins are numbered consecutively from 0, with input pins given lower values than output pins. In this example pins 0-2 are input pins and 3-6 are output pins.
New outputs are generated using void putState(int dest, int val), where dest is the (output) pin number and val is the new value. Using int getInputSize() we can easily calculate the output pin number from the input pin number.
Run DLSim 3 (using "ant run") and build the circuit shown below using Plugin00.
The default view used by this plug-in displays the plug-in's class name and a "left-right" pin configuration. The component's size is determined so that it accomodates the width of the name and the height of the pin set.![]()
Exercises