dynarithmic / twain_library

Dynarithmic TWAIN Library, Version 5.x
Apache License 2.0
56 stars 24 forks source link

On a scanner with an automatic document feeder, if the message notification is turned on and a paper jam occurs during the scanning process, the DTWAIN_TN_PAGEFAILED code will be received, but the message notification callback keeps being called #54

Open l585826 opened 1 year ago

l585826 commented 1 year ago

我不确定我的解决方案是否合理,甚至看着有点粗暴,但是确实解决消息通知回调被不停的调用问题,我在DTWAIN_TN_PAGEFAILED回调代码中使用DTWAIN_EnableMsgNotify(0)把消息通知关掉了,在下一次进行扫描时打开。另外我使用的语言是python

dynarithmic commented 1 year ago

Please note that the language that should be used in the Issues section should be English.

If I translate the text to English, I see this:

On a scanner with an automatic document feeder, if the message notification is turned on and a paper jam occurs during the scanning process, the DTWAIN_TN_PAGEFAILED code will be received, but the message notification callback keeps being called.

1) What is the model of the scanner? 2) Please produce a DTWAIN log of the scanning process.

l585826 commented 1 year ago

Thank you for your reply. The scanner model is HP LaserJet M1536dnf MFP. The Python program code is: TESTERR.PY.txt

The log is: log.txt

Question 2: In multi page scanning, after scanning the first page, a paper jam occurred while scanning the second page,No DTWAIN_TN_PAGEFAILED notification.But restarting the program,there will always be DTWAIN_TN_PAGEFAILED notification。 The Question 2 log is: log.txt

dynarithmic commented 1 year ago

As a test, in the Python program, try this:

  elif wparam == DTWAIN32.DTWAIN_TN_PAGEFAILED:
       print('DTWAIN_TN_PAGEFAILED')
       # mydll.DTWAIN_EnableMsgNotify(0)
       return 0

The return 0 should terminate the scanning session instead of retrying (that is what the return code of 1 will do). Does this stop the failure from occuring? If this doesn't work, try return 2 to see if that changes anything.

It looks like the driver does not reset itself on a paper jam, and maybe the only way to reset the driver is to probably close the source using DTWAIN_CloseSource() and reopen it again.

This is just a guess, and I would need the scanner in-house to really test this.

Since I do not have the scanner available, there is only one place in the source code where DTWAIN sends out the DTWAIN_TN_PAGEFAILED, and that is after an attempt of scanning the page is done, so this is relatively simple to figure out if you build the source code. If this is an option, let me know and I will guide you as to where to look in the code.

l585826 commented 1 year ago
elif wparam == `DTWAIN32.DTWAIN_TN_PAGEFAILED:
print('DTWAIN_TN_PAGEFAILED')
# mydll.DTWAIN_EnableMsgNotify(0)
return 0

The return 0 fault still occurs,but return 2 stopped the fault from occurring ,the DTWAIN_TN_PAGEFAILED notification received four times. The Question 2 solved.

images = mydll.DTWAIN_AcquireNative(
                TwainSource,                    #Source Specifies a selected TWAIN Source
                DTWAIN32.DTWAIN_PT_DEFAULT,     #PixelType Specifies the pixel type of the image
                1,                              #NumPages Specifies the number of pages to acquire   DTWAIN32.DTWAIN_MAXACQUIRE
                False,                          #bShowUI Specifies whether the Source displays the default User Interface.
                True,                           #bCloseSource Specifies whether the Source should be automatically closed when the User Interface is closed.
                byref(error_info)               #pStatus Points to a variable that will be filled in with an error status value or NULL if no error status is desired.
            )

Change the code to:

images = mydll.DTWAIN_AcquireNative(
                TwainSource,                    #Source Specifies a selected TWAIN Source
                DTWAIN32.DTWAIN_PT_DEFAULT,     #PixelType Specifies the pixel type of the image
                DTWAIN32.DTWAIN_MAXACQUIRE,                              #NumPages Specifies the number of pages to acquire   DTWAIN32.DTWAIN_MAXACQUIRE
                False,                          #bShowUI Specifies whether the Source displays the default User Interface.
                True,                           #bCloseSource Specifies whether the Source should be automatically closed when the User Interface is closed.
                byref(error_info)               #pStatus Points to a variable that will be filled in with an error status value or NULL if no error status is desired.
            )

,after scanning the first page, a paper jam occurred while scanning the second page,the DTWAIN_TN_PAGEFAILED notification received four times,Received DTWAIN_TN_QUERYPAGEDISCARD notification only after all page scans were completed,but I don't know why.I want to scan a page and obtain an image. What should I do?I have read the code for this library,I couldn't find the location to handle the callback return value,can you tell me? Thank you very much again!

dynarithmic commented 1 year ago

I made some changes to the DTWAIN_TN_PAGEFAILED notification and placed them in the development branch. Please try the development DLL's available here for 32-bit and here for 64bit.

As to the location of where the DTWAIN_TN_PAGEFAILED is issued, it is here.

dynarithmic commented 1 year ago

Also, I highly suggest that you not attempt anything after the paper jam, as the behavior is highly dependent on how your driver handles paper jams when something occurs.

In the case of a paper jam that occurs after many pages have been scanned successfully, I suggest you use DTWAIN_SetMultipageScanMode and specify you want to save the pages when the source is closed. This way, you will still have the pages that scanned successfully saved to the multipage file when the source or source UI is closed.

As stated on the help page:

_by default, DTWAIN will not save image files if the acquisition has been canceled by the user, application, or TWAIN driver. This can also be overridden by DTWAIN_SetMultipageScanMode._

Also, I suggest you attempt this with the UI on, not off, and see exactly what the UI of the device does when a paper jam occurs. Right now, you are not sure of the feedback when a jam occurs by running with the UI turned off.