roccomuso / node-ads

NodeJS Twincat ADS protocol implementation
58 stars 21 forks source link

added ADS function readState #11

Closed PLCHome closed 6 years ago

PLCHome commented 6 years ago

added ADS function readState

var client = ads.connect(options, function() {
    this.readState(function(err,rs) {
      var text = '?';
      switch (rs.adsState) {
        case ads.ADSSTATE.INVALID:
              text = 'INVALID';
              break;
        case ads.ADSSTATE.IDLE:
              text = 'IDLE';
              break;
        case ads.ADSSTATE.RESET:
              text = 'RESET';
              break;
        case ads.ADSSTATE.INIT:
              text = 'INIT';
              break;
        case ads.ADSSTATE.START:
              text = 'START';
              break;
        case ads.ADSSTATE.RUN:
              text = 'RUN';
              break;
        case ads.ADSSTATE.STOP:
              text = 'STOP';
              break;
        case ads.ADSSTATE.SAVECFG:
              text = 'SAVECFG';
              break;
        case ads.ADSSTATE.LOADCFG:
              text = 'LOADCFG';
              break;
        case ads.ADSSTATE.POWERFAILURE:
              text = 'POWERFAILURE';
              break;
        case ads.ADSSTATE.POWERGOOD:
              text = 'POWERGOOD';
              break;
        case ads.ADSSTATE.ERROR:
              text = 'ERROR';
              break;
        case ads.ADSSTATE.SHUTDOWN:
              text = 'SHUTDOWN';
              break;
        case ads.ADSSTATE.SUSPEND:
              text = 'SUSPEND';
              break;
        case ads.ADSSTATE.RESUME:
              text = 'RESUME';
              break;
        case ads.ADSSTATE.CONFIG:
              text = 'CONFIG';
              break;
        case ads.ADSSTATE.RECONFIG:
              text = 'RECONFIG';
              break;
        case ads.ADSSTATE.STOPPING:
              text = 'STOPPING';
              break;
      }
      console.log('The state is '+text);
      this.end();
    });
})
roccomuso commented 6 years ago

Let's resolve conflicts and we can merge :+1:

PLCHome commented 6 years ago

now it should work, please look over it again

PLCHome commented 6 years ago

Thanx 👍

Do you know Node-Red? I want to develop a plugin for TwinCat. May I use your module as a base? That would make many easier.

roccomuso commented 6 years ago

Yes. I've used it extensively. And it depends also on one of my module (memorystore).

Of course you can, feel free to develop a plugin. PS. I've added you as a node-ads mantainer ;)

PLCHome commented 6 years ago

Thanx:
I'm just at the beginning: https://github.com/ChrisHanuta/node-red-contrib-ads

PLCHome commented 6 years ago

Can you increase the NPM version?

roccomuso commented 6 years ago

Yes, we should first make sure that there are no breaking changes. And that it works flawlessly. I'd push a v2.0.0 right now. And then we can add the multiRead implementation as a minor v2.1.0.

What do you guys think @ChrisHanuta @ovi1337 ? confirm

PLCHome commented 6 years ago

Is OK for me. But I can also live with an 1.2.0.

PLCHome commented 6 years ago

In the Iplemantation, there are no changes to the call. All old calls work as before, I have paid attention to the compatiblity of the API.

ovi1337 commented 6 years ago

I also think 1.2.0 makes more sense, because we don't have breaking changes for now. We should reserve us the major release v2.0.0 for a larger refactoring.

roccomuso commented 6 years ago

Ok, I wasn't sure about the breaking changes. I'll publish a v1.2.0 now. Great. Thanks.