Reputation: 31
I'm using an HP PSC 1610 All-in-One printer to scan images on a Raspberry Pi 3 A+ (512MB RAM) with scanimage. Scanning works well at lower resolutions (100 and 200 dpi), but when the resolution is higher than 300 dpi, the scanning process begins but then suddenly stops with the error scanimage: sane_read: Error during device I/O.
Initially, I though this error was related to a timeout, as scanning at 600 dpi proceeds further than with 1200. However, now I guess it must be a memory error because I tried setting export SANE_TIMEOUT=30000
and then creating a hpaio.conf file with the dumb-read
and connection-timeout
properties set. Nothing changes
I tried creating more swap, but it doesn't seem to make much of a difference.
I tried scanning with hp-scan
(after installing hplip
) and with pyinsane2
-- nothing changes.
I also tried to change the buffer size (on scanimage --buffer-size) and still nothing happens.
Does anyone know how to work around this problem? Or am I really stuck with the low resolution?
Edit 1 - incoming suggestions are:
free -h
outputs that there are 230Mb of free RAM. Is this normal considering that I don't even have a DE on the Pi?I appreciate any help
Upvotes: 2
Views: 193
Reputation: 31
Edit in the end solves, with some tricks, the scanimage
command
After a couple of days I found a "solution" to this problem; or rather, a temporary solution. And it's quite unexpected...
On my Raspberry Pi, I tried changing the SD card (to a 32 GB one) to create more swap. Still the scanner wouldn't complete the job. I also tried scanning the image in parts, but it took very long.
Then, for the sake of testing/making sure I wasn't missing anything, I tested xsane
. And... it worked!? I still can't figure out why exactly does xsane, running on a GUI (standard raspberry pi desktop), would work, while scanimage
on the command line (without a DE) won't. My best guess is that xsane has a lower level access to the sane-backend
and better memory management, so that the program itself, when necessary, scans the image in parts and joining them without having to stop the scanner, allowing it to scan the complete image in high resolution within the expected/normal time.
Still, sometimes it fails to complete the job and outputs the I/O error if the cache pressure is too high or the swap is too small. When the cache pressure is about 70% and the system has a swap of 4GB, no errors will happen.
Now, regarding @MarkSetchell's idea of joining the images with various scans, what worried me was that the scanner wouldn't resume the scan from exactly the same place it left off the previous stripe (as the resolution at 1200dpi is approximately 21µm/pixel). However, for those that might need to use this method, worry not as this will not be a problem at all if you configure the stripes to be perpendicular to the direction of movement of the scanner.
It would still be appreciated if someone finds a definitive solution to the command line scanimage method.
Thank you for your help
Edit -- working scanimage
on the commandline
Apparently the desktop environment provide better memory management and/or me changing the cache pressuring properties did make the scanimage
work without throwing the I/O error. The recipe for making scanimage
work is the following:
If you have the light version of raspbian:
-1. sudo apt install xserver-xorg raspberrypi-ui-mods xorg
Note that for some reason, if you set the raspberry pi to automatically log into the desktop environment, the scanning won't work. You need to start it with the default command startx
startx
General instructions (on a terminal window)
Create the swap:
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Set the swappiness (percentage of allowance the system has to transfer data from the RAM to the swap) to 80%:
sudo sysctl vm.swappiness=80
Set a low cache pressure so that the cache persists for longer (~60%). This is probably what keeps the scan going besides the large file size:
sudo sysctl vm.vfs_cache_pressure=60
Edit 2 -- if you still find problems with scanimage
or if it produces inconsistent results (sometimes it will work while others it won't)
If you encounter erros with the device, such as Device Communication error: 5012
, the solution from the post Post 1 and Post 2 will solve them: a) sudo apt remove ipp-usb
and b) sudo apt purge ippusbxd
. Reboot the device.
Continuing from the steps list above:
Disable the swap (yes, you enable it as above and then disable it) sudo swapoff -a
Enable the swap again with sudo swapon -a
sudo sync
sudo su -c "echo 3 > /proc/sys/vm/drop_caches"
Follow steps 1. to 6. again (yes, it is necessary)
export SANE_TIMEOUT=90000000
Use scanimage
Upvotes: 1