Closed ostasevych closed 6 months ago
This is again an issue with the data source, but fortunately SANEWinDS (unlike SaneTwain) is open source, so I was able to make some fixes. Hopefully the author is able to merge them, but in the meantime if you like you can trying taking this SANEWinDS.dll and replacing it in the C:\Windows\twain_32\SANEWinDS
folder.
This is again an issue with the data source, but fortunately SANEWinDS (unlike SaneTwain) is open source, so I was able to make some fixes. Hopefully the author is able to merge them, but in the meantime if you like you can trying taking this SANEWinDS.dll and replacing it in the
C:\Windows\twain_32\SANEWinDS
folder.
Thanks! I've tested and see that nothing changed significantly. Should I replace the file in the folder "C:\Program Files(x86)\SaneWinDS" as well?
System.Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
Server stack trace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at DS_EntryWrapper.Message_To_DS(DS_EntryWrapper* , TW_IDENTITY* _pOrigin, UInt32 _DG, UInt32 _DAT, UInt16 _MSG, Void* _pData)
at NTwain.Triplets.Dsm.NativeMethods.DsmWinNew(TWIdentity origin, TWIdentity destination, DataGroups dg, DataArgumentType dat, Message msg, TWUserInterface data)
at NTwain.Triplets.Dsm.DsmEntry(TWIdentity origin, TWIdentity destination, Message msg, TWUserInterface data)
at NTwain.Triplets.UserInterface.EnableDS(TWUserInterface userInterface)
at NTwain.TwainSession.<>c__DisplayClass128_0.<NTwain.Internals.ITwainSessionInternal.EnableSource>b__0()
at NTwain.MessageLoopHook.<>c__DisplayClass11_0.<Invoke>b__0(Object o)
Exception rethrown at [0]:
at NTwain.MessageLoopHook.Rethrow(Exception ex)
at NTwain.MessageLoopHook.Invoke(Action action)
at NTwain.TwainSession.NTwain.Internals.ITwainSessionInternal.EnableSource(SourceEnableMode mode, Boolean modal, IntPtr windowHandle)
at NTwain.DataSource.Enable(SourceEnableMode mode, Boolean modal, IntPtr windowHandle)
at NAPS2.Scan.Internal.Twain.TwainSessionScanRunner.Init()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NAPS2.Scan.Internal.Twain.LocalTwainSessionController.<InternalScan>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NAPS2.Scan.Internal.Twain.LocalTwainSessionController.<StartScan>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NAPS2.Remoting.Worker.WorkerServiceImpl.<TwainScan>d__21.MoveNext()
at void NAPS2.Remoting.RemotingHelper.HandleErrors(Error error)
at async Task NAPS2.Remoting.Worker.WorkerServiceAdapter.TwainScan(ScanOptions options, CancellationToken cancelToken, ITwainEvents twainEvents)
at async Task NAPS2.Scan.Internal.Twain.RemoteTwainSessionController.StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken)
at async Task NAPS2.Scan.Internal.Twain.TwainScanDriver.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<IMemoryImage> callback)+(?) => { }
at async Task NAPS2.Scan.Internal.RemoteScanController.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<ProcessedImage, PostProcessingContext> callback)
at async Task NAPS2.Scan.ScanController+<>c__DisplayClass13_1.<Scan>g__DoScan|6(?)+DoScan(?)
at async IAsyncEnumerable<ProcessedImage> NAPS2.Scan.ScanController.Scan(ScanOptions options, CancellationToken cancelToken)+(?) => { }
Oops sorry I think I uploaded the wrong build, please try this one instead: SANEWinDS.zip
You might need to right click -> Properties on the DLL and select "Unblock" to get Windows to allow it to run.
You can also update to NAPS2 7.4.0 as it will provide a bit more useful error messages.
Oops sorry I think I uploaded the wrong build, please try this one instead: SANEWinDS.zip
You might need to right click -> Properties on the DLL and select "Unblock" to get Windows to allow it to run.
You can also update to NAPS2 7.4.0 as it will provide a bit more useful error messages.
So, what I've done:
TESTS:
test with default
mode:
Exception UI:
System.ArgumentException: Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0
at void NAPS2.Scan.Internal.Twain.TwainMemoryBufferReader.CopyBufferToImage(TwainMemoryBuffer memoryBuffer, TwainImageData imageData, IMemoryImage outputImage)
at void NAPS2.Scan.Internal.Twain.TwainImageProcessor.MemoryBufferTransferred(TwainMemoryBuffer memoryBuffer)
at async Task NAPS2.Remoting.Worker.WorkerServiceAdapter.TwainScan(ScanOptions options, CancellationToken cancelToken, ITwainEvents twainEvents)
at async Task NAPS2.Scan.Internal.Twain.RemoteTwainSessionController.StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken)
at async Task NAPS2.Scan.Internal.Twain.TwainScanDriver.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<IMemoryImage> callback)+(?) => { }
at async Task NAPS2.Scan.Internal.RemoteScanController.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<ProcessedImage, PostProcessingContext> callback)
at async Task NAPS2.Scan.ScanController+<>c__DisplayClass13_1.<Scan>g__DoScan|6(?)+DoScan(?)
at async IAsyncEnumerable<ProcessedImage> NAPS2.Scan.ScanController.Scan(ScanOptions options, CancellationToken cancelToken)+(?) => { }
in debug.log
:
2024-03-11 14:41:16.4351 11028 Debug: Using new dsm.
2024-03-11 14:41:16.6112 11028 Using TWAIN DSM: D:\Users\Ostasevych\Downloads\software\naps2-testtwain\App\lib\_win32\twaindsm.dll
2024-03-11 14:41:16.6229 11028 NAPS2.TW - Opening session
2024-03-11 14:41:16.6401 11028 Debug: Thread 1: OpenManager.
2024-03-11 14:41:18.7163 20676 Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0 System.ArgumentException: Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0
at void NAPS2.Scan.Internal.Twain.TwainMemoryBufferReader.CopyBufferToImage(TwainMemoryBuffer memoryBuffer, TwainImageData imageData, IMemoryImage outputImage)
at void NAPS2.Scan.Internal.Twain.TwainImageProcessor.MemoryBufferTransferred(TwainMemoryBuffer memoryBuffer)
at async Task NAPS2.Remoting.Worker.WorkerServiceAdapter.TwainScan(ScanOptions options, CancellationToken cancelToken, ITwainEvents twainEvents)
at async Task NAPS2.Scan.Internal.Twain.RemoteTwainSessionController.StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken)
at async Task NAPS2.Scan.Internal.Twain.TwainScanDriver.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<IMemoryImage> callback)+(?) => { }
at async Task NAPS2.Scan.Internal.RemoteScanController.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<ProcessedImage, PostProcessingContext> callback)
at async Task NAPS2.Scan.ScanController+<>c__DisplayClass13_1.<Scan>g__DoScan|6(?)+DoScan(?)
at async IAsyncEnumerable<ProcessedImage> NAPS2.Scan.ScanController.Scan(ScanOptions options, CancellationToken cancelToken)+(?) => { }
2024-03-11 14:41:25.0825 20676 Killing unresponsive worker
test with the memory
mode:
Exception in UI:
System.ArgumentException: Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0
at void NAPS2.Scan.Internal.Twain.TwainMemoryBufferReader.CopyBufferToImage(TwainMemoryBuffer memoryBuffer, TwainImageData imageData, IMemoryImage outputImage)
at void NAPS2.Scan.Internal.Twain.TwainImageProcessor.MemoryBufferTransferred(TwainMemoryBuffer memoryBuffer)
at async Task NAPS2.Remoting.Worker.WorkerServiceAdapter.TwainScan(ScanOptions options, CancellationToken cancelToken, ITwainEvents twainEvents)
at async Task NAPS2.Scan.Internal.Twain.RemoteTwainSessionController.StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken)
at async Task NAPS2.Scan.Internal.Twain.TwainScanDriver.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<IMemoryImage> callback)+(?) => { }
at async Task NAPS2.Scan.Internal.RemoteScanController.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<ProcessedImage, PostProcessingContext> callback)
at async Task NAPS2.Scan.ScanController+<>c__DisplayClass13_1.<Scan>g__DoScan|6(?)+DoScan(?)
at async IAsyncEnumerable<ProcessedImage> NAPS2.Scan.ScanController.Scan(ScanOptions options, CancellationToken cancelToken)+(?) => { }
in debug.log:
2024-03-11 14:42:18.7181 20676 Killing unresponsive worker
2024-03-11 14:42:24.5590 10896 Debug: Using new dsm.
2024-03-11 14:42:24.6447 10896 Using TWAIN DSM: D:\Users\Ostasevych\Downloads\software\naps2-testtwain\App\lib\_win32\twaindsm.dll
2024-03-11 14:42:24.6568 10896 NAPS2.TW - Opening session
2024-03-11 14:42:24.6707 10896 Debug: Thread 1: OpenManager.
2024-03-11 14:42:26.3021 20676 Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0 System.ArgumentException: Unsupported pixel type: 48 2 3 16,16,16,0,0,0,0,0
at void NAPS2.Scan.Internal.Twain.TwainMemoryBufferReader.CopyBufferToImage(TwainMemoryBuffer memoryBuffer, TwainImageData imageData, IMemoryImage outputImage)
at void NAPS2.Scan.Internal.Twain.TwainImageProcessor.MemoryBufferTransferred(TwainMemoryBuffer memoryBuffer)
at async Task NAPS2.Remoting.Worker.WorkerServiceAdapter.TwainScan(ScanOptions options, CancellationToken cancelToken, ITwainEvents twainEvents)
at async Task NAPS2.Scan.Internal.Twain.RemoteTwainSessionController.StartScan(ScanOptions options, ITwainEvents twainEvents, CancellationToken cancelToken)
at async Task NAPS2.Scan.Internal.Twain.TwainScanDriver.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<IMemoryImage> callback)+(?) => { }
at async Task NAPS2.Scan.Internal.RemoteScanController.Scan(ScanOptions options, CancellationToken cancelToken, IScanEvents scanEvents, Action<ProcessedImage, PostProcessingContext> callback)
at async Task NAPS2.Scan.ScanController+<>c__DisplayClass13_1.<Scan>g__DoScan|6(?)+DoScan(?)
at async IAsyncEnumerable<ProcessedImage> NAPS2.Scan.ScanController.Scan(ScanOptions options, CancellationToken cancelToken)+(?) => { }
2024-03-11 14:43:26.3154 20676 Killing unresponsive worker
3. Test with the `old DSM` mode:
no exception in UI it worked with numerous scanned pages till I broke the progress;
in debug.log:
2024-03-11 14:44:16.8522 24784 Debug: Using old dsm in windows. not C:\WINDOWS\system32\twaindsm.dll 2024-03-11 14:44:16.9865 24784 Using TWAIN DSM: C:\WINDOWS\twain_32.dll 2024-03-11 14:44:16.9949 24784 NAPS2.TW - Opening session 2024-03-11 14:44:16.9949 24784 Debug: Thread 1: OpenManager. 2024-03-11 14:44:17.0386 24784 NAPS2.TW - StateChanged (to 3) 2024-03-11 14:44:17.0386 24784 NAPS2.TW - Finding source 2024-03-11 14:44:25.3412 20676 NAPS2.TW - Sending cancel event
![image](https://github.com/cyanfish/naps2/assets/5199030/f33c568b-a9d8-44b3-9f25-98a8168e2a1f)
My SANEWinDS config files:
`SANEWinDS.ini`:
[Log] RetainDays=3
[General] INI_Version=0,8 Version=1.1.8600.41743 SaveDefaultsOnExit=True OptionValueSetMRU="{"test":"Local Defaults"}" [SANE] DefaultHost=3 [Host.3] NameOrAddress=192.168.232.250 UseTSClientIP=False Port=6566 Username= TCP_Timeout_ms=30000 Image_Timeout_s=1200 Device=test:0 AutoLocateDevice=test
`test.ini`:
[test.zip](https://github.com/cyanfish/naps2/files/14558790/test.zip)
PS So, it works! Later I will check it on other PCs with real scanners.
Indeed, I've had to unlock DLL file. If I place your modified DLL file to the folder with the SaneWinDS app the app doesn't work itself.
UPD Tested with old DSM on Canon MF3010 + SaneWinDS with your patch. It works!
Nice. Does the real scanner work with Default as the twain impl? The "Unsupported pixel type" error is because it's trying to scan 48-bit color but NAPS2 only supports 24-bit color. I'm not sure if that's a bug in SANEWinDS or in the test backend you were using to default to 48-bit.
Nice. Does the real scanner work with Default as the twain impl? The "Unsupported pixel type" error is because it's trying to scan 48-bit color but NAPS2 only supports 24-bit color. I'm not sure if that's a bug in SANEWinDS or in the test backend you were using to default to 48-bit.
Yes, it works with the default mode as well. I hope SaneWinDS devs will approve your PR as soon as possible, as it solves one of the major issues.
Meanwhile, is that possible to fix the wia driver as well? ;)
SANEWinDS version 1.2 has been published with those fixes and more, it seems to be working well now.
I am trying to find out a reliable twain client for windows, sanetwain doesn't want to work with native scanning, and needs to call scanimage every time, wia clears the settings after each restart of the client, and needs to change the id of device every time the client is restarted.
Finally I was trying to conquer SaneWinDS which has the most recent developments, and here I also failed. Modes
native
ormemory
constantly reports the error:in debug.log:
Though, SaneWinDS works fine as a standalone app. Tested with a test scanner sane service run in wsl2 on the same PC, as the client.