gdziuba / node-red-contrib-usbhid

A node-hid (USB HID device access library) wrapper for nodered
Apache License 2.0
3 stars 0 forks source link

unable to duplicate the output of the provided example #9

Open EW57 opened 7 months ago

EW57 commented 7 months ago

Device: Raspberry Pi Zero W OS: Raspberry Pi Imager recommended RPi OS (Legacy, 32 bit) Debian/Bullseye Barcode Scanners: Honeywell 1990iXR & Nadamoo Bur3003 Process:

  1. Fresh install of recommended RPi OS (Legacy, 32 bit) Debian/Bullseye
  2. Library installation of node-red-contrib-usbhid
  3. Resolved Raspberry Pi/Node Red crashing by implementing the following
  4. After locating VID & PID, the “HIDdevice” flow would error with “TypeError: Cannot write to hid device”
  5. Ignoring this error & scanning would output individual characters as shown below (& not as a continuous string). Request:
    What am I currently missing that is preventing me from duplicating the results shown in the original article?

    [ { "id": "e7bfae6b93c713bf", "type": "tab", "label": "Flow 1", "disabled": false, "info": "", "env": [] }, { "id": "7213798195f1c63d", "type": "group", "z": "e7bfae6b93c713bf", "name": "USBHID", "style": { "label": true }, "nodes": [ "c5f5f7e78d547a66", "0ed45f133c95bb55", "8a4dd18c70dca5d2", "06b8086b8b687eb9", "911ec5f175e778cf", "fbaea9ab03cbe2a2", "27114005a81dc1e2" ], "x": 194, "y": 59, "w": 692, "h": 122 }, { "id": "c5f5f7e78d547a66", "type": "debug", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "name": "debug 2", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 620, "y": 100, "wires": [] }, { "id": "0ed45f133c95bb55", "type": "getHIDdevices", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "name": "", "x": 460, "y": 100, "wires": [ [ "c5f5f7e78d547a66" ] ] }, { "id": "8a4dd18c70dca5d2", "type": "inject", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 300, "y": 100, "wires": [ [ "0ed45f133c95bb55" ] ] }, { "id": "06b8086b8b687eb9", "type": "HIDdevice", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "connection": "68a0ec4b6af1dcb1", "name": "", "x": 470, "y": 140, "wires": [ [ "fbaea9ab03cbe2a2" ], [] ] }, { "id": "911ec5f175e778cf", "type": "debug", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "name": "debug 3", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 780, "y": 140, "wires": [] }, { "id": "fbaea9ab03cbe2a2", "type": "function", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "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": 630, "y": 140, "wires": [ [ "911ec5f175e778cf" ] ] }, { "id": "27114005a81dc1e2", "type": "inject", "z": "e7bfae6b93c713bf", "g": "7213798195f1c63d", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 300, "y": 140, "wires": [ [ "06b8086b8b687eb9" ] ] }, { "id": "68a0ec4b6af1dcb1", "type": "HIDConfig", "vid": "3118", "pid": "4097", "name": "Barcode Scanner" } ]

Picture1 Picture2 Picture3 Picture4

gdziuba commented 7 months ago

Did you run the commands associated to the Linux instructions? By default node red can access usb because of permissions.

These instructions?

EW57 commented 7 months ago

Yes, initially when I would attempt to reload the rules, I would get an error. Upon looking @ node-hid, I noticed a slight difference as follows sudo udevadm control --reload-rules, no errors occurred with the 'sudo' addition, however, I still have the issue of each character having its own message (as shown above). My /etc/udev/rules.d/85-pure-data.rules is as follows: Capture

gdziuba commented 7 months ago

Make sure you don't have any other competing rules in the same directory and assure that you restarted.

gdziuba commented 7 months ago

@EW57 I think I figured out your issue. Sorry hadn't had a chance to look until now. You need to update your KERNEL=="hidraw2" not "hidraw0"

Signified here: image

It should look like this:

