Can't get hidraw0 device to open in nodeJS app

隐身守侯 提交于 2021-01-29 14:48:04

问题


Good evening!

I'm trying to setup a barcode scanner app using the Node SerialPort package, used on a Raspberry Pi 4, and I'm having a hard time getting the code to either recognise the device

I've identified that the path is /dev/hidraw0 as this is what I was able to ascertain from a dmesg output.

When I run cat /dev/hidraw0 it opens and when I scan a barcode it outputs %""'#''!'&" to the console (I know it's gibberish, but different problem for a different day). BUT, when I reference this path in my nodeJS code, I get the below error:

Serial port error: Error: Error: Invalid argument setting custom baud rate of 9600

I've confirmed on the manufacturer website that the default baud rate is 9600. I have tried removing the baudRate option in the below code, but it still says the same error.

This is the code I'm using right now:

// Use the serialport module to get scanner  data
const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline')

// Open the serial port with some configuration
const port = new SerialPort('/dev/hidraw0', {baudRate: 9600});
const parser = new Readline()
port.pipe(parser)

// When the port is open just say so
port.on('open', function() {
 console.log('Serial port open');
});

// Check for errors on the serial interface
port.on('error', function(err) {
 console.log(`Serial port error: ${err}`);
});

// Pass scanner data onto web server
port.on('data', function(data) {
 console.log('Scan prompted');
});

The USB Scanner I'm using is the Zebra LS2208 and I would love some help or guidance on what may be causing this.

Thanks in advance!


回答1:


In case anyone else comes around this, I was not able to get the device working with the NPM package I referenced, but as this module used node-hid, I decided to use that one and was able to get my scanner recognised and working properly.



来源:https://stackoverflow.com/questions/60668365/cant-get-hidraw0-device-to-open-in-nodejs-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!