This project has moved and is read-only. For the latest updates, please go here.

Dont want to set twain.Capabilities.XferCount.Set

Jun 16, 2016 at 8:05 AM
Edited Jun 16, 2016 at 8:31 AM
Hello Saraff,

I don't want to set twain.Capabilities.XferCount.set property, because i have lot of pages to count and still i want to fire Completed event.
Please help me for this i really need that, my application is being stuck.

Please help me thru code.

or is there any other way to achieve that than please give me.
I want to scan all pages put in a scanner tray and than system will free to do other stuff.

Thank you
Jun 16, 2016 at 12:00 PM
Edited Jun 17, 2016 at 8:48 AM
Hello, VishalJani.
The fact that you turn on the Automatic Document Feeder. By default the XferCount is equal to infinity. Therefore, the only way for the scanner to report the end of the scan - this is to inform you that a user canceled the scanning (in a Twain32.AcquireError instead a Twain32.AcquiredCompleted).
Try process AcquireError event. Also, you can process a Twain32.EndXfer event.
// <<< preparing

_twain32.Acquire();

private void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e) {
    try {
        System.Diagnostics.Debug.WriteLine();
        System.Diagnostics.Debug.WriteLine("EndXfer");

        e.Image.Save(Path.GetTempFileName(), ImageFormat.Jpeg);

    } catch(Exception ex) {
        // <<<
    }
};

private void _twain32_AcquireCompleted(sender, e) {
    try {
        System.Diagnostics.Debug.WriteLine();
        System.Diagnostics.Debug.WriteLine("Acquire Completed.");

        this._AcquireCompleted(); // <<<

    } catch(Exception ex) {
        // <<<
    }
};

private void _twain32_AcquireError(object sender, Twain32.AcquireErrorEventArgs e) {
    try {
        System.Diagnostics.Debug.WriteLine();
        System.Diagnostics.Debug.WriteLine("Acquire Error: ReturnCode = {0}; ConditionCode = {1};", e.Exception.ReturnCode, e.Exception.ConditionCode);

        if(e.Exception.ReturnCode==TwRC.Cancel) {
            this._AcquireCompleted(); // <<<
        } else {
            Program.WriteException(e.Exception);
        }

    } catch(Exception ex) {
        // <<<
    }
};

private void _AcquireCompleted() {
    for(var i=0; i<_twain32.ImageCount; i++) {
        var _image=_twain32.GetImage(i);
        // <<<
    }
}

Jun 16, 2016 at 12:59 PM
Hello Saraff,

Thank you for Reply.

But AcquireError event did not going to fire after opening Automatic Document Feeder.
Kindly provide settings what i have to set to achieve this functionality.

Thank you
Jun 16, 2016 at 2:16 PM
Hello, VishalJani.
Well, it means that the scanner will continue waiting for new pages for scanning. And, wherefore you need to the Twain32.AcquireCompleted event?
Jun 16, 2016 at 2:46 PM
Hello Saraff,

Than how can i fire Twain32.AcquireCompleted event ?
That is my issue.
That is event is not fire and my form will not be free from waiting.
Please help on this

Thank you
Jun 16, 2016 at 3:17 PM
Hello, VishalJani.
Once again, I repeat. Well, it means that the scanner will continue waiting for new pages for scanning. The Twain32.AcquireCompleted event occurs at the time of completion of the cycle of image scans. It can not be called manually. The initiator should be a scanner. The application can tell the scanner that does not need to scan more (if that makes sense). And then will be occurs the Twain32.AcquireCompleted event.
Jun 16, 2016 at 3:48 PM
Hello Saraff,
Than how can i tell scanner that does not need to scan more.
And i don't want to set XferCount value.
Is there any other way ?
Jun 16, 2016 at 9:47 PM
Edited Jun 17, 2016 at 8:47 AM
Hello, VishalJani.
Try set a true value to a Cancel property of event args (for the XferDone, EndXfer, SetupMemXfer, MemXfer, SetupFileXfer, FileXfer events). You mast download latest source code.
Change set number f637719d86e1.
private void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e) {
    try {
        // ...
        e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        // ...
    } catch(Exception ex) {
        // ...
    }
}
Jun 17, 2016 at 6:32 AM
Hello Saraff,

