Barcode Scanner/Keyboard on BBB with Crontab

Hello all,

I have been successfully using a barcode scanner / keyboard emulator with python on a BBB thanks to the evdev library (https://python-evdev.readthedocs.io/en/latest/) recommended by Drew Fustini.

However, when I run the main program with crontab instead of from a console (I want to eliminate the need to have a laptop at the workstation), the barcode scanner no longer works. I suspect it has something to do with with the /dev/input path to the device being different in that environment, but I’m not entirely sure.

I’ve done some searching and reading into this but haven’t found the magic answer yet. I’ve not yet even been able to connect a console to the instance that was spawned by crontab to see what’s going on inside of it.

Any guidance appreciated, including pointing me to resources to work through myself.

Hello all,

I have been successfully using a barcode scanner / keyboard emulator with python on a BBB thanks to the evdev library (https://python-evdev.readthedocs.io/en/latest/) recommended by Drew Fustini.

However, when I run the main program with crontab instead of from a console (I want to eliminate the need to have a laptop at the workstation), the barcode scanner no longer works. I suspect it has something to do with with the /dev/input path to the device being different in that environment, but I’m not entirely sure.

I’ve done some searching and reading into this but haven’t found the magic answer yet. I’ve not yet even been able to connect a console to the instance that was spawned by crontab to see what’s going on inside of it.

Any guidance appreciated, including pointing me to resources to work through myself.

I’ve been using C, not Python, but I do launch my program from a udev rule, which should be comparable to being launched from crontab. I do a bit more in the udev rules (https://github.com/jadonk/beagle-tester/blob/master/beagle-tester.rules) to actually create a symlink for the barcode scanner that I then use in my C program:

KERNEL==“event*”, ATTRS{idVendor}==“05fe”, ATTRS{idProduct}==“1010”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”
KERNEL==“event*”, ATTRS{idVendor}==“05f9”, ATTRS{idProduct}==“2204”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”
KERNEL==“event*”, ATTRS{idVendor}==“067e”, ATTRS{idProduct}==“0801”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”
KERNEL==“event*”, ATTRS{idVendor}==“0c2e”, ATTRS{idProduct}==“0901”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”
KERNEL==“event*”, ATTRS{idVendor}==“05f9”, ATTRS{idProduct}==“2206”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”
KERNEL==“event*”, ATTRS{idVendor}==“24ea”, ATTRS{idProduct}==“0197”,\
SYMLINK+=“input/beagle-barcode”, TAG+=“systemd”,\
ENV{SYSTEMD_WANTS}=“beagle-tester.service”

You can see I also use the insertion of the barcode scanner to startup the beagle-tester.service (https://github.com/jadonk/beagle-tester/blob/master/beagle-tester.service):

[Unit]
Description=Beagle Self-test
Requires=dev-input-beagle\x2dbarcode.device
BindsTo=dev-input-beagle\x2dbarcode.device

[Service]
ExecStart=/usr/sbin/beagle-tester

In my C program (https://github.com/jadonk/beagle-tester/blob/master/beagle-tester.c#L3119), I just open up the symlink:

int barcode = open("/dev/input/beagle-barcode", O_RDONLY);

The path shouldn’t change based on if you invoke the program from the console or by a crontab, but it could change due to adding/removing input devices. I suggest you look at my udev-rule + systemd method of invocation and see if that makes it more stable. The VID/PID entries in the udev rules are based on which barcode scanners I’ve used/tested. You can make a more generic rule to try to catch more input devices.

Note, these rules come pre-installed on the Debian images, so they might actually be getting in your way already! We use these in production tests of the boards.

Thank you for this information. I will have to do some reading and experimenting with udev and symlinks over the next few days.

Interesting that you mention this in the context of a BBB self-test, because a PCBA factory functional test fixture is exactly the application I’m working on right now.