[sane-devel] C#/Mono FrontEnd Wrapper for scanimage / scanadf

Alejandro Imass ait at p2ee.org
Mon Apr 5 04:05:32 UTC 2010


On Sun, Apr 4, 2010 at 10:12 PM, Christopher Sawyer
<christoofar at gmail.com> wrote:
> (copy to list)
>
> Yes the STDIN/STDOUT is pretty kludgy way of interfacing to SANE, but it was
> quick and dirty.   Now that I have the core objects written like I want
> them, I can now go back and figure out how to glue it up using a direct
> binding.
>
> Actually I think what most Mono programmers do is write a C binding system
> object lib that uses simple data types and then write a .NET object which
> uses [DllImport] P/Invoke directive on the methods to redirect the calls on
> the object to the library.
>
>
> What I need to do now is read the scanimage source code and understand how
> it works so I can understand the headers and write the .NET proxy class and
> the lib glue code (no small task!) :-)

You will need the SANE API Doc found here:
http://www.sane-project.org/docs.html (see Programmer's
Documentation). The Sane mapping is probably not that trivial as it
was not designed to interface to a higher-level language so there are
a lot of structs and other funky stuff. I hacked a little into the
Sane API for Perl
http://search.cpan.org/~ratcliffe/Sane-0.03/lib/Sane.pm
Look in the XS files and take a look how Jeffrey Ratcliffe mapped it
to Perl. It's not so hard to understand if you find yourself a good
Perl XS reference. But there you have an excellent example and will
probably serve as base for your mappings to Mono

Best,
Alejandro Imass

>
> On Sun, Apr 4, 2010 at 9:16 PM, Alejandro Imass <ait at p2ee.org> wrote:
>>
>> On Sun, Apr 4, 2010 at 12:55 PM, Christopher Sawyer
>> <christoofar at gmail.com> wrote:
>> > Hello
>> >
>> > I had been looking for a long time for a Mono binding for SANE but most
>> > of
>> > my efforts have been fruitless (probably because none exist! :-)  so I
>> > started writing my own.
>> >
>> > If anybody wants to help me, I put the source here:
>> > http://code.google.com/p/mono-sane/
>> >
>> > The code is capable of reading the scanner list from scanimage,
>> > interpreting
>> > the configuration options, performing a one-pass scan with or without
>> > scanimage options.
>> >
>> > It shells out to scanimage and collects its output from there.  I'm
>> > expanding it as I go along since I'm using it to experiment with forms
>> > recognition.  I'm working on ADF, thread-safety, delegate callbacks for
>> > asynchronous scanning right now and hope to finish it soon.
>> >
>>
>> Dunno much about Mono but you should be using the SANE API directly.
>> It has of course native binding to C, but surely there must be a way
>> of loading shared objects and static C libraries from Mono/C#. For
>> example in Perl it's called XS, a language/API that helps glue C code
>> to Perl, there surely must be something for C#., I think you should be
>> looking into that, rather than a STDIN/STDOUT interface with
>> scanimage. Just did a quick google search came up with this:
>>
>> http://www.mono-project.com/Interop_with_Native_Libraries
>>
>> Cheers,
>> Alejandro Imass
>>
>> > --
>> > sane-devel mailing list: sane-devel at lists.alioth.debian.org
>> > http://lists.alioth.debian.org/mailman/listinfo/sane-devel
>> > Unsubscribe: Send mail with subject "unsubscribe your_password"
>> >             to sane-devel-request at lists.alioth.debian.org
>> >
>
>



More information about the sane-devel mailing list