Thanks for your reply and latest source code.

But how can i know that this is my last page and than i have to do "e.Cancel = true;"

That event or property should be available.

Thank you
Jun 17, 2016 at 7:59 AM
Hello, VishalJani.
Try follow capabilities: CAP_FEEDERLOADED, CAP_PAPERDETECTABLE.
Jun 17, 2016 at 8:11 AM
Hello Saraff,

Thank you for you quick reply.

I use that but every time that property gives me Count 1 value even if its is last page.

Please give me solution to do e.Cancel = true;
I think that is work for me.

Thank you.
Jun 17, 2016 at 8:44 AM
Hello, VishalJani.
Try follow:
private void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e) {
    try {
        // ...
        if(_twain32.Capabilities.FeederLoaded.IsSupported(TwQC.GetCurrent)&&!_twain32.Capabilities.FeederLoaded.GetCurrent()) {
            e.Cancel = true; // <<< it tell scanner that does not need to scan more.
        }
        // ...
    } catch(Exception ex) {
        // ...
    }
}
Jun 17, 2016 at 10:27 AM
Hello Saraff,

Thank you for your reply
But this is not going to work for me.

Is there any other solution ?

Thank you
Jun 17, 2016 at 11:37 AM
Hello Saraff,

Please help me sir my project is stuck in a middle.
i want free the application after all pages are scanning successfully.
I tried lot of things but not success.

Please help for this.
If you can write full lines of code with the capabilities which i have to set than it is more beneficial for me.

Thank you
Jun 17, 2016 at 11:54 AM
Hello, VishalJani.
Try to consider the following options:
  • press the cancel button on the scanner at the end of the scan;
  • prompt the user to choose between the "continue" or "stop" after scanning each page;
  • scan several times on one page, ie, set XferCount = 1 and recall many times a Twain32.Acquire().
Jun 17, 2016 at 1:36 PM
Edited Jun 17, 2016 at 1:36 PM
Hello Saraff,

Thank you very much for reply.
But that would not my solution.
User can not press yes button multiple times like 100 or 150 times.
I want on my own like if pages are not available on the tray, than i want a return value so that i can able to cancel the scanning.

Please give me some solution sir.
I really needed.

Thank you.
Jun 17, 2016 at 9:46 PM
Hello, VishalJani.
Insert follow code in a handlers of a EndXfer and XferDone events. And show me results.
System.Diagnostics.Debug.WriteLine(string.Format("{0} {{",e.GetType().Name));
var _caps=this._twain32.Capabilities.SupportedCaps.Get();
for(var i = 0; i<_caps.Count; i++) {
    System.Diagnostics.Debug.WriteLine(string.Format("    {0}: {1}",_caps[i],this._twain32.GetCurrentCap((TwCap)_caps[i])));
}
System.Diagnostics.Debug.WriteLine("}");
Jun 20, 2016 at 8:01 AM
Hello Saraff,