SUBSYSTEM=="input", GROUP="input", MODE="0777"
SUBSYSTEM=="usb", MODE:="777", GROUP="input"
KERNEL=="hidraw2", MODE="0777", GROUP="input"

I should probably make this point a little bigger in the readme:

Now add the following rules to /etc/udev/rules.d/85-pure-data.rules making sure to updated KERNEL to your hidraw* device:

EW57 commented 7 months ago

Attempted an number of variations yesterday with both the Honeywell & Bur3003.

With the Honeywell, if the kernel was changed to "hidraw*", the scanner would output a string vs individual characters, so that was an improvement.

However, regardless of what scanner settings, I changed, I couldnt eliminate additional characters from being output.

For example, scanning a type 39 barcode with a value of "*03-02*" would output "]A003-02b0"

I assume this could be rectified in the 'hex to string' function, however, I currently lack the understanding on how to manipulate that data.

With the Bur3003, regardless of what I changed the kernel value to, (or scanner settings attempted), the output would remain as shown, being a number of outputs all with single character values.

It appears that the Symbol LS2208 is a popular device & I'm attempted to try one in this application.

gdziuba commented 7 months ago

@EW57 Glad to hear that you had improvement and got data in. It sounds like the issues you have now are "configuration" of the barcode scanner and potentially regexing out the parts you don't like with extra characters.

Have you tried using something like ChatGPT for the extra characters. It become very helpful for creating functions like this. For example, the question I would ask for the example above would look like this:

Can you help me write a function in Node-RED that will extract the the value using a regular expression out of msg.paylod. The payload looks like "��]A003-02b0" and I want to pull the variable "03-02" out.

Running it through ChatGPT it returned this function:

// Function node code
// Assuming msg.payload is the string from which you want to extract the value

// Regular expression to find the pattern "A" followed by two digits, a hyphen, and two more digits
const regex = /A(\d{2}-\d{2})/;

// Using the regular expression to search within msg.payload
const matches = msg.payload.match(regex);

// Check if we found a match
if (matches && matches.length > 1) {
    // matches[0] would be the full string that matches the regex including 'A'
    // matches[1] is the first capturing group (the part we're interested in)
    msg.payload = matches[1];
} else {
    // If no match was found, maybe handle the error or set payload to null
    msg.payload = null;
}

return msg;

Use Regexer to adjust further.

intmech commented 7 months ago

I'm having a very similar issue, I've followed the linux install instructions, I'm running on a rpi4b 32bit up to date, I can see the barcode scanner outputs the correct string in a text editor on the pi's local desktop, but the usbhid node gives me gibberish.

image image

any advice on where to look?

gdziuba commented 7 months ago

@intmech What happens if you bypass the hex to string block? It looks like the barcode scanner is setup to send multiple messages.

When can you connect a debug node to the second output and see if you are getting any errors?

intmech commented 7 months ago

No errors on the 2nd output but the hex codes do represent the #%' symbols that the hex to string function outputs

On Sat, Mar 16, 2024, 12:11 PM gdziuba @.***> wrote:

@intmech https://github.com/intmech What happens if you bypass the hex to string block? It looks like the barcode scanner is setup to send multiple messages.

When can you connect a debug node to the second output and see if you are getting any errors?

— Reply to this email directly, view it on GitHub https://github.com/gdziuba/node-red-contrib-usbhid/issues/9#issuecomment-2002033155, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASZHIXTMYF62UKJC6QFNG7DYYRVKLAVCNFSM6AAAAABEAE2SH2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBSGAZTGMJVGU . You are receiving this because you were mentioned.Message ID: @.***>

intmech commented 7 months ago

image

gdziuba commented 7 months ago

@intmech, IMO the node is functioning as expected, but parsing the data is the problem. I would look at the documentation for the scanner and see if the data is being sent in a certain structure. From there, it would be possible to reverse engineer.

p84586 commented 2 weeks ago

You need change Honeywell barcode reader to USB-HID or USB keyboard.