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

TransferError event is not raised for Paperjam and other errors in source #34

Open
reachgauravm opened this issue Dec 23, 2022 · 5 comments

Comments

@reachgauravm
Copy link

reachgauravm commented Dec 23, 2022

We have built a custom application using NTwain to scan documents. When testing the application, we find that when an error is encountered on device side, like a paper jam, error handler event (TransferError) is raised for some scanners but it is not raised for some other scanners. Seeing this problem especially when using Canon model number, DR-G1130 and associated driver. Driver UI has been disabled by setting ShowUI and CAP_INDICATORS to false in source's capabilities. Is this an issue with NTwain or is a workaround possible to overcome this.

@soukoku
Copy link
Owner

soukoku commented Dec 23, 2022

Does it support CAP_DEVICEEVENT to set the ones you want to know and later can listen to in session's DeviceEvent? If it doesn't then I'm not sure how else you can know about it when it doesn't report the condition in the transfer calls like the spec says.

@reachgauravm
Copy link
Author

reachgauravm commented Jan 2, 2023

Thanks @soukoku. We tried subscribing to CAP_DEVICEEVENT and did not see the handler getting invoked with any scanner. I am unsure if we subscribed correctly though. This is how we set the ones we are interested in handling:

var twain = new TwainSession(TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetExecutingAssembly()));
var hit = twain.FirstOrDefault();
hit.Capabilities.CapDeviceEvent.SetValue(DeviceEvent.PowerSaveNotify);
hit.Capabilities.CapDeviceEvent.SetValue(DeviceEvent.DeviceOffline);
hit.Capabilities.CapDeviceEvent.SetValue(DeviceEvent.PaperDoubleFeed);
hit.Capabilities.CapDeviceEvent.SetValue(DeviceEvent.PaperJam);

and attach a handler like this

twain.DeviceEvent += (s, e) =>
            {
                string deviceEvt = e.DeviceEvent.Event.ToString();
                PlatformInfo.Current.Log.Info("Device Event value is: " + deviceEvt);
            };

Is this the right way of implementing. I searched around but could not find a sample to set and subscribe to the device event and hence posted a code sample.

@reachgauravm
Copy link
Author

@soukoku - Can you please clarify how does NTwain handle error events?
For instance:

  • Return value for a Twain command?
  • DAT_NULL message (callback system of TWAIN) ?
  • Or something else?

@Scoria92
Copy link

Hello @soukoku ,
I have the same problem as @reachgauravm that no TransferErrorEvent or DeviceEvent is raised if a paper jam occurs or any other error occurs.

In my service the session is opened without a window handle so the internal message loop of NTwain is used. However the actual scanning process with twain is not executed in the main thread because the service handles another requests as well. Could this setup lead to a problem that the session is not created in the main thread and the error events cannot be raised properly?

Regards

@fichtip2
Copy link

I have the same problem. In my case if there is a paper jam (or I simply open the scanner) the session gets stuck in state 6. Even session.forceStepDown does not change the state. If I try to initiate another scan it failes when trying to open the data source (return code 1 'Failure').

Sadly, the only "solution" to get it working again is to reboot the computer.

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

4 participants