below listed values:
XferDoneEventArgs {
33025: False
33024: False
AutoFeed: True
AutoScan: True
32797: True
CameraEnabled: True
32798: 8
CameraOrder: 8
CameraSide: 0
CustomDSData: True
ClearPage: False
FeedPage: False
DeviceOnline: True
Duplex: 1
DuplexEnabled: True
EnableDSUIOnly: True
Endorser: 0
FeederAlignment: 2
FeederEnabled: True
FeederLoaded: True
Indicators: False
JobControl: 0
PaperDetectable: True
Printer: 1
PrinterEnabled: False
PrinterIndex: 0
PrinterMode: 0
PrinterString: 
SupportedCaps: System.Object[]
UIControllable: True
XferCount: -1
AutoSize: 1
AutomaticBorderDetection: True
BitDepth: 24
BitDepthReduction: 0
BitOrder: 1
Brightness: 0
ICompression: 0
Contrast: 0
ExtImageInfo: True
Filter: 3
Frames: {X=0,Y=428.003,Width=-15829.76,Height=-310.4717}
Halftones: None
ImageFileFormat: 2
JpegQuality: 75
MaxFrames: 1
MinimumHeight: 0.2133331
MinimumWidth: 0.2133331
Orientation: 0
PhysicalWidth: 12.00667
PhysicalHeight: 17.04666
PixelFlavor: 0
IPixelType: 2
PlanarChunky: 0
Rotation: 0
SupportedSizes: 1
UndefinedImageSize: True
IUnits: 0
IXferMech: 0
XResolution: 300
YResolution: 300
32793: 250
32820: -1
32841: 1
32842: 1
32873: 1
32787: 0
32862: 0
32866: 2
32771: 3
32769: 0
32885: 1
32794: 0.009994507
32770: 2
32886: 0
32782: 0
32772: 0
32783: 0
32821: 4
32822: 2
32829: 1
32830: 0
32832: 0
32834: 0
32831: 0
32835: 0
32849: 1
32854: 0
32859: 1
32863: 305
32864: 453
32872: 0
32874: 0
32876: 0
32878: 1
32879: 1
32768: 1
32828: 1
32844: 0
32853: Auto-detection
32774: 0
32775: 0
32817: 0
32823: 0
32827: 0
32847: 0
32848: 0
32867: 0
32779: 0
32780: 0
32811: 0
32781: 0
AutomaticDeskew: False
32805: 0
32806: 0
32785: 1
32777: 3
32788: 0
32809: 0
32861: 1
32819: 0
32833: 0
32855: 128
32875: 128
32856: 0
32857: 0
32869: 0
32889: 0
32880: 1
32887: 0
32888: 4
32818: 0
32776: 0
32860: 0
32870: 0
32871: 40
32808: 0
32786: -4502
32789: 0
32790: 0
32791: 1
32792: 0
32810: 0
32813: 0
32814: 0
BarCodeDetectionEnabled: False
32795: 0
32796: 1
32804: 0
32836: 1
32837: 
32850: 0
32851: 1526
32890: 75
32858: 0
Threshold: 128
32865: 0
32868: 0
32900: DR-6030C
SerialNumber: FLU00568
}

EndXferEventArgs {
33025: False
33024: False
AutoFeed: True
AutoScan: True
32797: True
CameraEnabled: True
32798: 8
CameraOrder: 8
CameraSide: 0
CustomDSData: True
ClearPage: False
FeedPage: False
DeviceOnline: True
Duplex: 1
DuplexEnabled: True
EnableDSUIOnly: True
Endorser: 0
FeederAlignment: 2
FeederEnabled: True
FeederLoaded: True
Indicators: False
JobControl: 0
PaperDetectable: True
Printer: 1
PrinterEnabled: False
PrinterIndex: 0
PrinterMode: 0
PrinterString: 
SupportedCaps: System.Object[]
UIControllable: True
XferCount: -1
AutoSize: 1
AutomaticBorderDetection: True
BitDepth: 24
BitDepthReduction: 0
BitOrder: 1
Brightness: 0
ICompression: 0
Contrast: 0
ExtImageInfo: True
Filter: 3
Frames: {X=0,Y=428.003,Width=-15855.76,Height=-427.503}
Halftones: None
ImageFileFormat: 2
JpegQuality: 75
MaxFrames: 1
MinimumHeight: 0.2133331
MinimumWidth: 0.2133331
Orientation: 0
PhysicalWidth: 12.00667
PhysicalHeight: 17.04666
PixelFlavor: 0
IPixelType: 2
PlanarChunky: 0
Rotation: 0
SupportedSizes: 1
UndefinedImageSize: True
IUnits: 0
IXferMech: 0
XResolution: 300
YResolution: 300
32793: 250
32820: -1
32841: 1
32842: 1
32873: 1
32787: 0
32862: 0
32866: 2
32771: 3
32769: 0
32885: 1
32794: 0.009994507
32770: 2
32886: 0
32782: 0
32772: 0
32783: 0
32821: 4
32822: 2
32829: 1
32830: 0
32832: 0
32834: 0
32831: 0
32835: 0
32849: 1
32854: 0
32859: 1
32863: 305
32864: 453
32872: 0
32874: 0
32876: 0
32878: 1
32879: 1
32768: 1
32828: 1
32844: 0
32853: Auto-detection
32774: 0
32775: 0
32817: 0
32823: 0
32827: 0
32847: 0
32848: 0
32867: 0
32779: 0
32780: 0
32811: 0
32781: 0
AutomaticDeskew: False
32805: 0
32806: 0
32785: 1
32777: 3
32788: 0
32809: 0
32861: 1
32819: 0
32833: 0
32855: 128
32875: 128
32856: 0
32857: 0
32869: 0
32889: 0
32880: 1
32887: 0
32888: 4
32818: 0
32776: 0
32860: 0
32870: 0
32871: 40
32808: 0
32786: -4502
32789: 0
32790: 0
32791: 1
32792: 0
32810: 0
32813: 0
32814: 0
BarCodeDetectionEnabled: False
32795: 0
32796: 1
32804: 0
32836: 1
32837: 
32850: 0
32851: 1526
32890: 75
32858: 0
Threshold: 128
32865: 0
32868: 0
32900: DR-6030C
SerialNumber: FLU00568
}

in Both event AutoBright capability is not supported.
and after this SerialNumber capability there is 32902, 32903, 32904, 38905 is not supported.

i wrote my code which is set for capabilities...
_twain.ShowUI = false;
_twain.Capabilities.Indicators.Set(false);
_twain.Capabilities.FeederEnabled.Set(true);
_twain.Capabilities.AutoFeed.Set(true);
_twain.Capabilities.DuplexEnabled.Set(true);
_twain.Capabilities.Duplex.Set(TwDX.OnePassDuplex);

if i have to set another capabilities than please tell me.

Please help for this.

Thank you
Jun 20, 2016 at 1:25 PM
Hello Saraff,

Please reply me, i am waiting for you reply eagerly.

Thank you.
Jun 20, 2016 at 5:00 PM
Hello, VishalJani.
Try set a CAP_AUTOSCAN to a false. Also, try set a CAP_INDICATORS to a true, because it will display progress bar and a cancel button.
Jun 21, 2016 at 8:41 AM
Hello Saraff,

I don't want that user cancels the button and than application will free.
I don't want any user input.
When all pages are finish to scan than system will automatically free and user can do further things.

Thank you.
Jun 21, 2016 at 10:05 AM
Hello, VishalJani.
Are you try set a CAP_AUTOSCAN to a false.
Jun 21, 2016 at 11:32 AM
Hello saraff,

I tried that, but not succeed.
Form is not free, and i dont want that use press cancel button and stop the scanning.
Please do something and give me solution.
I m stuck here from last 2 weeks.
Please give me solution.
Jun 21, 2016 at 2:57 PM
Hello Saraff,

I am waiting for your reply.

Thank you
Jun 21, 2016 at 7:28 PM
Hello, VishalJani.
I can give only the following two solutions:
Marked as answer by SARAFF on 6/30/2016 at 11:40 AM
Jun 23, 2016 at 7:04 AM
Hello Saraff,

Thank you for all your help.
And thank you for your nice and handy library.

After all the research i came to know that my scanner does not support xFerCount value when he acquire the image so that was the issue when last page is scanned and still that property gets result with 1, so it will wait for the document placed on the tray, and my application was stuck like hang.

I tried same code with another scanner that it will work fine without any issue.

But i came to know that after all scanning when close my form than one error message will from the windows and said: SVChost service is not closed.
and the options is:

Tell this issue to microsoft ?
Close ?
Debug ?

Do u have any idea regarding this ?

That scanner is not connected directly with my computer, that is over LAN.

Thank you.
Jun 23, 2016 at 8:59 AM
Hello, VishalJani.
Try invoke a Twain32.CloseDataSource() method before close your form.
Jun 23, 2016 at 11:08 AM
Hello Saraff,

I did that...
CloseDataSource();
CloseDSM();

and last i tried Dispose method but not succeed.

Remember that scanner is on network, i access through IP address(LAN)

Thank you
Jun 23, 2016 at 12:27 PM
Hello, VishalJani.
That is how work scanner (locally or over a network) does not affect to the application. The scanner driver in any case is loaded into the application.
Apparently, the problem is in the scanner driver, as he don't unloaded (when invoked a Twain32.CloseDataSource() method), and when unloading DSM it fails.
Jun 23, 2016 at 2:56 PM
Edited Jun 23, 2016 at 3:09 PM
Hello Saraff,

Thank for your all your replies and support.

Thank you