Get data from barcode

Hi everyone!

I've been trying to read data from a barcode and print it on a debug node, but it just doesn't print anything.

I've the barcode reader connected by USB port to a raspberry pi 4. The reader is configured for a USB interface, 9600 baud rate, 8 data bits, 1 stop bit, and no parity. The reader appears at the address /dev/hidraw0, I know its because it's the only device which appears in /dev/ directory when I plug it in and out.

But when I put that address in the "serial input" node, I get the following error in the debug window: "Error: permission denied, cannot open /dev/hidraw0". So, I ran the following command to give it permission: sudo chmod 777/dev/hidraw0 (I know it's temporary, but it still doesn't work).

In my flow, I only have the nodes "serial input" and "debug". The serial input is configured like 9600 baud rate, 8 data bits, 1 stop bit, and no parity. In the input part, I already tried the options "after a timeout of 100 ms" and "on the character \ n". And the debug node, I already configured it with the output of msg.payload and the complete msg object.

So my question is if there is another way to read and print the data with a barcode reader with node red?

Because the reader works correctly if I use Word or Excel, in fact I use those programs to verify that after reading a code the "enter" works.

I'd also like to know how I could use the python node to process the information the barcode gives me.

Thanks :slightly_smiling_face:.

I would recommend you start from that end... Google for some Python code to read and parse the data, then send that data to Node Red via whatever method works best... MQTT perhaps?

For example

there should be a space after the 777

Have you searched the forum using 'barcode'? There are many threads out there and while I don't know if any will provide a solution for you, that's the first place to start.

Have you tried sudo nano /etc/udev/rules.d/50-hidraw.rules
KERNEL=="hidraw*", GROUP="plugdev", MODE="0660" RUN+="/bin/chgrp -R plugdev /dev/bus/usb/001"

Thanks, but I would like to keep looking for a way to get the data directly from the barcode reader. Anyway, if I can't find another solution, yours sounds good.

Hi, thanks. Earlier in the debug window, it gave me the error "permission denied, cannot open / dev / hidraw0", but now after entering your command, I get the following error:
"[serialconfig: 225189b78960afdd] serial port /dev /hidraw0 error : Error: Error: Invalid argument setting custom baud rate of 9600 ".
I've already tried all the baud rate options. I was researching about that error, and everyone uses the "stty" command but I think it doesn't work in raspbian, or at least when I entered the command: "stty -F /dev/hidraw0 9600" I get the message "invalid argument"

The hidraw driver provides a raw interface to USB and Bluetooth Human
Interface Devices (HIDs). It differs from hiddev in that reports sent and
received are not parsed by the HID parser, but are sent to and received from
the device unmodified.

Hidraw should be used if the userspace application knows exactly how to
communicate with the hardware device, and is able to construct the HID
reports manually. This is often the case when making userspace drivers for
custom HID devices.
So do you know exactly how to communicate with this device ? You are sure that /dev/hidraw0 is the correct device ?

Some barcodereaders which are HID devices (keyboards)

Try looking at what dmesg tells you (also in /var/log/messages) for the point where the USB device is detected, should give you a clue as to how linux has assigned it. A keyboard should appear somewhere in /dev/input, a serial port may be a /dev/tty

If you find this is a keyboard device, try using usbhid

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.