pavel-a/usb-relay-hid

nodejs API

aartek opened this issue · 4 comments

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...

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

@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.

@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 ;)

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);
  });
};