This project has moved. For the latest updates, please go here.

About Set Property ,alert [General failure in response to DAT_CAPS]

Jul 23, 2014 at 5:11 AM
some scan model
i test scan
it is alert error,but ,pushed [ok] can continue,but i set use gray,it alerted this error,only scan color......

About Set Property ,alert [General failure in response to DAT_CAPS]

Help me
Jul 23, 2014 at 5:11 AM
I don`t know witch property set ,can alert this error.....
Jul 23, 2014 at 5:13 AM
            //Feeder
            if ((this._twain32.IsCapSupported(TwCap.Duplex) & TwQC.Get) != 0)
            {
                var _duplexCapValue = (TwDX)this._twain32.GetCap(TwCap.Duplex);
                if (_duplexCapValue != TwDX.None)
                {
                    if ((this._twain32.IsCapSupported(TwCap.FeederEnabled) & TwQC.Set) != 0)
                    {
                        this._twain32.SetCap(TwCap.FeederEnabled, true);

                        if ((this._twain32.IsCapSupported(TwCap.XferCount) & TwQC.Set) != 0)
                        {
                            this._twain32.SetCap(TwCap.XferCount, -1);

                            if ((this._twain32.IsCapSupported(TwCap.DuplexEnabled) & TwQC.Set) != 0)
                            {
                                this._twain32.SetCap(TwCap.DuplexEnabled, true);
                            }
                        }
                    }
                }
            }

            //Brightness
            if ((this._twain32.IsCapSupported(TwCap.Brightness) & TwQC.Set) != 0)
            {
                this._twain32.SetCap(TwCap.Brightness, _rightness); //Allowed Values: -1000f to +1000f; Default Value: 0f;
            }

            //Contrast
            if ((this._twain32.IsCapSupported(TwCap.Contrast) & TwQC.Set) != 0)
            {
                this._twain32.SetCap(TwCap.Contrast, _contrast); //Allowed Values: -1000f to +1000f; Default Value: 0f;
            }

            //Iunits
            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.IUnits) & TwQC.Get) != 0)
            {
                object o = this._twain32.GetCap(Saraff.Twain.TwCap.IUnits);
                Saraff.Twain.Twain32.Enumeration ot = (Saraff.Twain.Twain32.Enumeration)o;
                _pixunit.Clear();
                for (int ii = 0; ii < ot.Count; ii++)
                {
                    switch ((UInt16)ot[ii])
                    {
                        case 0:
                            _pixunit.Add(0, TwUnits.Inches);
                            break;
                        case 1:
                            _pixunit.Add(1, TwUnits.Centimeters);
                            break;
                        case 2:
                            _pixunit.Add(2, TwUnits.Picas);
                            break;
                        case 3:
                            _pixunit.Add(3, TwUnits.Points);
                            break;
                        case 4:
                            _pixunit.Add(4, TwUnits.Twips);
                            break;
                        case 5:
                            _pixunit.Add(5, TwUnits.Pixels);
                            break;
                        case 6:
                            _pixunit.Add(6, TwUnits.Millimeters);
                            break;
                    }
                }
            }

            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.IUnits) & TwQC.Set) != 0)
            {
                if (_pixunit[0] != null)
                {
                    this._twain32.SetCap(Saraff.Twain.TwCap.IUnits, (TwUnits)_pixunit[0]);
                    _punit = (TwUnits)_pixunit[0];
                }
                else if (_pixunit[5] != null)
                {
                    this._twain32.SetCap(Saraff.Twain.TwCap.IUnits, (TwUnits)_pixunit[5]);
                    _punit = (TwUnits)_pixunit[5];
                }
                else if (_pixunit[1] != null)
                {
                    this._twain32.SetCap(Saraff.Twain.TwCap.IUnits, (TwUnits)_pixunit[1]);
                    _punit = (TwUnits)_pixunit[1];
                }
                else if (_pixunit[6] != null)
                {
                    this._twain32.SetCap(Saraff.Twain.TwCap.IUnits, (TwUnits)_pixunit[6]);
                    _punit = (TwUnits)_pixunit[6];
                }
            }

            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.AutomaticBorderDetection) & TwQC.Set) != 0)
            {
                this._twain32.SetCap(Saraff.Twain.TwCap.AutomaticBorderDetection, true);
            }

            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.XResolution) & TwQC.Set) != 0)
            {
                this._twain32.Capabilities.XResolution.Set(_resolutions);
            }

            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.YResolution) & TwQC.Set) != 0)
            {
                this._twain32.Capabilities.YResolution.Set(_resolutions);
            }
            //this._twain32.Capabilities.XResolution.Set(_resolutions);
            //this._twain32.Capabilities.YResolution.Set(_resolutions);

            this._twain32.ImageLayout = new RectangleF(_imagex, _imagey, _imagewidth, _imageheight);


            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.IPixelType) & TwQC.Set) != 0)
            {
                this._twain32.Capabilities.PixelType.Set(TwPixelType.Gray);
            }
            //this._twain32.Capabilities.PixelType.Set(TwPixelType.Gray);

            if ((this._twain32.IsCapSupported(Saraff.Twain.TwCap.IXferMech) & TwQC.Set) != 0)
            {
                this._twain32.Capabilities.XferMech.Set(_trustion);
            }
            //this._twain32.Capabilities.XferMech.Set(_trustion);
Coordinator
Jul 23, 2014 at 8:30 AM
Hello, JohnnyLeung!
Try follow code to see the list of supported capabilities:
System.Diagnostics.Debug.WriteLine("SupportedCaps:");
foreach(ushort _item in this._twain32.GetCap(TwCap.SupportedCaps) as object[]) {
    TwCap _cap=(TwCap)_item;
    System.Diagnostics.Debug.Write(string.Format("{0}: ", _cap).PadRight(25));
    System.Diagnostics.Debug.WriteLine(this._twain32.IsCapSupported(_cap));
}
Marked as answer by JohnnyLeung on 7/23/2014 at 10:33 AM
Jul 23, 2014 at 5:33 PM
Thx
Sep 10, 2014 at 6:33 PM
Hi Saraff
I used this code to get all scanner capabilities but even I get an array of tens of values for all of them I get 0 as IsCapSuppoted.
I checked the code and I get Failure from
TwRC _rc=this._dsmEntry.DsInvoke(this.AppId,this._srcds,TwDG.Control,TwDAT.Capability,TwMSG.QuerySupport,ref _cap);
in IsCapSupported for all values except for SupportedCaps.

I'm using a Fujitsu fi-7160 and his TWAIN driver.

With other scanner like Canon Lide 210 everything is ok.

What's wrong ?
Than you
Domenico
Coordinator
Sep 10, 2014 at 8:46 PM
Hello, dbarile.
This data source (for Fujitsu fi-7160) is to blame. Apparently, it does not implement a triplet DG_CONTROL / DAT_CAPABILITY / MSG_QUERYSUPPORT.
Sep 11, 2014 at 8:16 AM
Hi SARAFF,
what should I do ?
Even if I use ShowUI=true I couldn't get images !

Thank you
Domenico
Coordinator
Sep 11, 2014 at 10:56 AM
Hello, dbarile.
Please provide details about the problem.
Sep 12, 2014 at 11:01 AM
Hi Saraff
with this code
TwainInterface.OpenDSM();
TwainInterface.SelectSource();
TwainInterface.ShowUI = true;
TwainInterface.Acquire();
The scanner get the page but at the end of scanning the AcquireError event if fired with those AcquireErrorEventArgs
Exception {"Parameter is not valid."}
    base    {"Parameter is not valid."} 
    ConditionCode   Success 
    ReturnCode  Success 
If I try with TwainSample2, I could select the scanner (WIA fi-7160) but when I press NEW button the scanner doesn't get the page.
Even if I set ShouUI to true.

Tell me what I could do to give you more information.
Thank you!
Domenico
Coordinator
Sep 12, 2014 at 11:59 AM
Hello, dbarile.
Please, show value of the property AcquireErrorEventArgs.TwainException.StackTrace in the event AcquireError.
And if AcquireErrorEventArgs.TwainException.InnerException is not null then AcquireErrorEventArgs.TwainException.InnerException.StackTrace.
However, the problem is likely associated with the scanner driver (the data source).
Sep 12, 2014 at 3:10 PM
Hi Saraff,
the StackTrace is null.
InnerException is System.ArgumentException - "Parameter is not valid"
and his StackTrace is
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at Saraff.Twain.DibToImage.WithStream(IntPtr dibPtr) in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\DibToImage.cs:line 64
at Saraff.Twain.Twain32._NativeTransferPictures() in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\Twain32.cs:line 986
at Saraff.Twain.Twain32._TwCallbackProcCore(TwMSG msg, MethodInvoker endAction) in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\Twain32.cs:line 1211
at Saraff.Twain.Twain32._MessageFilter.PreFilterMessage(Message& m) in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\Twain32.cs:line 2137

The driver seems ok: I could use it with Adobe Acrobat, Paint .NET and with his applications.

Thank you
Domenico
Coordinator
Sep 12, 2014 at 4:56 PM
Hello, dbarile.
Modify (for debugging) file DibToImage.cs as show below
File.WriteAllBytes(@"c:\image.bmp",_stream.ToArray()); //new line
return Image.FromStream(_stream); //line 64 of DibToImage.cs
Send to me the image.bmp file.
Sep 12, 2014 at 5:22 PM
It doesn't execute those instructions.
Tracying code I saw that the exception was thrown from line 964 of Twain32.cs
Coordinator
Sep 12, 2014 at 5:49 PM
You wrote:
at Saraff.Twain.DibToImage.WithStream(IntPtr dibPtr) in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\DibToImage.cs:line 64
Sep 12, 2014 at 6:52 PM
Edited Sep 12, 2014 at 6:52 PM
You are right!
Sometimes I have the different exceptions (thrown from line 964 of Twain32.cs).

I got the images and I saved at https://dl.dropboxusercontent.com/u/7750952/image.bmp

Thank you for you support!
Coordinator
Sep 12, 2014 at 10:16 PM
Hello, dbarile.
Try latest source code.
Sep 13, 2014 at 6:45 PM
Hello Saraff,
with latest source code I get AcquireError with e.Message = "It worked!" and StackTrace =
at Saraff.Twain.Twain32._NativeTransferPictures() in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\Twain32.cs:line 980
at Saraff.Twain.Twain32._TwCallbackProcCore(TwMSG msg, MethodInvoker endAction) in c:\Sviluppo\Progetti .NET\PdfCaptureManager\Saraff.Twain\Twain32.cs:line 1196
InnerException is null.

I checked the image in DibToImage - WithStream and now it's correct.

Thenk you
Coordinator
Sep 13, 2014 at 7:16 PM
Hello, dbarile.
Please, show value of the property AcquireErrorEventArgs.TwainException.ConditionCode and AcquireErrorEventArgs.TwainException.ReturnCode.
Sep 14, 2014 at 2:22 PM
ConditionCode = Success
ReturnCode = Cancel
Coordinator
Sep 14, 2014 at 5:39 PM
Hello, dbarile.
This suggests that you canceled the scanning operation.
Native Mode Transfer
The Return Code / Condition Code returned from the DG_IMAGE / DAT_IMAGENATIVEXFER / MSG_GET operation may indicate one of these actions occurred.
If the Return Code is TWRC_XFERDONE:
This indicates the transfer was completed and the session is in State 7. However, it does not guarantee that the Source did not clip the image to make it fit. Even if the application issued a DG_IMAGE / DAT_IMAGEINFO / MSG_GET operation prior to the transfer to determine the image size, it cannot assume that the ImageWidth and ImageLength values returned from that operation really apply to the image that was ultimately transferred. If the dimensions of the image are important to the application, the application should always check the actual transferred image size after the transfer is completed. To do this:
  1. Execute a DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER operation to move the session from State 7 to State 6 (or 5).
  2. Determine the actual size of the image that was transferred by reading the header of the actual image data transferred. See Chapter 12, "Operating System Dependencies" for more information.
If the Return Code is TWRC_CANCEL:
The acquisition was canceled by the user. The session is in State 7. Execute a DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER operation to move the session from State 7 to State 6 (or 5).
If the Return Code is TWRC_FAILURE:
Check the Condition Code to determine the cause of the failure. The session is in State 6. No memory was allocated for the DIB or PICT. The image is still pending. If lack of memory was the cause, you can try to free additional memory or discard the pending image by executing DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER.
[TWAIN 2.2 Specification. 4-16]
Sep 15, 2014 at 10:04 AM
Hello Saraff
obiously I'm not canceling the scanning operation.
The fi-7160 driver is based on TWAIN & ISIS one and it implements images enhancement that could be the cause of those problem.

I will try to understand with Fujitsu if there is a "native" twain driver.

Thank you for you quick and significant support.
Domenico