kazuhikoarase / simcirjs

A circuit simulator in HTML5 and JavaScript
https://kazuhikoarase.github.io/simcirjs/
MIT License
291 stars 152 forks source link

How to set HIGH to in-port in registered device? #13

Closed tyfkda closed 6 years ago

tyfkda commented 6 years ago

Is there any way to set HIGH to a in-port in registered device?

I tried to create some logic which uses DC to connect to some gate directly. It worked as expected in a workspace.

When I registered the circuit and use it as a device, it didn't work.

ss

In above screenshot, I've registered MyNot using simcir.registerDevice method. In the logic I connected DC to NAND. It worked as Not gate in workspace. But the registered device didn't work as expected. I suspect that DC output is ignored in registered device.

Here is the code:

  simcir.registerDevice(
    'MyNot',
    {
      "width":800,
      "height":400,
      "showToolbox":true,
      "toolbox":[
        {"type":"In"},
        {"type":"Out"},
        {"type":"Joint"},
        {"type":"DC"},
        {"type":"LED"},
        {"type":"PushOff"},
        {"type":"PushOn"},
        {"type":"Toggle"},
        {"type":"BUF"},
        {"type":"NOT"},
        {"type":"AND"},
        {"type":"NAND"},
        {"type":"OR"},
        {"type":"NOR"},
        {"type":"XOR"},
        {"type":"XNOR"},
      ],
      "devices":[
        {"type":"Toggle","id":"dev0","x":72,"y":24,"label":"Toggle","state":{"on":true}},
        {"type":"In","id":"dev1","x":128,"y":24,"label":"In"},
        {"type":"DC","id":"dev2","x":16,"y":56,"label":"DC"},
        {"type":"NAND","id":"dev3","x":184,"y":48,"label":"NAND"},
        {"type":"Out","id":"dev4","x":240,"y":48,"label":"Out"},
        {"type":"LED","id":"dev5","x":296,"y":48,"label":"LED"}
      ],
      "connectors":[
        {"from":"dev0.in0","to":"dev2.out0"},
        {"from":"dev1.in0","to":"dev0.out0"},
        {"from":"dev3.in0","to":"dev1.out0"},
        {"from":"dev3.in1","to":"dev2.out0"},
        {"from":"dev4.in0","to":"dev3.out0"},
        {"from":"dev5.in0","to":"dev4.out0"}
      ]
    }
  );
{
  "width":400,
  "height":200,
  "showToolbox":true,
  "toolbox":[
    {"type":"MyNot"},
    {"type":"In"},
    {"type":"Out"},
    {"type":"Joint"},
    {"type":"DC"},
    {"type":"LED"},
    {"type":"PushOff"},
    {"type":"PushOn"},
    {"type":"Toggle"},
    {"type":"BUF"},
    {"type":"NOT"},
    {"type":"AND"},
    {"type":"NAND"},
    {"type":"OR"},
    {"type":"NOR"},
    {"type":"XOR"},
    {"type":"XNOR"}
  ],
  "devices":[
    {"type":"LED","id":"dev0","x":192,"y":24,"label":"LED"},
    {"type":"DC","id":"dev1","x":16,"y":24,"label":"DC"},
    {"type":"Toggle","id":"dev2","x":64,"y":24,"label":"Toggle","state":{"on":true}},
    {"type":"MyNot","id":"dev3","x":112,"y":24,"label":"MyNot"}
  ],
  "connectors":[
    {"from":"dev0.in0","to":"dev3.out0"},
    {"from":"dev2.in0","to":"dev1.out0"},
    {"from":"dev3.in0","to":"dev2.out0"}
  ]
}
kazuhikoarase commented 6 years ago

Hi, You can't set it. Here is a quotation from the document.

Remember that all the connectors on an input of 'In' and an output of 'Out' are disconnected internally when the device is reused.

tyfkda commented 6 years ago

@kazuhikoarase thank you to your answer.

The upper input line of the NAND gate is connected to 'In', so it is reasonable to disconnect a line before it. But the lower one is connected to DC directly, not 'In'. So actually this is not used for 'In' port of the registered device. Is the rule applied in this case, too?

If so, is there any plan to change the behavior to preserve connections unrelated to 'In' or 'Out'? Thanks.

kazuhikoarase commented 6 years ago

Hi again,

DC that integrated in the library does not supply a power.

What's your purpose?

In this case, I think you can do like this.

image

tyfkda commented 6 years ago

I am trying to create 4bit increment logic(Inc4) using 4bit adder(Add4):

ss

I think it is useful to enable HIGH input to make specialized logic from general one.

kazuhikoarase commented 6 years ago

All the output is derived by some input.

Would this help you?

image

tyfkda commented 6 years ago

Aha, it worked! I didn't come up this idea, thanks.

tyfkda commented 6 years ago

@kazuhikoarase , I've sent a pull request to enable DC in registered device. Would you please take a look?

16