跳至內容
出自 Arch Linux 中文维基

SANE (Scanner Access Now Easy) 提供了在 GNU/Linux 下使用掃描儀的庫和命令行工具。

安裝

安裝 sane 軟體包。無論如何,大多數前端和驅動程序都會將其作為依賴項,因此通常無需明確安裝。

掃描儀驅動

許多現代掃描儀都支持"無驅動"掃描。[1] 您可以在 sane-airscan GitHubApple AirPrint devices 上查找設備的兼容性。

如果掃描儀已知可以在"無驅動"模式下工作,則安裝 sane-airscan軟體包。如果掃描儀使用 USB,還需安裝 ipp-usb 軟體包並啟動/啟用 ipp-usb.service 以便通過 USB 連接使用 IPP 協議。

否則,請檢查 SANE - 支持的設備SANE/掃描儀特定問題,查看您的掃描儀是否可以使用不同的驅動程序。

大多數掃描儀開箱即可使用。如果您的掃描儀不能正常工作,請參閱 SANE/掃描儀特定問題獲取安裝說明。

注意:Some drivers, including sane-airscan, use multicast to search for network scanners. See iptables#Allowing multicast traffic to correctly configure your firewall.

前端

SANE 有許多前端,不完全列表可在 SANE 項目網站上找到。

  • GNOME Document Scanner — 簡化的圖形用戶界面,與 XSane 相比更易於使用,並能更好地集成到 GNOME 桌面中。屬於 gnome包組 的一部分。
https://apps.gnome.org/SimpleScan/ || simple-scan
  • Skanlite — 簡單的圖像掃描應用程式,基於 KSane 後端,只需掃描和保存圖像。是 kde-graphics包組 的一部分。
https://apps.kde.org/skanlite/ || skanlite
  • Skanpage — 一款簡單的掃描應用程式,用於多頁掃描並保存文檔和圖像。屬於 kde-utilities包組 的一部分。
https://apps.kde.org/skanpage/ || skanpage
  • XSane — 基於 GTK 的全功能前端,看起來有點老舊,但可提供擴展功能。
http://www.xsane.org/ || xsaneAUR
  • Scantailor — 一款掃描應用程式,可與項目協同工作,並允許在掃描過程中進行實時編輯。
https://github.com/4lex4/scantailor-advanced || scantailor-advanced

Some OCR software can scan images using SANE: gImageReader, gscan2pdf, Linux-Intelligent-Ocr-Solution, OCRFeeder, Paperwork.

注意:
  • 使用 XSane 在 16 位色深模式下直接掃描為 PDF 時,已知會生成 已損壞文件pacman 輸出中的注釋對此提出了警告。已知 8 位模式可以正常工作。

本文或本章節的事實準確性存在爭議。

原因: skanlite does not need to handle mDNS. As long as mDNS hostname resolution is set up correctly and the scanner 's address is specified as hostname.local, it should just work. This looks like a hplip limitation/bug.(在 Talk:SANE 中討論)


  • Using a frontend does not mean you do not have to apply some tricks. This is especially true with devices configured via mDNS. For example, skanlite needs to have additional info specified on the command line in order to detect a network scanner properly as it cannot handle mDNS. Here is an example with an HP Officejet Pro L7590: skanlite --device "hpaio:/net/Officejet_Pro_L7500?ip=192.168.0.17".

Verification

Now you can try to see if sane recognizes your scanner.

$ scanimage -L

If that fails, run the command again as root to check for permission problems. If that fails as well, check that your scanner is plugged into the computer. You also might have to unplug/plug your scanner for /usr/lib/udev/rules.d/65-sane.rules to recognize your scanner.

Now you can see if it actually works

$ scanimage --format=png --output-file test.png --progress

If the scanning fails with the message scanimage: sane_start: Invalid argument you may need to specify the device.

$ scanimage -L
device `v4l:/dev/video0' is a Noname Video WebCam virtual device
device `pixma:04A91749_247936' is a CANON Canon PIXMA MG5200 multi-function peripheral

Then you would need to run

$ scanimage --device "pixma:04A91749_247936" --format=tiff --output-file test.tiff --progress

Sane provides many special backend options for numerous scanner types. To see what these are for your device:

$ scanimage -A

Firmware

注意:This section is only needed if you need to upload firmware to your scanner.

Firmwares usually have the .bin extension.

Firstly you need to put the firmware someplace safe, it is recommended to put it in a subdirectory of /usr/share/sane/.

Then you need to tell sane where the firmware is:

  • Find the name of the backend for your scanner from the sane supported devices list.
  • Open the file /etc/sane.d/backend-name.conf.
  • Make sure the firmware entry is uncommented and let the file-path point to where you put the firmware file for your scanner. Be sure that members of the group scanner can access the /etc/sane.d/backend-name.conf file.

If the backend of your scanner is not part of the sane package (such as hpaio.conf which is part of hplip), you need to uncomment the relevant entry in /etc/sane.d/dll.d or in /etc/sane.d/dll.conf.

