Menu

#394 Device rescan needed every time because of changing USB bus/device number

v1.0_(example)
open
nobody
usb (1)
5
2022-01-15
2022-01-14
John S.
No

I have a USB scanner that regularly receives dufferent USB bus and device numbers when restarting the host or when replugging. When these numbers change, gscan2pdf resets all scan settings and I must rescan the devices.

I compared the configuration file gscan2pdfrc in both cases and found the following differences:

78c78
<    "device" : "pfufs:fi-7140:003:002",
---
>    "device" : "pfufs:fi-7140:002:003",
96c96
<          "label" : "FUJITSU fi-7140 on pfufs:fi-7140:003:002",
---
>          "label" : "FUJITSU fi-7140 on pfufs:fi-7140:002:003",
98c98
<          "name" : "pfufs:fi-7140:003:002",
---
>          "name" : "pfufs:fi-7140:002:003",

Apparently, the device identifier changed because of the changed bus and device numbers.

Can gscan2pdf be changed to identify the device in a stable manner? For example, identifying by manufacturer ID and device ID would work well in my case, because I have only one scanner of this type. Maybe this could be an alternative mode to address devices if a configuration option is set (config file and command line).

Discussion

  • Jeffrey Ratcliffe

    So the problem is really that because gscan2pdf considers every different device name a different device, the device settings are only remembered if the bus and device numbers match.

    I don't see a way to find the new device name without scanning for devices, but I could certainly do some fuzzy matching to ignore differences in the device and bus numbers when restoring the settings.

    Good idea! Thanks for the report!

     
  • John S.

    John S. - 2022-01-15

    Thanks for your response. I like the idea of fuzzy matching. As a suggestion - if only the bus and device number are different and only one device matches when ignored, then you could safely assume it is the same device. In case of multiple devices you could keep the old behavior to be on the safe side.
    Best Wishes

    P. S. Until the feature is implemented I am using the following wrapper script to work around the problem.

    gscan2pdf-wrapper:

    config=~/.config/gscan2pdfrc
    [ -r "$config" ] || exit 1
    
    device="$(lsusb | grep Fujitsu | head -n1 | tr ':' ' ' | awk '{ print "pfufs:fi-7140:" $2 ":" $4}')"
    [ -n "$device" ] || exit 2
    echo "Scanner device detected: '$device'"
    
    echo "Patching config file '$config'"
    sed -i'bak' 's/pfufs:fi-7140:[[:digit:]]\{3\}:[[:digit:]]\{3\}/'"$device"'/g' "$HOME/.config/gscan2pdfrc"
    
    gscan2pdf &
    
     

    Last edit: John S. 2022-01-15

Log in to post a comment.

MongoDB Logo MongoDB