SANE
SANE (Scanner Access Now Easy) 提供了在 GNU/Linux 下使用扫描仪的库和命令行工具。
安装[编辑 | 编辑源代码]
安装 sane包 软件包。无论如何,大多数前端和驱动程序都会将其作为依赖项,因此通常无需明确安装。
扫描仪驱动[编辑 | 编辑源代码]
许多现代扫描仪都支持"无驱动"扫描。[1] 您可以在 sane-airscan GitHub 或 Apple AirPrint devices 上查找设备的兼容性。
如果扫描仪已知可以在"无驱动"模式下工作,则安装 {sane-aircan包软件包。如果扫描仪使用 USB,还需安装 ipp-usb包 软件包并启动/启用 ipp-usb.service
以便通过 USB 连接使用 IPP 协议。
否则,请检查 SANE - 支持的设备 和 SANE/扫描仪特定问题,查看您的扫描仪是否可以使用不同的驱动程序。
大多数扫描仪开箱即可使用。如果您的扫描仪不能正常工作,请参阅 SANE/扫描仪特定问题获取安装说明。
前端[编辑 | 编辑源代码]
SANE 有许多前端,不完全列表可在 SANE 项目网站 上找到。
- GNOME Document Scanner — 简化的图形用户界面,与 XSane 相比更易于使用,并能更好地集成到 GNOME 桌面中。属于 gnome包组 的一部分。
- Skanlite — 简单的图像扫描应用程序,基于 KSane 后端,只需扫描和保存图像。是 kde-graphics包组 的一部分。
- Skanpage — 一款简单的扫描应用程序,用于多页扫描并保存文档和图像。属于 kde-utilities包组 的一部分。
- XSane — 基于 GTK 的全功能前端,看起来有点老旧,但可提供扩展功能。
- http://www.xsane.org/ || xsaneAUR
- Scantailor — 一款扫描应用程序,可与项目协同工作,并允许在扫描过程中进行实时编辑。
Some OCR software can scan images using SANE: gImageReader, gscan2pdf, Linux-Intelligent-Ocr-Solution, OCRFeeder, Paperwork.
- 使用 XSane 在 16 位色深模式下直接扫描为 PDF 时,已知会生成 已损坏文件,
pacman
输出中的注释对此提出了警告。已知 8 位模式可以正常工作。
- 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[编辑 | 编辑源代码]
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][失效链接 2024-07-30 ⓘ] 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).
scanimage -L
on the server to see the scanner url.Accessing your scanner from a remote workstation[编辑 | 编辑源代码]
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).
Troubleshooting[编辑 | 编辑源代码]
See also SANE/Scanner-specific problems.
Invalid argument[编辑 | 编辑源代码]
If you get an "Invalid argument" error with xsane or another sane front-end, this could be caused by one of the following reasons:
Missing firmware file[编辑 | 编辑源代码]
No firmware file was provided for the used scanner (see #Firmware for details).
Wrong firmware file permissions[编辑 | 编辑源代码]
The permissions for the used firmware file are wrong. Correct them using
# chown root:scanner /usr/share/sane/SCANNER_MODEL/FIRMWARE_FILE # chmod ug+r /usr/share/sane/SCANNER_MODEL/FIRMWARE_FILE
Multiple backends claim scanner[编辑 | 编辑源代码]
It may happen, that multiple backends support (or pretend to support) your scanner, and sane chooses one that does not do after all (the scanner will not be displayed by scanimage -L
then). This has happened with older Epson scanners and the epson2
resp. epson
backends. In this case, the solution is to comment out the unwanted backend in /etc/sane.d/dll.conf
. In the Epson case, that would be to comment out epson2:
/etc/sane.d/dll.conf
#epson2 epson
It may also be possible that the independent iscanAUR epkowa
backend interferes with your snapscan
backend (epson scanners). You may get this error right after using the scanimage -L
command. Starting the scanner app (like xsaneAUR) twice can also solve the problem. Otherwise check your /etc/sane.d/epkowa.conf
for wrong configurations or remove the iscanAUR package.
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 here[失效链接 2023-05-06 ⓘ] and here (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.
Firewall[编辑 | 编辑源代码]
When network scanning scanner hangs, then invalid argument error occured.
saned uses data port range, so you must enable connections to 6566/tcp and data_portrange from /etc/sane.d/saned.conf or use conntrack firewall module for sane to enable data ports as described above.
Slow startup[编辑 | 编辑源代码]
If you encounter slow startup issue (e.g. xsane
or scanimage -L
does not return results nearly instantly), one of the drivers you do not use may be the culprit.
You can resolve this by editing /etc/sane.d/dll.conf
and commenting out the scanner drivers you do not use. You can use scanimage -L
to determine which drivers you need:
$ 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
The parts between the `
and the :
in the output indicate the driver for the device. For example, if only want to use the Brother scanner and not the webcam or the generic scanner driver, you can comment out everything but the brother4
driver in /etc/sane.d/dll.conf
.
Device busy[编辑 | 编辑源代码]
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 中,scanner
和 lp
组已被弃用。无需将用户添加到这些组中。详见用户和用户组#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"
保存文件,拔出并重新插入扫描仪,此时文件权限应该正确无误。
另一个小窍门是可以在后台文件中添加设备(扫描仪):
在 /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[编辑 | 编辑源代码]
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
Then restart the saned
daemon.
Error during device I/O[编辑 | 编辑源代码]
If you are getting SANE: Error during device I/O (code=9)
while trying to scan using an HP scanner, make sure you have hplip-pluginAUR installed (see CUPS/打印机特定问题#HP).
See also[编辑 | 编辑源代码]
- Wikipedia:WS-Discovery, Microsoft's "driverless" protocol