GithubHelp home page GithubHelp logo

Write a floating value about node-eibd HOT 3 CLOSED

andreek avatar andreek commented on June 2, 2024
Write a floating value

from node-eibd.

Comments (3)

andreek avatar andreek commented on June 2, 2024

Hey,

thank you, it's really kind to get such a feedback.

The encoding isn't implemented in this module, so you have to do more to send a floating value. I guess you mean EIS5/DPT9 Values.

var encodeDPT9 = function(value) {

  var state = value;

  var data = null;
  var sign = (state < 0 ? 0x8000 : 0 );
  var exp = 0;
  var mant = 0;

  mant = new Number(state * 100.0);

  while( Math.abs(mant) > 2046 ) {
    mant = mant >> 1;
    exp += 1;
  }

  data = sign | (exp << 11) | (mant & 0x07ff);

  var buf = new Array(3);
  buf[0] = 0;
  buf[1] = data >> 8;
  buf[2] = data & 0xff;

  return buf;

};

var conn    = eibd.Connection();
var address = eibd.str2addr('1/0/0');

conn.socketRemote({ host: host, port: port }, function() {
    conn.openTGroup(address, 1, function (err) {
      if(err) {
        callback(err);
      } else {

        var data = encodeDPT9(20.5);
        conn.sendAPDU(data, callback);

      }
    });
})

I hope this is a solution for your issue. I've only executed the code local with tests and not in any eibd/knx environment, because I don't have access to one at the moment.

from node-eibd.

ptorrent avatar ptorrent commented on June 2, 2024

Thanks ! I'll see if it's work.

I found a little problem in your example :

parser.on('write', function(src, dest, val){
console.log('Write from '+src+' to '+dest+': '+val);
});

==>

parser.on('write', function(src, dest, dpt, val){
console.log('Write from '+src+' to '+dest+': '+val);
});

You just missed the dpt argument in your function

from node-eibd.

andreek avatar andreek commented on June 2, 2024

Thanks. I've fixed it.

from node-eibd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.