Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Apr 20, 2023 · 6 comments

Comments

@l585826
Copy link

l585826 commented Apr 20, 2023

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

@dynarithmic
Copy link
Owner

dynarithmic commented Apr 20, 2023

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.

@dynarithmic dynarithmic changed the title 在有自动馈纸器的扫描仪上,如果打开了消息通知,并且在扫描过程中发生卡纸,会收到DTWAIN_TN_PAGEFAILED代码,但是消息通知回调一直不停的被调用 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在有自动馈纸器的扫描仪上,如果打开了消息通知,并且在扫描过程中发生卡纸,会收到DTWAIN_TN_PAGEFAILED代码,但是消息通知回调一直不停的被调用 Apr 20, 2023
@dynarithmic dynarithmic changed the title 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在有自动馈纸器的扫描仪上,如果打开了消息通知,并且在扫描过程中发生卡纸,会收到DTWAIN_TN_PAGEFAILED代码,但是消息通知回调一直不停的被调用 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 Apr 20, 2023
@l585826
Copy link
Author

l585826 commented Apr 21, 2023

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
Copy link
Owner

dynarithmic commented Apr 21, 2023

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
Copy link
Author

l585826 commented Apr 23, 2023

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
Copy link
Owner

dynarithmic commented Apr 23, 2023

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
Copy link
Owner

dynarithmic commented Apr 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants