soukoku / ntwain

A TWAIN lib for dotnet.
MIT License
117 stars 47 forks source link

Error 27 when updating scanner settings #48

Open Mister-Genius opened 10 months ago

Mister-Genius commented 10 months ago

We have built an application that needs to scan documents and the end user also needs to be able to update the scanner settings from the driver. We have 2 different scanners and on the KODAK scanner it works but on out Canon scanners (DRG2090) there is a generic error when changing settings.

We can open the settings it works and then when we close them and try to open again it crashes with an error 27. This only happens on the Canon, the KODAK works without any problems. All the other functionalities work without a problem on both scanners.

screenshot

Mister-Genius commented 9 months ago

Fixed this issue. _twain.CurrentSource.Enable(SourceEnableMode.ShowUIOnly, true, IntPtr.Zero);

Previous dev had this set to: _twain.CurrentSource.Enable(SourceEnableMode.ShowUIOnly, false, IntPtr.Zero);

But this is not allowed on Windows machines as stated in the Twain documentation.

_ On Windows - It is not recommended to set this field to TRUE. The Source may ignore this value and use FALSE if it is version 2.1 or lower. If both Source and the Application are 2.2 or higher, then the Source must return TWRCCHECKSTATUS if it does not support requested value

ljchengx commented 6 months ago

@Mister-Genius At present, when the model 2090 is used, there will still be an error of -27. Have you encountered it? code: m_twain_source.Enable(SourceEnableMode.NoUI, false, this.Handle)

ljchengx commented 6 months ago

@ljchengx vsersion is 3.7.0

jidesheng6 commented 5 months ago

@ljchengx If you have this piece of code in your code: NTwain.PlatformInfo.Current.PreferNewDSM = false; You can try commenting it out, or changing fase to true; I get the same 27 error code on my 2090s, and it hasn't come up since I canceled the above code; guessing it's because the 2090s has a newer driver, and twaindsm below version 2.1 might be getting some information wrong. If you're a winform program, you may have scaling issues with the newer twaindsm (when you have DPI-aware configuration enabled, it's recommended to disable it), if you don't care about the scaling issues, you can ignore what I said!

I haven't tested it on an older machine, like a g1100, but I don't think it will be too much of a problem.

jidesheng6 commented 5 months ago

@ljchengx 如果你的代码中有这一段代码:NTwain.PlatformInfo.Current.PreferNewDSM = false; 你可以尝试注释它,或者将fase更改为true;我的2090s也是一样会遇到27错误代码,我取消了上述代码后,它就没有出现过了;猜测应该是2090s的驱动比较新,低于2.1版本的twaindsm可能获取某些信息出错了。如果你是winform程序,使用新的twaindsm可能会出现缩放问题(当你启用了DPI感知配置,建议取消它),如果你不在乎缩放问题,可以忽略我说的

我没有在比较老的机器上测试,比如g1100,不过我觉得不会有太大的问题。

jidesheng6 commented 5 months ago

@ljchengx 而且enable那块一定要使用false,windows上使用true的话,可能会导致驱动没反应,这两天我试过了。