SULDR Forums Supported Printers Printing Questions Scanning Questions General Questions Samsung Installer

Scan to PC in Linux (Development)

Started by angelnu, December 20, 2012, 07:00:41

Previous topic - Next topic

angelnu

Hi,

I wanted to make usage of the "scan to PC" option of my Samsung CLX 3300 in order to save documents to my local Linux server. This way I would not have to turn on the computer just to trigger the scan.

Unfortunately the Samsung Unified Linux Driver does not support this feature so I created my own implementation after doing a reverse engineering of the messages sent by the windows version. My implementation uses python and sane and allows defining several configuration setups. The code is still very primitive (I just finished getting it working) so the following things are missing:

* PDFs and TIFFs get a file/page, even if you select M_PDF or M_TIFF
* create debian package
* add image enhancements (the Python PIL include several but I did not try them yet)

Enjoy and let me know if it works for you or you have patches to improve it.

bchemnet

Thanks for sharing.  If this proves of interest to others, and any configuration is moved out of the script itself into a config file, I could probably package and distribute it.

angelnu

All the configuration is at the begining of the script so it would be easy to move it to an extra file under /etc. Any preferences?

The script would also need an upstart config file and, potentially, a logrotate one as well.

At the moment what it is anoying me is that Sane is slow with the Samsung devices conpared to scanning from Windows: it takes 45 second to scan a page in "Grayscale - 256 Levels" and 300 dpis while Windows or scanning to a USB memory plugged into the scanner only takes 15. My theory based on the number and size of the packages in my network capture is that the Windows driver is able to tell the scanner to scan and transfer the image already compressed in JPEG format. In Sane I only found support for PNM and TIFF...

bchemnet

Quote from: angelnu on December 20, 2012, 16:06:05
All the configuration is at the begining of the script so it would be easy to move it to an extra file under /etc. Any preferences?
No, anything uniquely identifying works for me.

Quote from: angelnu on December 20, 2012, 16:06:05The script would also need an upstart config file and, potentially, a logrotate one as well.
For compatibility, I use old-style init scripts for packages that need them; that way they can be used with any of the various startup routines, and upstart (or whatever) can deal with it on the fly.  This is simple for me to implement.  I haven't looked at your script closely enough to see if it is generating enough output to justify a logrotate, but feel free to include that if you think it might be necessary.

I am unlikely to do anything with packaging for at least the next two weeks, although I hope to spend some time on it at some point in January.  (I'm really hoping Samsung releases a new driver right before then, but they seem to have a habit of doing that right after I go through an update round.)  So from my point of view, there is no urgency on this.

Quote from: angelnu on December 20, 2012, 16:06:05At the moment what it is anoying me is that Sane is slow with the Samsung devices conpared to scanning from Windows: it takes 45 second to scan a page in "Grayscale - 256 Levels" and 300 dpis while Windows or scanning to a USB memory plugged into the scanner only takes 15. My theory based on the number and size of the packages in my network capture is that the Windows driver is able to tell the scanner to scan and transfer the image already compressed in JPEG format. In Sane I only found support for PNM and TIFF...
I suspect you are correct.  Personally I find that to be no loss, as I much prefer to take the time/storage penalty at the front end and decide later whether the compression is necessary/worthwhile.  I'm probably in a minority, though, and it also doesn't really matter since I personally have no use for this script (no scanner on my printer).  I doubt there is an easy solution to that, unless there is a physical printer configuration option to default to jpeg output.

Of course, it may also just be that the Windows driver is faster or more efficient in its transfer protocol.  That would hardly be surprising given the massive investment in Windows support Samsung has compared to Linux.

angelnu

I found a few hours today to finish a new version of the script to be include in a package:

- binary file in /opt/Samsung/mfp/bin/scannerServer.py
- config file in /etc/samsungScannerServer.conf (can be changed in scannerServer.py)
- log file in /var/log/samsungScannerServer.log (defined in samsungScannerServer.conf)
- use python logrotate
- /etc/init.d/samsungScannerServer
- support to create PDFs of multiple pages
- DPI settings working for JPEG and PDF files
- support for image filters in the config file (see example in samsungScannerServer.conf)

How to use:
- extract content of the tarball to your root file system
- modify the settings at /etc/samsungScannerServer.conf
- reboot or run "sudo service samsungScannerServer start"

bchemnet

I will package this up and add it to the repository, sometime in the near future.

tuomis

I've started the server, with no Errors, but when i've checked the log file saw the errors. Could you, please check the attached log file, to help me fix this.

bchemnet

Quote from: tuomis on February 27, 2013, 04:23:23
I've started the server, with no Errors, but when i've checked the log file saw the errors. Could you, please check the attached log file, to help me fix this.

No log file was attached.

totally-king

@bchemnet: Have you already packaged this and added it to the repository? What would be the package name?

bchemnet

Quote from: totally-king on March 08, 2013, 17:06:26
@bchemnet: Have you already packaged this and added it to the repository? What would be the package name?

Not yet, my to-do-immediately list hasn't cleared enough for to spend time on it yet.  But you can still use the attachment in this thread.

totally-king

OK, I installed it, configured it and it (kind of) works with the CLX-3305W over WiFi! (Only the first page is scanned, and sometimes the server needs to be restarted, maybe more details in a later post.)

But for all other interested people who want to install this in ubuntu you need the following packages for the scan server to work (tested with quantal):

sudo apt-get install python-imaging-sane python-pypdf python-pysnmp-common

totally-king

Quote from: angelnu on December 30, 2012, 18:29:29
How to use:
[...]
- reboot or run "sudo service samsungScannerServer start"
For other users to know: Being started on system boot is not the default behaviour.

If you want the server to be registered for automatic start up on system boot, run:
sudo update-rc.d samsungScannerServer defaults
And if you want to unregister it:
sudo update-rc.d -f samsungScannerServer remove

totally-king

#12
Ok, I now post a new version 0.2.2 with a few bug fixes and enhancements by me. For me this is still not working correctly, I can only scan one image and then have to wait around 5 minutes to do the next without restart of the server. But I still wanted to post this (as I think cleaner) version, since those problems might be device related. (The original author angelnu has a CLX-3300, I work with a CLX-3305W with updated firmware V3.00.01.18 as of 01/16/2013.)

All you need is in the attachments. To install the server first install needed packages:
Quote from: totally-king on March 09, 2013, 08:13:36
sudo apt-get install python-imaging-sane python-pypdf python-pysnmp-common
After you downloaded the attached files into one directory, run the following from there:

bash installSSS.sh samsungScannerServer_v022.tgz

and answer Yes to continue with default settings (nothing to be overwritten during 1st time install).

Start the server with:

sudo service samsungScannerService start # or stop or restart


Quote from: totally-king on March 11, 2013, 11:28:42
If you want the server to be registered for automatic start up on system boot, run:
sudo update-rc.d samsungScannerServer defaults
And if you want to unregister it:
sudo update-rc.d -f samsungScannerServer remove

Read the changelog, if you wanna know what's new (and inspect the code if you like) and have fun. ;)

EDIT: In the changelog I meant uid 1000 (!not 100!).
EDIT: The installSSS.sh script is not the correct one (it is for a GUI package, sry my bad!) just use the script in the next post.

totally-king

#13
I finally got it to work! It seems in the SANE backend for the CLX-3305W multi-page scanning is not implemented. That's why I wrote a TCP (and UDP) proxy that interferes with these messages as a man in the middle and recreates what the Samsung Windows server is doing. (Yet more reverse enginerring ... :| ) In the attached deb package this new method is disabled by default (you can enable it by editing `/etc/samsungScannerServer.conf`).

So, deb packages should install and work out of the box. The GUI package is an application indicator for ubuntu that provides status messages and easy clicks to restart / stop the server app. (Helpful if you don't run this on a server but your desktop PC or notebook.) Changelogs are included in the deb packages.

I provided the installSSS.sh script is for use with the tarball in the previous post (since the old script was broken) for historical reasons. But you should use this version, since it does not break any functionality!

EDIT: GUI deb file in next post. Misclicked, sry ... am a little tired. Just ignore the tar.gz file.

totally-king

deb file for GUI (ubuntu application indicator)

bchemnet

When I finally get to this, I'll include all the changes you've made into the repository.

totally-king

Nice, thank you! I hope it isn't too much trouble for you. Only (review? and) sign the packages and add them to the repo or am I thinking too simple? If you need anything else just tell me.

On another note: Fixed dependency issues with python-pysnmp* on ubuntu quantal (12.10), tested before only on precise (12.04): new version attached.

bchemnet

An update: with all the other repository changes I have just finished making, I have not yet had time to deal with this package.  I will have to make some minor changes to align it with the new structure I'm using for the other packages, but it looks like no big deal.  I'll post when they are available, certainly within the next few days.

bchemnet

Here's a pass at repackaging.  Since I can't actually test that they completely work, I'm posting here first for testing.  Please let me know whether or not these packages are fully functional.  Once confirmed, I will add to the repository.

Changes:
Dependencies:
I could not determine any explicit reason to depend on the Configurator instead of just the driver, so I modified that dependency to the driver.
GUI depends on sudo.
Other names updated to match new format.

Naming/location:
Names use suld- instead of samsungmfp-.
Program names more consistently use "samsungScannerServer" style instead of that mixed with "scannerServer" (I think I fixed the necessary references in config files, the desktop file, and the python scripts).
Files moved from /opt/ to /bin/.

Init scripts:
Standard Debian handling of init scripts for scantopc with postinst/prerm/postinst scripts.

angelnu

#19
Thanks totally-king and bchemnet! Sorry for following this thread: I assume I forgot to subscribe for updates...

I added a few fixes/functions (please see attached version 0.3.2):
# - Allow saving files outside ~
# - Check scanner connection at start
# - Small problem at program clean-up when MODIFIED_SANE is not used

I sucessfully tested the package with the samsung drivers 4.1 and 4.0.39  on Ubuntu 12.10 64 bits :-) but python gets a segmentation fault on 13.04 in the PIL library :-( It seems that other PIL users are also affected so hopefully it gets fixed soon. I tried to run the code on Python 3 (after using the 2to3 conversion tool) but Sane and PIL are not available.

bchemnet

Thanks.  I'll incorporate this into the package and plan to release this weekend.

PIL has not had a release in 4 years, and it's not clear when or if there will be another.  Debian experimental has the pillow (PIL fork) versions of the packages that theoretically support python 3, and/or may solve the segmentation fault problems in 13.04, should you feel like trying those packages.

angelnu

Thanks bchemnet! I am giving it a try now. If the replacement fixes the problem I will upload a newer version. I should also be able to make the code compatible with python3.

angelnu

#22
The problem in Ubuntu Raring came actually with the switch to Pyllow. There the PDF plugin is broken due to a new feature added to the JPEG plugin.

I opened a bug at pyllow: https://github.com/python-imaging/Pillow/issues/215

Until this is fixed, the save to PDF in the scanner will be broken. I could try a circumvention or save the JPEG files and call an external tool to do the conversion if this is not fixed soon but I will give the Pyllow team a chance :-)

Update: I fixed the Pillow issue upstream so now we just have to wait for it be picked into the distros. Until this is done I included a circumvention for Pillow 2.0.0.

Bonus: the code is now Python 3 ready. I could not completly test it since some dependencies are not available for python3 yet.

bchemnet

Am I correct in assuming that the 0.4.0 version is still compatible with Python 2.7?

If so, I can go ahead and put together a package based on this.  When the revised pillow reaches distributions (probably with the 13.10 release for Ubuntu), a package can be released without your current workaround.  And when the remaining dependencies are available for python 3, a python 3 version can be released.

Does all that sound like I'm correctly understanding the situation?

angelnu

#24
Yes, the package has to (and does) run on Python 2.7 until the python3 dependencies are solved.

My circumvention only activates with Pillow 2.0.0 so there is no rush to remove it: it should dissable automatically if anything than Pillow 2.0.0 is used.

For 13.10 I will give it again a try to get it running on Python 3. The code should be prepared so hopefully just a test and we can switch.

Btw: I noticied that the service did not start automatically after a reboot. The reason is that in computer the network is actually configured after login (from the networkconfiguration applet). I will try to add a version that keeps periodically retrying when the network is down.

Update: I added retries every 30 seconds until the scanner can be contacted. I also updated the init.d script according to http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/facilname.html

Hopefully now this is the stable version :-) Waiting for your package.

bchemnet

The package is up.  Let me know of any issues and/or updates.

angelnu

Thanks bchemnet,

I received the update automatically from your repository since I had already your beta version.

One small issue: the package update just start the service instead of doing a restart. So after the upgrade the old daemon keeps running.

Another problem I found is that at least with my scanner I have to use suld-driver-4.00.39. With suld-driver-4.01.17 the multi-page scan does not work: the scanner does not use the document feeder and instead just scans the page inside the scanner.

bchemnet

Quote from: angelnu on May 18, 2013, 08:41:48
One small issue: the package update just start the service instead of doing a restart. So after the upgrade the old daemon keeps running.

I'll fix that.

Quote from: angelnu on May 18, 2013, 08:41:48
Another problem I found is that at least with my scanner I have to use suld-driver-4.00.39. With suld-driver-4.01.17 the multi-page scan does not work: the scanner does not use the document feeder and instead just scans the page inside the scanner.

If all the driver versions worked correctly, I would not need to package 7 versions....  But 4.01.17 in particular involved lots of changes, so I'm not entirely surprised it appears to quite full of bugs.  It's particularly unfortunate that I cannot even do basic testing on it because of Samsung's decision to drop support for my printer.  My general policy when they make major changes like that is to wait for the second version before I package, but in this case there doesn't seem to be a second version coming any time soon and there are several printers that otherwise would have no working driver.

angelnu

Thanks for continuing your work even if it does not benefice you directly any longer!

Should we expect new releases of the 4.0 version? I will stay on it until there is a newer release of the 4.1 version since multiscan is pretty valuable for me.

If I find some time I will see if I can reproduce the problem just with pure sane to discard Pillow problems but I am quite convinced that this time the Bug is in the Samsung driver and not in Sane/Python. With MORE time, maybe reverse-engineering the scan protocol would be the best solution: it is also bad transfering RAW images from a scanner that can transfer JPEGs directly...

bchemnet

I don't expect Samsung to release any further 4.00.xx driver versions.  And for the last 18 months or so, they have only released any new versions in parallel with introduction of a new printer.  Therefore, I don't expect a new 4.01.xx driver before fall, or possibly even next spring, unless Samsung decides the bugs are severe enough to justify a special release.

However, for your purposes, the lack of updates is not important.  The 4.00.39 driver should continue to work for at least a couple of years, probably much longer, before some system update starts to cause problems with it.

Repository Information Legal Contact Alternative Drivers