Sharing your scanner over a network

You can share your scanner with other hosts on your network who use sane, xsane or xsane-enabled GIMP. To set up the server, first indicate which hosts on your network are allowed access.

Change the /etc/sane.d/saned.conf file to your liking, for example:

# required
localhost
# allow local subnet
192.168.0.0/24

Second, install, start and enable avahi-daemon on your server (if it is not already active) so your scanner can be found by multicast. Or, if your scanner is supported by Airscan installing the sane-airscan package is an alternative.

If you use iptables, insert the nf_conntrack_sane module to let the firewall track saned connections.

Conntrack helper seems to be disabled by default.[2] You can activate it with

# echo 1 > /proc/sys/net/netfilter/nf_conntrack_helper  

To configure this permanently, set the nf_conntrack_helper=1 option for the nf_conntrack module, see Kernel module#Using files in /etc/modprobe.d/.

Now start/enable saned.socket. Your scanner is now available over the network. For more information, see saned(8).

注意:saned intentionally refuses to share scanners that use the net: backend (which includes some USB scanners). There is a crude patch to allow this in FS#54786, but note it may cause problems on some networks. Check output of scanimage -L on the server to see the scanner url.

Accessing your scanner from a remote workstation

這一章節正在考慮移除。

原因: Once a local scanner is shared (above), remote workstations should follow the normal instructions (i.e. Installation's #Scanner_drivers). Static IPs & avahi-daemon should move to that section. (在 Talk:SANE 討論)


注意:Some network scanners require a different approach. See SANE/Scanner-specific problems.

You can access your network-enabled scanner from a remote Arch Linux workstation.

First, specify the server's host name or IP address in the /etc/sane.d/net.conf file:

# static IP address
192.168.0.1
# or host name
stratus

Second, depending on what you configured at the server side, install, start and enable avahi-daemon or install sane-airscan at the remote workstation.

Now test your workstation's connection:

$ scanimage -L

The network scanner should now also show up in some front-ends.

Windows clients

Since the Windows port of SANE seems to be unsupported, outdated and difficult to get, you can try SANEWinDS or SaneTwain (old).

疑難解答

另請參閱 SANE/掃描儀特定問題

參數無效

如果在使用 xsane 或其他 sane 前端時出現"Invalid argument"錯誤,可能是由以下原因造成的:

固件文件缺失

未提供所用掃描儀的固件文件(詳情請參見 #固件 。)

固件文件權限錯誤

所用固件文件的權限有誤。用以下方法更正:

# chown root:scanner /usr/share/sane/SCANNER_MODEL/FIRMWARE_FILE
# chmod ug+r /usr/share/sane/SCANNER_MODEL/FIRMWARE_FILE

Multiple backends claim scanner

可能會出現這樣的情況:多個後端都支持(或假裝支持)您的掃描儀,而 sane 卻選擇了一個最終不支持的後端(此時 scanimage -L 將無法顯示掃描儀)。老式愛普生掃描儀和 epson2 以及 epson 後端就會出現這種情況。在這種情況下,解決辦法是在 /etc/sane.d/dll.conf 中注釋掉不需要的後端。在愛普生案例中,就是注釋掉 epson2:

/etc/sane.d/dll.conf
#epson2
epson

也有可能是獨立的 iscanAUR epkowa 後端與 snapscan 後端(愛普生掃描儀)相互干擾。使用 scanimage -L 命令後,可能會立即出現此錯誤。啟動掃描儀應用程式(如 xsaneAUR)兩次也能解決問題。否則,請檢查 /etc/sane.d/epkowa.conf 是否存在錯誤配置,或刪除 iscanAUR 軟體包。

Communication via xHCI not working (older scanner models)

Some older scanner models do not work when connected via an USB3 port. If you experience this issue, try setting the SANE_USB_WORKAROUND=1 environment variable before starting your frontend.[3][4]

If that does not work, try one of the following workarounds:

  • Use an USB2 port instead of an USB3 port, if available.
  • Disable xHCI via BIOS/EFI. eHCI will consequently be used and communication with the scanner will work. On the downside, USB3 speed can not be reached on any port.
  • On (some) intel chipsets the setpci command can be used to route specific usb ports to either the xHCI or the eHCI controller. See force-a-single-usb-3-0-port-to-work-as-usb-2-0 (scroll down to where it says "setpci") for further information. With this it is possible to toggle single USB ports with a simple shell script.
  • Connect the scanner over the network instead if it is supported.

防火牆

當網絡掃描掃描儀掛起時,會出現無效參數錯誤。

saned 使用數據埠範圍,因此必須在 /etc/sane.d/saned.conf 中啟用與 6566/tcp 和 data_portrange 的連接,或如上所述使用 sane 的 conntrack 防火牆模塊啟用數據埠。

啟動緩慢

如果遇到啟動緩慢的問題(例如,xsanescanimage -L 無法立即返回結果),可能是其中一個未使用的驅動程序造成的。

您可以通過編輯 /etc/sane.d/dll.conf 並注釋掉不使用的掃描儀驅動程序來解決這一問題。您可以使用 scanimage -L 來確定需要哪些驅動程序:

$ scanimage -L
device `brother4:net1;dev0' is a Brother DCP-L2550DW
device `v4l:/dev/video0' is a Noname Logitech Webcam C925e virtual device
device `escl:http://192.168.1.2:80' is a Brother DCP-L2550DW series adf,platen scanner

輸出中 `:} 之間的部分表示設備的驅動程序。例如,如果只想使用 Brother 掃描儀,而不想使用 webcam 或通用掃描儀驅動程序,則可以在 /etc/sane.d/dll.conf 中注釋掉除 brother4 驅動程序之外的所有內容。

設備忙

本文或本章節的事實準確性存在爭議。

原因: 用戶不需要在掃描儀組中(請參閱用戶和用戶組#預 systemd 組)。(在 Talk:SANE 中討論)


If your USB device is listed with scanimage -L but launching the test scanimage pixma:04A9173E_11DAD1 --format=tiff --output-file test.tiff always return the 'Device busy' error, you might try to add your username to the scanner group usermod -a -G scanner yourusername then blacklist the usblp kernel module by writing blacklist usblp in /etc/modprobe.d/no-usblp.conf (it prevents usblp from loading to support scanning, not needed by xsane and related tools, might also conflict with CUPS). Reboot to finish. [5]

In addition to this, some Cannon printers return "device busy" if the scan mode is set to "Computer". Setting this to the "Remote Scanner" mode should fix the issue.[6]

權限問題

在 systemd 中,scannerlp 組已被棄用。無需將用戶添加到這些組中。詳見用戶和用戶組#systemd 之前的群組

你也可以嘗試更改 USB 設備的權限,但不建議這樣做,更好的辦法是修復 Udev 規則,使掃描儀能夠被識別。

首先使用 lsusb 檢查已連接的 USB 設備:

Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 003: ID 04d9:1603 Holtek Semiconductor, Inc.
Bus 003 Device 002: ID 04fc:0538 Sunplus Technology Co., Ltd
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 006: ID 03f0:2504 Hewlett-Packard
Bus 001 Device 002: ID 046d:0802 Logitech, Inc. Webcam C200
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In our example we see the scanner: Bus 001 Device 006: ID 03f0:2504 Hewlett-Packard. Here 03f0 is the vendorID and 2504 is the productID.

Alternatively, running sane-find-scanner with root permission will also give you the same vendorID and productID.

Now open /usr/lib/udev/rules.d/65-sane.rules and see if there is there is a line with the vendorID and productID of your scanner. If there is not any, create the new file /etc/udev/rules.d/65-sane-missing-scanner.rules, with the following contents:

ATTRS{idVendor}=="vendorID", ATTRS{idProduct}=="productID", MODE="0664", GROUP="lp", ENV{libsane_matched}="yes"

保存文件,拔出並重新插入掃描儀,此時文件權限應該正確無誤。

本文或本章節的事實準確性存在爭議。

原因: 掃描儀需要添加到正確的後端文件中,hp4200.conf 不適用於任何掃描儀。(在 Talk:SANE 中討論)


另一個小竅門是可以在後台文件中添加設備(掃描儀):

/etc/sane.d/hp4200.conf 中添加 usb 0x03f0 0x2504 ,使其看起來像這樣:

#
# Configuration file for the hp4200 backend
#
#
# HP4200
#usb 0x03f0 0x0105
usb 0x03f0 0x2504

Parallel port scanners

All devices attached to a parallel port are assumed to be printers, and are given a lp group. Either create a udev rule to mark the relevant parallel port as libsane_matched, or add your user to the lp user group. CUPS also uses the lp group for read-only access to configuration files, so there are potential security implications to adding users to the lp group - see CUPS#Connection interfaces for more information.

avahi-daemon is not mandatory

本文或本章節的語言、語法或風格需要改進。參考:幫助:風格

原因:這是配置,不是疑難解答。(在Talk:SANE討論)

Some scanner applications may require you to start the avahi-daemon upon startup. This is actually the cause of SANE. If for some reason you do not want to enable the avahi-daemon service because you use a wired scanner or do not need it because your scanner's driver supports networking already on setup, then comment out the net backend in the SANE configuration:

/etc/sane.d/dll.conf
# The next line enables the network backend; comment it out if you do not
# need to use a remote SANE scanner over the network -- see sane-net(5)
# and saned(8) for details.
#net

然後重啟 saned 守護進程。

設備輸入/輸出時出錯

如果您在嘗試使用惠普掃描儀掃描時收到 SANE: Error during device I/O (code=9),請確保您安裝了 hplip-pluginAUR (請參閱 CUPS/印表機特定問題#HP)。

See also