pavel-a / usb-relay-hid

Software for USB-connected relays with HID interface. See the WIKI for more info.
http://vusb.wikidot.com/project:driver-less-usb-relays-hid-interface
242 stars 105 forks source link

nodejs API #15

Open aartek opened 7 years ago

aartek commented 7 years ago

Hey, I've made a library for nodejs, based on your project (it uses your DLL), but I'm not sure if I can publish it to github and npm repository. I don't want to break the license...

pavel-a commented 7 years ago

You can publish your files, and get my DLL from github using curl or whatever. Sorry I don't know anything about nodejs.

MaxNijholt commented 6 years ago

@aartek if you can publish or share your files. I'm currently using node-hid to control the relay. A direct interface would be better.

aartek commented 6 years ago

@MaxNijholt I've made my repo public. The code is in the "develop" branch. https://github.com/aartek/usb-relay-hid-node-js/tree/develop

It's not well tested, so If you find any bugs, or will have ideas for improvements, feel free to make a pull request.

Let me know if that works for you ;)

MaxNijholt commented 6 years ago

It works like a charm! Thanks @aartek! Only one small note: I changed the x64 dll to the x32. Due to the fact that the system is in x32 still. We still need to test it on Windows 10, x64.

Perhaps download the file instead of having it in your repo?

var http = require('http');
var fs = require('fs');

var download = function(url, dest, cb) {
  var file = fs.createWriteStream(dest);
  var request = http.get(url, function(response) {
    response.pipe(file);
    file.on('finish', function() {
      file.close(cb);  // close() is async, call cb after close completes.
    });
  }).on('error', function(err) { // Handle errors
    fs.unlink(dest); // Delete the file async. (But we don't check the result)
    if (cb) cb(err.message);
  });
};