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

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
Posts: 1
Joined: Mon Mar 22, 2021 9:16 pm

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

Post by DavidC » Mon Mar 22, 2021 9:56 pm


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;
		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);

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



Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest