Skip to content

Instantly share code, notes, and snippets.

@gdziuba
Created January 12, 2024 19:59
Show Gist options
  • Save gdziuba/3e08565bc0e024e81325dc028c5da792 to your computer and use it in GitHub Desktop.
Save gdziuba/3e08565bc0e024e81325dc028c5da792 to your computer and use it in GitHub Desktop.
USB HID to String (Barcode Scanner)

USB HID

This project can be used with Windows, Linux, and Mac.

Follow the instructions here to get started.

This flow gives an example of how to set up and test a USB HID input.

The most common example would be a barcode scanner.

[{"id":"cbae0763803aa6e9","type":"group","z":"3b6a718c4021497b","name":"USBHID","style":{"label":true},"nodes":["78f82fb335672aca","c1ecae6308a0525f","d99660be8c6c6066","546ab3a525f72ecc","1b5120024bf4bc62","f8d8cae1919e186c","e1d69c8863f6de73"],"x":34,"y":19,"w":692,"h":122},{"id":"78f82fb335672aca","type":"debug","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":60,"wires":[]},{"id":"c1ecae6308a0525f","type":"getHIDdevices","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"","x":300,"y":60,"wires":[["78f82fb335672aca"]]},{"id":"d99660be8c6c6066","type":"inject","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":60,"wires":[["c1ecae6308a0525f"]]},{"id":"546ab3a525f72ecc","type":"HIDdevice","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","connection":"68a0ec4b6af1dcb1","name":"","x":290,"y":100,"wires":[["e1d69c8863f6de73"],[]]},{"id":"1b5120024bf4bc62","type":"inject","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":100,"wires":[["546ab3a525f72ecc"]]},{"id":"f8d8cae1919e186c","type":"debug","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":100,"wires":[]},{"id":"e1d69c8863f6de73","type":"function","z":"3b6a718c4021497b","g":"cbae0763803aa6e9","name":"Hex to String","func":"const hexBuffer = msg.payload;\n\n// Convert the hex buffer to a Buffer object\nconst buffer = Buffer.from(hexBuffer, 'hex');\n\n// Convert the Buffer to a string\nconst string = buffer.toString();\n\n// Assign the string to msg.payload for further processing\nmsg.payload = string;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":100,"wires":[["f8d8cae1919e186c"]]},{"id":"68a0ec4b6af1dcb1","type":"HIDConfig","vid":"1504","pid":"1536","name":"Barcode Scanner"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment