Jump to content

How to write C# program using WIA Automation 2.0 to support MultiFeed Scanner


Recommended Posts

Posted

I am working on a project right now that needs to be able to scan in

multiple pages using a scanner's multi feed feature. The scanner that

I am using to test is Fujitsu fi-5120C.

 

I am coding this project in C# and am trying to use WIA Automation 2.0

Library. I am open to alternative technologies if someone has any

suggestions.

 

My test case is that I have three sheets of paper in the document

feeder and I want my code to scan in all three pages at once.

 

All the pages get scanned correctly when I call the following code:

 

private void CallScanWizard()

{

 

WIA.CommonDialog dlg = new WIA.CommonDialog();

 

Device dvc =

dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType,true,false);

 

if (dvc != null)

{

dlg.ShowAcquisitionWizard(dvc);

}

}

 

This tells me that it is possible in WIA. However, this can't be the

solution for me. I don't want the user to have to pick a file path

for the images to be saved to. I want to work with them in memory

only.

 

So I tried the following code:

 

private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER = 1;

private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FLATBED =

2;

private const int WIA_IPS_PAGES = 3096;

 

private const int WIA_DPS_DOCUMENT_HANDLING_STATUS_FEED_READY

= 1;

 

private const int WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS =

1024;

private const int WIA_PROPERTIES_WIA_DIP_FIRST = 2;

private const int WIA_PROPERTIES_WIA_DPA_FIRST =

WIA_PROPERTIES_WIA_DIP_FIRST +

WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

private const int WIA_PROPERTIES_WIA_DPC_FIRST =

WIA_PROPERTIES_WIA_DPA_FIRST +

WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

 

private const int WIA_PROPERTIES_WIA_DPS_FIRST =

WIA_PROPERTIES_WIA_DPC_FIRST +

WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

private const int

WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS =

WIA_PROPERTIES_WIA_DPS_FIRST + 13;

private const int

WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT =

WIA_PROPERTIES_WIA_DPS_FIRST + 14;

private const string WIA_DPS_DOCUMENT_HANDLING_STATUS_STR =

"Document Handling Status";

 

private const double WIA_ERRORS_BASE_VAL_WIA_ERROR =

2149646336;

private const double WIA_ERRORS_WIA_ERROR_PAPER_EMPTY =

WIA_ERRORS_BASE_VAL_WIA_ERROR + 3;

 

private const int WIA_IPS_CUR_INTENT = 6146;

private const int WIA_IPS_XRES = 6147;

private const int WIA_IPS_YRES = 6148;

 

private const int WIA_INTENT_NONE = 0x00000000;

private const int WIA_INTENT_IMAGE_TYPE_COLOR = 0x00000001;

private const int WIA_INTENT_IMAGE_TYPE_GRAYSCALE =

0x00000002;

private const int WIA_INTENT_IMAGE_TYPE_TEXT = 0x00000004;

private const int WIA_INTENT_IMAGE_TYPE_MASK = 0x0000000F;

private const int WIA_INTENT_MINIMIZE_SIZE = 0x00010000;

private const int WIA_INTENT_MAXIMIZE_QUALITY = 0x00020000;

private const int WIA_INTENT_BEST_PREVIEW = 0x00040000;

private const int WIA_INTENT_SIZE_MASK = 0x000F0000;

private const int FEED_READY = 0x01;

 

private const string wiaFormatPNG =

"{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}";

private void TestScan()

{

DeviceManager manager = new DeviceManager();

object index = 1;

 

DeviceInfo info = manager.DeviceInfos.get_Item(ref index);

Device dvc = info.Connect();

object res = 150;

object intent = WIA_INTENT_IMAGE_TYPE_COLOR;

object statusProp = WIA_DPS_DOCUMENT_HANDLING_STATUS_STR;

int documentStatus = 0;

object pgs = 0;

object handler = WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER;

 

foreach (Property p in dvc.Properties)

{

switch (p.PropertyID)

{

case

WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT:

p.set_Value(ref handler);

break;

 

case WIA_IPS_XRES:

case WIA_IPS_YRES:

p.set_Value(ref res);

break;

 

case WIA_IPS_CUR_INTENT:

p.set_Value(ref intent);

break;

 

case

WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS:

documentStatus = (int)p.get_Value();

break;

 

case WIA_IPS_PAGES:

p.set_Value(ref pgs);

break;

}

}

 

foreach (Item itm in dvc.Items)

{

while ((documentStatus & FEED_READY) == FEED_READY)

{

itm.Transfer(wiaFormatPNG);

documentStatus = (int)dvc.Properties.get_Item(ref

statusProp).get_Value();

}

}

}

 

I got this code idea from http://www.xtremevbtalk.com/showthread.php?t=288758.

However, the DOCUMENT HANDLING STATUS always stays 5 even when all the

pages are scanned through. This eventually ends in a com exception

being thrown when all the pages have been scanned. I could just throw

a try catch around the whole thing but that doesn't seem right to me.

I don't like it.

 

Does anyone have any suggestions for me? This code needs to work

regardless of what scanner is being used. Is WIA the wrong choice

here? Should I go right to TWAIN code?

 

Thanks in advance for any help anyone can give me.

  • Replies 4
  • Created
  • Last Reply

Popular Days

Posted

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

It's gotta be this line:

 

private const int WIA_INTENT_NONE = 0x00000000;

 

 

If it isn't I'm wrong! Or maybe this is the wrong group?

 

 

Good luck, Rich

 

 

"Tom G." <tgrant@healthcareone.info> wrote in message

news:7c70c281-a55c-4f47-99f1-d635afd247cc@n75g2000hsh.googlegroups.com...

>I am working on a project right now that needs to be able to scan in

> multiple pages using a scanner's multi feed feature. The scanner that

> I am using to test is Fujitsu fi-5120C.

>

> I am coding this project in C# and am trying to use WIA Automation 2.0

> Library. I am open to alternative technologies if someone has any

> suggestions.

>

> My test case is that I have three sheets of paper in the document

> feeder and I want my code to scan in all three pages at once.

>

> All the pages get scanned correctly when I call the following code:

>

> private void CallScanWizard()

> {

>

> WIA.CommonDialog dlg = new WIA.CommonDialog();

>

> Device dvc =

> dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType,true,false);

>

> if (dvc != null)

> {

> dlg.ShowAcquisitionWizard(dvc);

> }

> }

>

> This tells me that it is possible in WIA. However, this can't be the

> solution for me. I don't want the user to have to pick a file path

> for the images to be saved to. I want to work with them in memory

> only.

>

> So I tried the following code:

>

> private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER = 1;

> private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FLATBED =

> 2;

> private const int WIA_IPS_PAGES = 3096;

>

> private const int WIA_DPS_DOCUMENT_HANDLING_STATUS_FEED_READY

> = 1;

>

> private const int WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS =

> 1024;

> private const int WIA_PROPERTIES_WIA_DIP_FIRST = 2;

> private const int WIA_PROPERTIES_WIA_DPA_FIRST =

> WIA_PROPERTIES_WIA_DIP_FIRST +

> WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

> private const int WIA_PROPERTIES_WIA_DPC_FIRST =

> WIA_PROPERTIES_WIA_DPA_FIRST +

> WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

>

> private const int WIA_PROPERTIES_WIA_DPS_FIRST =

> WIA_PROPERTIES_WIA_DPC_FIRST +

> WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

> private const int

> WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS =

> WIA_PROPERTIES_WIA_DPS_FIRST + 13;

> private const int

> WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT =

> WIA_PROPERTIES_WIA_DPS_FIRST + 14;

> private const string WIA_DPS_DOCUMENT_HANDLING_STATUS_STR =

> "Document Handling Status";

>

> private const double WIA_ERRORS_BASE_VAL_WIA_ERROR =

> 2149646336;

> private const double WIA_ERRORS_WIA_ERROR_PAPER_EMPTY =

> WIA_ERRORS_BASE_VAL_WIA_ERROR + 3;

>

> private const int WIA_IPS_CUR_INTENT = 6146;

> private const int WIA_IPS_XRES = 6147;

> private const int WIA_IPS_YRES = 6148;

>

> private const int WIA_INTENT_NONE = 0x00000000;

> private const int WIA_INTENT_IMAGE_TYPE_COLOR = 0x00000001;

> private const int WIA_INTENT_IMAGE_TYPE_GRAYSCALE =

> 0x00000002;

> private const int WIA_INTENT_IMAGE_TYPE_TEXT = 0x00000004;

> private const int WIA_INTENT_IMAGE_TYPE_MASK = 0x0000000F;

> private const int WIA_INTENT_MINIMIZE_SIZE = 0x00010000;

> private const int WIA_INTENT_MAXIMIZE_QUALITY = 0x00020000;

> private const int WIA_INTENT_BEST_PREVIEW = 0x00040000;

> private const int WIA_INTENT_SIZE_MASK = 0x000F0000;

> private const int FEED_READY = 0x01;

>

> private const string wiaFormatPNG =

> "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}";

> private void TestScan()

> {

> DeviceManager manager = new DeviceManager();

> object index = 1;

>

> DeviceInfo info = manager.DeviceInfos.get_Item(ref index);

> Device dvc = info.Connect();

> object res = 150;

> object intent = WIA_INTENT_IMAGE_TYPE_COLOR;

> object statusProp = WIA_DPS_DOCUMENT_HANDLING_STATUS_STR;

> int documentStatus = 0;

> object pgs = 0;

> object handler = WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER;

>

> foreach (Property p in dvc.Properties)

> {

> switch (p.PropertyID)

> {

> case

> WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT:

> p.set_Value(ref handler);

> break;

>

> case WIA_IPS_XRES:

> case WIA_IPS_YRES:

> p.set_Value(ref res);

> break;

>

> case WIA_IPS_CUR_INTENT:

> p.set_Value(ref intent);

> break;

>

> case

> WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS:

> documentStatus = (int)p.get_Value();

> break;

>

> case WIA_IPS_PAGES:

> p.set_Value(ref pgs);

> break;

> }

> }

>

> foreach (Item itm in dvc.Items)

> {

> while ((documentStatus & FEED_READY) == FEED_READY)

> {

> itm.Transfer(wiaFormatPNG);

> documentStatus = (int)dvc.Properties.get_Item(ref

> statusProp).get_Value();

> }

> }

> }

>

> I got this code idea from

> http://www.xtremevbtalk.com/showthread.php?t=288758.

> However, the DOCUMENT HANDLING STATUS always stays 5 even when all the

> pages are scanned through. This eventually ends in a com exception

> being thrown when all the pages have been scanned. I could just throw

> a try catch around the whole thing but that doesn't seem right to me.

> I don't like it.

>

> Does anyone have any suggestions for me? This code needs to work

> regardless of what scanner is being used. Is WIA the wrong choice

> here? Should I go right to TWAIN code?

>

> Thanks in advance for any help anyone can give me.

>

Posted

Re: How to write C# program using WIA Automation 2.0 to support MultiFeed Scanner

 

On Feb 29, 5:10 pm, "Rich" <dontbotherme@localhost> wrote:

> It's gotta be this line:

>

> private const int WIA_INTENT_NONE = 0x00000000;

>

> If it isn't I'm wrong! Or maybe this is the wrong group?

>

> Good luck, Rich

>

> "Tom G." <tgr...@healthcareone.info> wrote in message

>

> news:7c70c281-a55c-4f47-99f1-d635afd247cc@n75g2000hsh.googlegroups.com...

>

>

>

> >I am working on a project right now that needs to be able to scan in

> > multiple pages using a scanner's multi feed feature.  The scanner that

> > I am using to test is Fujitsu fi-5120C.

>

> > I am coding this project in C# and am trying to use WIA Automation 2.0

> > Library.  I am open to alternative technologies if someone has any

> > suggestions.

>

> > My test case is that I have three sheets of paper in the document

> > feeder and I want my code to scan in all three pages at once.

>

> > All the pages get scanned correctly when I call the following code:

>

> >        private void CallScanWizard()

> >        {

>

> >            WIA.CommonDialog dlg = new WIA.CommonDialog();

>

> >            Device dvc =

> > dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType,true,false);

>

> >            if (dvc != null)

> >            {

> >                dlg.ShowAcquisitionWizard(dvc);

> >            }

> >        }

>

> > This tells me that it is possible in WIA.  However, this can't be the

> > solution for me.  I don't want the user to have to pick a file path

> > for the images to be saved to.  I want to work with them in memory

> > only.

>

> > So I tried the following code:

>

> > private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER = 1;

> >        private const int WIA_DPS_DOCUMENT_HANDLING_SELECT_FLATBED =

> > 2;

> >        private const int WIA_IPS_PAGES = 3096;

>

> >        private const int WIA_DPS_DOCUMENT_HANDLING_STATUS_FEED_READY

> > = 1;

>

> >        private const int WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS =

> > 1024;

> >        private const int WIA_PROPERTIES_WIA_DIP_FIRST = 2;

> >        private const int WIA_PROPERTIES_WIA_DPA_FIRST =

> > WIA_PROPERTIES_WIA_DIP_FIRST +

> > WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

> >        private const int WIA_PROPERTIES_WIA_DPC_FIRST =

> > WIA_PROPERTIES_WIA_DPA_FIRST +

> > WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

>

> >        private const int WIA_PROPERTIES_WIA_DPS_FIRST =

> > WIA_PROPERTIES_WIA_DPC_FIRST +

> > WIA_PROPERTIES_WIA_RESERVED_FOR_NEW_PROPS;

> >        private const int

> > WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS =

> > WIA_PROPERTIES_WIA_DPS_FIRST + 13;

> >        private const int

> > WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT =

> > WIA_PROPERTIES_WIA_DPS_FIRST + 14;

> >        private const string WIA_DPS_DOCUMENT_HANDLING_STATUS_STR =

> > "Document Handling Status";

>

> >        private const double WIA_ERRORS_BASE_VAL_WIA_ERROR =

> > 2149646336;

> >        private const double WIA_ERRORS_WIA_ERROR_PAPER_EMPTY =

> > WIA_ERRORS_BASE_VAL_WIA_ERROR + 3;

>

> >        private const int WIA_IPS_CUR_INTENT = 6146;

> >        private const int WIA_IPS_XRES = 6147;

> >        private const int WIA_IPS_YRES = 6148;

>

> >        private const int WIA_INTENT_NONE = 0x00000000;

> >        private const int WIA_INTENT_IMAGE_TYPE_COLOR = 0x00000001;

> >        private const int WIA_INTENT_IMAGE_TYPE_GRAYSCALE =

> > 0x00000002;

> >        private const int WIA_INTENT_IMAGE_TYPE_TEXT = 0x00000004;

> >        private const int WIA_INTENT_IMAGE_TYPE_MASK = 0x0000000F;

> >        private const int WIA_INTENT_MINIMIZE_SIZE = 0x00010000;

> >        private const int WIA_INTENT_MAXIMIZE_QUALITY = 0x00020000;

> >        private const int WIA_INTENT_BEST_PREVIEW = 0x00040000;

> >        private const int WIA_INTENT_SIZE_MASK = 0x000F0000;

> >        private const int FEED_READY = 0x01;

>

> >        private const string wiaFormatPNG =

> > "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}";

> >      private void TestScan()

> >        {

> >            DeviceManager manager = new DeviceManager();

> >            object index = 1;

>

> >            DeviceInfo info = manager.DeviceInfos.get_Item(ref index);

> >            Device dvc = info.Connect();

> >            object res = 150;

> >            object intent = WIA_INTENT_IMAGE_TYPE_COLOR;

> >            object statusProp = WIA_DPS_DOCUMENT_HANDLING_STATUS_STR;

> >            int documentStatus = 0;

> >            object pgs = 0;

> >            object handler = WIA_DPS_DOCUMENT_HANDLING_SELECT_FEEDER;

>

> >            foreach (Property p in dvc.Properties)

> >            {

> >                switch (p.PropertyID)

> >                {

> >                    case

> > WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_SELECT:

> >                        p.set_Value(ref handler);

> >                        break;

>

> >                    case WIA_IPS_XRES:

> >                    case WIA_IPS_YRES:

> >                        p.set_Value(ref res);

> >                        break;

>

> >                    case WIA_IPS_CUR_INTENT:

> >                        p.set_Value(ref intent);

> >                        break;

>

> >                    case

> > WIA_PROPERTIES_WIA_DPS_DOCUMENT_HANDLING_STATUS:

> >                        documentStatus = (int)p..get_Value();

> >                        break;

>

> >                    case WIA_IPS_PAGES:

> >                        p.set_Value(ref pgs);

> >                        break;

> >                }

> >            }

>

> >            foreach (Item itm in dvc.Items)

> >            {

> >                while ((documentStatus & FEED_READY) == FEED_READY)

> >                {

> >                    itm.Transfer(wiaFormatPNG);

> >                    documentStatus = (int)dvc.Properties.get_Item(ref

> > statusProp).get_Value();

> >                }

> >            }

> >        }

>

> > I got this code idea from

> >http://www.xtremevbtalk.com/showthread.php?t=288758.

> > However, the DOCUMENT HANDLING STATUS always stays 5 even when all the

> > pages are scanned through.  This eventually ends in a com exception

> > being thrown when all the pages have been scanned.  I could just throw

> > a try catch around the whole thing but that doesn't seem right to me.

> > I don't like it.

>

> > Does anyone have any suggestions for me?  This code needs to work

> > regardless of what scanner is being used.  Is WIA the wrong choice

> > here?  Should I go right to TWAIN code?

>

> > Thanks in advance for any help anyone can give me.- Hide quoted text -

>

> - Show quoted text -

 

I am not sure why you are referencing that line. What is wrong with

private const int WIA_INTENT_NONE = 0x00000000;? You think that

somehow applies to the Document Handling Status remaining 5 even with

no paper in the tray?

 

Wrong group? Do you mean that I have posted to the wrong group? I

picked this group for two reasons. When I did a google search on this

topic, I got the most hits in this news group. The second reason is

that this group has a lot of activity. Is there a better group to

post to?

 

Thanks for you reply.

 

Tom

Posted

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

 

"Tom G." <tgrant@healthcareone.info> wrote in message

news:9a600dd5-bd70-4a3a-83ba-28b005c6141f@2g2000hsn.googlegroups.com...

<snip>

 

Wrong group? Do you mean that I have posted to the wrong group? I

picked this group for two reasons. When I did a google search on this

topic, I got the most hits in this news group. The second reason is

that this group has a lot of activity. Is there a better group to

post to?

 

Thanks for you reply.

 

Tom

 

 

Yes, you posted to one of many wrong groups. You have a programming

problem, but most people here are not

programmers. The number of hits isn't especially important. What is

important is the context.

Jim

Guest Bill in Co.
Posted

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

Re: How to write C# program using WIA Automation 2.0 to support Multi Feed Scanner

 

There are several microsoft programming newsgroups, if you just look at the

headers.

 

Jim wrote:

> "Tom G." <tgrant@healthcareone.info> wrote in message

> news:9a600dd5-bd70-4a3a-83ba-28b005c6141f@2g2000hsn.googlegroups.com...

> <snip>

>

> Wrong group? Do you mean that I have posted to the wrong group? I

> picked this group for two reasons. When I did a google search on this

> topic, I got the most hits in this news group. The second reason is

> that this group has a lot of activity. Is there a better group to

> post to?

>

> Thanks for you reply.

>

> Tom

>

>

> Yes, you posted to one of many wrong groups. You have a programming

> problem, but most people here are not

> programmers. The number of hits isn't especially important. What is

> important is the context.

> Jim


×
×
  • Create New...