Monday, 29 May 2017

Make a NodeJS server auto-detect a connected device through USB

I did a web interface for a colorimeter using a NodeJS server which reads USB serial inputs using the serialport npm library and sends that info to a local web page. The colorimeter is basically a circuit using a microcontroller which is connected to my PC through USB, using an intermediate USB module.

The web page has state messages like: "Device Detected" (if the page is started with the device already inserted in the USB), "Device Disconnected" (if I pull out the device from the USB). The message updates perfectly for scenarios like pulling out the device from the USB port but I can't make it autodetect when inserting it back in the USB, without doing a browser page refresh.

Is there any workaround for making the Node server detect automatically when the USB device is inserted in the PC and update the state message?

Server code: https://codepen.io/grazvan/pen/wdLGPZ?editors=0010#0 Currently, I am doing it on Linux that's why the boardPort = '/dev/ttyACM0';. I am open for solutions in Windows or another programming language too.



via Gorgan Razvan

No comments:

Post a Comment