Page 1 of 1

Detecting a paper jam when TwainGetLastConditionCode method doesn't seem to work?

Posted: Mon Mar 22, 2021 9:56 pm
by DavidC
Hi,

I developed a simple C# Winforms app to use with a Canon DR-M140 office document scanner. Here's what I'm trying to accomplish:

1. User scans a packet of 10 pages.
2. A paper jam occurs; detect the jam and pause scanning.
3. Advise the user a paper jam occurred. After he clears the jam, let him resume scanning.

I'm stuck on # 2, detecting the jam. I "know" I should use the GdPictureImaging.TwainGetLastConditionCode class method after calling the GdPictureImaging.TwainAcquireToGdPictureImage class method. However, I'm always getting a GdPicture14.TwainConditionCode.TWCC_SUCCESS code, never a TWCC_PAPERJAM code.

I understand this could be because my scanner doesn't communicate this via TWAIN (possibly). However, I am getting a windows message box error outside of my code which advised "Paper jammed in scanner; clear paper and continue.(-4426)". So this seems to indicate the scanner is communicating the paper jam to Windows, so why can't I pick it up in my C# code? What could I be doing wrong?

Here's a simplified snippet of the code where I'd like to catch the paper jam:

Code: Select all

TwainConditionCode lastConditionCode;
TwainStatus lastTwainState;
do
{
	try
	{
		imageId = _gdPictureImaging.TwainAcquireToGdPictureImage(this.Handle);
		// I set a breakpoint here to see if these change to an interesting status.
		lastConditionCode = _gdPictureImaging.TwainGetLastConditionCode();
		lastTwainState = _gdPictureImaging.TwainGetState();
	}
	catch (Exception ex)
	{
		// An exception is never thrown here by .NET.
		throw ex;
	}

	if (imageId != 0)
	{
		var filepath = Path.GetTempFileName();
		filepath = filepath.Replace(".tmp", ".tif");
		_gdPictureImaging.SaveAsTIFF(imageId, filepath, TiffCompression.TiffCompressionAUTO);
		_gdPictureImaging.ReleaseGdPictureImage(imageId);

	}
}
while (_gdPictureImaging.TwainGetState() > TwainStatus.TWAIN_SOURCE_ENABLED);

_gdPictureImaging.TwainCloseSource();
Thanks!

David

Re: Detecting a paper jam when TwainGetLastConditionCode method doesn't seem to work?

Posted: Wed Aug 18, 2021 9:27 am
by Fabio
Hello David,

The issue has been reported to our developer team. I'll keep you posted here on any updates.

With best,
Fabio