Skip to content

Instantly share code, notes, and snippets.

@bendytree
Created August 26, 2022 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendytree/7a1c85c1c508bcdf3e6a5ae826a6ad00 to your computer and use it in GitHub Desktop.
Save bendytree/7a1c85c1c508bcdf3e6a5ae826a6ad00 to your computer and use it in GitHub Desktop.
NOYITO USB Control Relay in NodeJS
const HID = require('node-hid');
class Relay {
constructor() {
const devices = HID.devices();
const deviceInfo = devices.find(d => d.product === 'USBRelay8');
this.device = new HID.HID(deviceInfo.path);
}
set(n, on) {
const send = Array(9).fill(0x0);
send[1] = on ? 0xff : 0xfd;
send[2] = n; // n is 1-8
this.device.sendFeatureReport(send);
}
setAll(on) {
const send = Array(9).fill(0x0);
send[1] = on ? 0xfe : 0xfc;
this.device.sendFeatureReport(send);
}
disconnect() {
this.device.close();
}
}
// Example usage
const relay = new Relay();
relay.setAll(false);
relay.set(1, true); // 1 is the first relay, 8 is the last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment