Tag Archives: scanning

SANE Backends network scanning package for Synology NAS

UPDATE – SANE version 1.0.28, new frontend AirSane package, and updated frontend software info below

SANE-package

Many scanners last considerably longer than they enjoy driver updates for. Manufacturers are seldom willing to update drivers for new operating systems. The transition to 64bit was a similar obstacle. Furthermore Microsoft dropped support for the TWAIN scanning API in favour of the WIA (Windows Image Acquisition) for 64bit versions of its OS, and Apple removed TWAIN in macOS 10.9 Mavericks, superseded by ICA (Image Capture Architecture). These conditions have resulted in a mountain of perfectly good hardware being thrown away unnecessarily. I recently found myself without any modern drivers for my own Canon CanoScan LiDE 20, so I decided to do something about the problem. Now you can use this package to share your obsolete scanner from your Synology NAS.

SANE is an open source scanning API which has a fantastic wealth of device support. SANE’s differentiator is that it separates the drivers (backend) from the presentation and the scanning (frontend). This is ideal for a headless device like a NAS, and it also frees the frontend to be quite generic rather than highly customized to each device.

 

Device Support

HP all-in-one models are not supported by the package since their backend hpaio is not part of a standard SANE build, and it requires significant additional dependencies. Scanner backends which require libieee1284 are not supported by the package (canon_pp, hpsj5s, and mustek_pp), neither is backend dell1600n_net which needed a TIFF library and in fact only supports one device. You can verify which backend is required for your model of scanner using the SANE Project search engine. Expand below for the full list of backends which this Synology package supports:

Backend support in Synology package as of version 1.0.28-003
------------------------------------------------------------

Note that some backends default to disabled in /var/packages/sane-backends/target/etc/sane.d/dll.conf
This can be because they may slow down detection routines
This is a default SANE config unrelated to the Synology pacakge
Detection is faster if unused backends are commented out in this file

abaton
agfafocus
apple
artec
artec_eplus48u
as6e
avision
bh
canon
canon630u
canon_dr
cardscan
coolscan
coolscan2
coolscan3
dc25
dc210
dc240
dmc
epjitsu
epson
epson2
epsonds
fujitsu
genesys (except on armv5tel which lacks C++11 toolchain support)
gt68xx
hp
hp3500
hp3900
hp4200
hp5400
hp5590
hpljm1005
hs2p
ibm
kodak
kodakaio
kvs1025
kvs20xx
kvs40xx
leo
lexmark
ma1509
magicolor
matsushita
microtek
microtek2
mustek
mustek_usb
mustek_usb2
nec
net
niash
p5
pie
pieusb
pixma
plustek
plustek_pp
qcam
ricoh
ricoh2
rts8891
s9036
sceptre
sharp
sm3600
sm3840
snapscan
sp15c
st400
stv680
tamarack
teco1
teco2
teco3
test
u12
umax
umax_pp
umax1220u
xerox_mfp
 

Synology Package Installation

  • In Synology DSM’s Package Center, click Settings and add my package repository:
    Add Package Repository
  • The repository will push its certificate automatically to the NAS, which is used to validate package integrity. Set the Trust Level to Synology Inc. and trusted publishers:
    Trust Level
  • Now browse the Community section in Package Center to install SANE Backends.
    Community-packages
    The repository only displays packages which are compatible with your specific model of NAS. If you don’t see SANE Backends in the list, then either your NAS model or your DSM version are not supported at this time. DSM 6.0 is the minimum supported version for this package.
  • When the package is started it will attempt to detect a scanner and output the results to the package log. If your scanner is listed in the log, that is all that is required at the backend.
  •  

    SANE Frontend for the Computer

    Since I have a variety of systems at home I spent some time investigating the various options. I list them in order of quality of experience below (updated in September 2019). You will need to manually specify the IP address of your NAS when setting up the scanner. Be aware that the scanner will need redefining on the computer if you change USB port later for instance. No credentials are needed for connection by default.

    • AirSane (macOS Mojave and earlier) – Hands down the most elegant SANE frontend solution, and one which I have now packaged separately for Synology. AirSane will autodetect any available SANE scanner and will advertise it via Bonjour to the macOS Image Capture application as a shared AirScan device. No configuration is required – it just works! Even if you don’t have a Mac it offers a simple WebUI for scanning.
      AirSane is in active development at the time of writing in September 2019, in fact its author SimulPiscator fixed a few issues I discovered while testing prior to packaging it.
    • WiaSane (Windows 10 and earlier) – Marc Hoersken has developed a SANE to WIA bridge which works very well, presenting the remote device to Windows Device Manager as if it is locally attached. Scanning using the Windows Fax and Scan application is seamless (preview, partial selections etc.), and other software with WIA support can be used, for instance NAPS2 (Not Another PDF Scanner 2) which offers OCR, and Paint.net, both of which are free. Although the latest version of WiaSane does now include a signed device driver which works in Windows 10, the device configuration wizard only seems to work at install time, and each time the scanner changes USB ID it has to be removed and reinstalled.
      WiaSane was last updated in February 2017
    • SwingSane As a Java application SwingSane will run on most operating systems. It is full-featured but it has some rough edges which caused me to think it was broken when I first evaluated it. This explanatory video by SwingSane’s author Roland Quast explains some of the non-obvious aspects.
      The most confusing thing is that the Settings tab was not offering me the appropriate settings for my scanner – for instance I could not set the resolution or the page size. Roland explains in the video that these main settings were specifically targeting Epson scanners, and that for all other models Custom Settings should be used, in particular he recommends to select Check Options which queries the backend driver for its parameters. The next problem is that with custom settings SwingSane will not select the whole bed of the scanner by default, only a small selection. If you export the settings and inspect the XML file you can discover the constraint values (maxima) for the br-x and br-y values in millimetres (bottom right of the selection rectangle), set those and save the settings. This is far too counter-intuitive when surely these values can be determined automatically by the software.
      One strength of SwingSane however, is that all the scans produced in the current session are stored in the preview tab and can be output to the same multi-page PDF (AirSane and Image Capture also permits this). Finally, the file requestor confused me on macOS (more so than on Windows). There is a dropdown for File Format which is blank (why show this?). I was expecting to specify the filename, but this is determined by the scan batch so really the file requestor is asking for a destination folder only. This should be stated in the window title. Furthermore on macOS you cannot save once you have browsed inside a folder – you have to navigate to the parent and select the destination folder without navigating to its contents! This is really not obvious and leads you to suspect the software is broken.
      SwingSane was last updated in April 2015.
    • SaneWinDS (Windows 10 and earlier) – This frontend does not hook into WIA so you will have to use it for the scan acquisition rather than acquiring from inside applications. It does a good job of presenting the available options, and will send the scans directly to the default application for the destination file type. There is no driver component – it’s just a software application so it works fine even on Windows 10.
      Author Alec Skelly last updated SaneWinDS in April 2015.
     

    Notes

    • The package can be stopped and started in Package Center but really this is to launch and provide the log output of sane-find-scanner and scanimage -L in the easiest way for non-technical users. saned uses the inetd super-server daemon so it is only loaded and invoked when a SANE frontend makes contact on port 6566. This means that really there is no performance nor memory penalty for leaving the package running all the time, even on very resource limited systems.
    • Unfortunately Synology decided to remove the ability to view package log files via the DSM 6.2 GUI and they’ve provided no information in the Developer Guide on how to integrate with the new Log Center apps. I lack the motivation to reverse engineer functionality the company significantly alters with each DSM release, so troubleshooting this package does now require some familiarity with SSH or SCP. The package log file is /var/packages/sane-backends/target/var/sane-find-scanner.log
    • Now that I have built the package with libusb 1.0 rather than using DSM’s version 0.1, it does automatically detect scanners that have been hot-plugged.
    • By default access is granted to SANE frontends originating from any IP address (0.0.0.0/0 and ::/0 for IPv6). This can be restricted by modifying /var/packages/sane-backends/target/etc/sane.d/saned.conf, or by configuring the DSM Firewall.
    • By default connections to the SANE backends do not require credentials. If you would like to secure devices, create the text file /var/packages/sane-backends/target/etc/sane.d/saned.users, specifying credentials in the format “user:password:backend”, e.g.:
      swingsane:fqkg3h328rge:plustek
    • The DSM 6.0 toolchains provide pre-built development libraries for certain components such as avahi and dbus which are complex to build. Although I did not build sane-backends with support for avahi (due to stability issues), these libraries are needed by the AirSane package hence the new requirement for DSM 6.0 at a minimum. Some much older macOS SANE frontends make the assumption that avahi will be used and so do not allow you to statically define a target IP address, so they cannot be used with this package.
    • Although most of the library search path behaviour can be controlled at compilation time, unfortunately the backend drivers are searched for using a static path, and sane-backends insists on saving its configuration in a static location. I am always careful that my packages do not damage the system they are installed on so I have kept all of this contained within /var/packages/sane-backends/target by cross-compiling in this same location on my development Linux VM. My build steps are documented on GitHub.
     

    Package scripts

    For information, here are the package scripts so you can see what it’s going to do. You can get more information about how packages work by reading the Synology 3rd Party Developer Guide.

    installer.sh

    #!/bin/sh
    
    #--------SANE Backends installer script
    #--------package maintained at pcloadletter.co.uk
    
    
    SYNO_CPU_ARCH="`uname -m`"
    [ "${SYNOPKG_DSM_ARCH}" == "comcerto2k" ] && SYNO_CPU_ARCH="armneon"
    [ "${SYNOPKG_DSM_ARCH}" == "armada375" ] && SYNO_CPU_ARCH="armneon"
    [ "${SYNOPKG_DSM_ARCH}" == "armada38x" ] && SYNO_CPU_ARCH="armneon"
    [ "${SYNOPKG_DSM_ARCH}" == "alpine" ] && SYNO_CPU_ARCH="armneon"
    [ "${SYNOPKG_DSM_ARCH}" == "alpine4k" ] && SYNO_CPU_ARCH="armneon"
    [ "${SYNOPKG_DSM_ARCH}" == "monaco" ] && SYNO_CPU_ARCH="armneon"
    NATIVE_BINS_URL="https://syno.pcloadletter.co.uk/bin/sane1.0.28-native-${SYNO_CPU_ARCH}.tar.xz"   
    NATIVE_BINS_FILE="`echo ${NATIVE_BINS_URL} | sed -r "s%^.*/(.*)%\1%"`"
    INSTALL_FILES="${NATIVE_BINS_URL}"
    COMMENT="# Synology SANE Backends Package"
    TEMP_FOLDER="`find / -maxdepth 2 -path '/volume?/@tmp' | head -n 1`"
    PUBLIC_FOLDER="`synoshare --get public | sed -r "/Path/!d;s/^.*\[(.*)\].*$/\1/"`"
    source /etc/profile
    
    
    preinst ()
    {
      cd ${TEMP_FOLDER}
      for WGET_URL in ${INSTALL_FILES}
      do
        WGET_FILENAME="`echo ${WGET_URL} | sed -r "s%^.*/(.*)%\1%"`"
        [ -f ${TEMP_FOLDER}/${WGET_FILENAME} ] && rm ${TEMP_FOLDER}/${WGET_FILENAME}
        wget ${WGET_URL}
        if [ $? != 0 ]; then
          if [ -d ${PUBLIC_FOLDER} ] && [ -f ${PUBLIC_FOLDER}/${WGET_FILENAME} ]; then
            cp ${PUBLIC_FOLDER}/${WGET_FILENAME} ${TEMP_FOLDER}
          else
            echo "There was a problem downloading ${WGET_FILENAME} from the official download link, " >> $SYNOPKG_TEMP_LOGFILE
            echo "which was \"${WGET_URL}\" " >> $SYNOPKG_TEMP_LOGFILE
            echo "Alternatively, you may download this file manually and place it in the 'public' shared folder. " >> $SYNOPKG_TEMP_LOGFILE
            exit 1
          fi
        fi
      done
    
      exit 0
    }
    
    
    postinst ()
    {
      #extract CPU-specific binaries
      cd ${SYNOPKG_PKGDEST}
      tar xJf ${TEMP_FOLDER}/${NATIVE_BINS_FILE} && rm ${TEMP_FOLDER}/${NATIVE_BINS_FILE}
    
      #allow access to saned by default (this can be restricted by IP/subnet)
      echo 0.0.0.0/0 >> /var/packages/${SYNOPKG_PKGNAME}/target/etc/sane.d/saned.conf
      echo ::/0 >> /var/packages/${SYNOPKG_PKGNAME}/target/etc/sane.d/saned.conf
    
      #add firewall config
      /usr/syno/bin/servicetool --install-configure-file --package /var/packages/${SYNOPKG_PKGNAME}/conf/${SYNOPKG_PKGNAME}.sc > /dev/null
    
      exit 0
    }
    
    
    preuninst ()
    {
      `dirname $0`/stop-start-status stop
    
      exit 0
    }
    
    
    postuninst ()
    {
      #remove system configuration changes
      sed -i "/${COMMENT}/d" /etc/services
      sed -i "/${COMMENT}/d" /etc/inetd.conf
    
      #remove firewall config
      if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
        /usr/syno/bin/servicetool --remove-configure-file --package ${SYNOPKG_PKGNAME}.sc > /dev/null
      fi
    
      exit 0
    }
    
    
    preupgrade ()
    {
      `dirname $0`/stop-start-status stop
    
      exit 0
    }
    
    
    postupgrade ()
    {
      exit 0
    }
    
     

    start-stop-status.sh

    #!/bin/sh
    
    #--------SANE Backends start-stop-status script
    #--------package maintained at pcloadletter.co.uk
    
    PKG_FOLDER="/var/packages/sane-backends"
    DLOG="${PKG_FOLDER}/target/var/sane-find-scanner.log"
    COMMENT="# Synology SANE Backends Package"
    source /etc/profile
    source /root/.profile
    
    
    EnvCheck ()
    #updates to DSM will reset these changes so check them each startup
    {
      #/etc/services should contain 1 line added by this package tagged with trailing comments
      COUNT=`grep -c "${COMMENT}$" /etc/services`
      if [ $COUNT != 1 ]; then
    
        #remove any existing mods
        sed -i "/${COMMENT}/d" /etc/services
    
        #make the required changes
        echo "sane-port       6566/tcp                        ${COMMENT}" >> /etc/services
      fi
      #/etc/inetd.conf should contain 1 line added by this package tagged with trailing comments
      COUNT=`grep -c "${COMMENT}$" /etc/inetd.conf`
      if [ $COUNT != 1 ]; then
    
        #remove any existing mods
        sed -i "/${COMMENT}/d" /etc/inetd.conf
    
        #make the required changes      
        echo "sane-port stream tcp    nowait  root    ${PKG_FOLDER}/target/sbin/saned    saned  ${COMMENT}" >> /etc/inetd.conf
      fi
      #/usr/syno/etc/synoservice.d/pkgctl-sane-backends.cfg should contain an upstart entry for inetd
      COUNT=`grep -c "inetd" /usr/syno/etc/synoservice.d/pkgctl-sane-backends.cfg`
      if [ $COUNT != 1 ]; then
        sed -i -r "s/(\"pkgctl-sane-backends\")/\1,\"inetd\"/" /usr/syno/etc/synoservice.d/pkgctl-sane-backends.cfg
      fi
    }
    
    case $1 in
      start)
        EnvCheck
        reload inetd
        echo `date "+%F %R"` startup. `${PKG_FOLDER}/target/bin/sane-find-scanner -q` > ${PKG_FOLDER}/target/var/sane-find-scanner.log
        echo `date "+%F %R"` `${PKG_FOLDER}/target/bin/scanimage -L` >> ${PKG_FOLDER}/target/var/sane-find-scanner.log
        exit 0
      ;;
    
      stop)
        #remove any existing config changes
        sed -i "/${COMMENT}/d" /etc/services
        sed -i "/${COMMENT}/d" /etc/inetd.conf
        killall -q saned
        reload inetd
        exit 0
      ;;
    
      status)
        grep -q "${COMMENT}" /etc/inetd.conf && exit 0 || exit 1
      ;;
    
      log)
        echo "${DLOG}"
        exit 0
      ;;
    
    esac
    
     

    Changelog:

    • 0003 15/Sep/19 – Updated to SANE 1.0.28 and libusb 1.0.23 (DSM still uses libusb 0.1), fixed inetd start issue, allowed connections on IPv6 interfaces by default, added support for new Synology product models, added aarch64 build for 64bit ARM CPUs, published a separate package AirSane to automatically present SANE scanners to the macOS Image Capture application, updated the section on frontends in this page. Old package version available here for DSM 5.0 users.
    • 0002 20/Jul/16 – Added support for Marvell Armada 385 SoC
    • 0001 16/Dec/15 – Initial public release
     
     
    Advertisements