code_junkie

How do I check if the scanner is plugged in (C#, .NET TWAIN)

Nov 11th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. enum AcquireResult
  2. {
  3. OK = 0,
  4. InitFailed = 1,
  5. DeviceIDFailed = 2,
  6. CapabilityFailed = 3,
  7. UserInterfaceError = 4
  8. }
  9. private void StartScan()
  10. {
  11. if (!_msgFilter)
  12. {
  13. _parent.Enabled = false;
  14. _msgFilter = true;
  15. Application.AddMessageFilter(this);
  16. }
  17. AcquireResult ar = _twain.Acquire();
  18. if (ar != AcquireResult.OK)
  19. {
  20. EndingScan();
  21. switch (ar)
  22. {
  23. case AcquireResult.CapabilityFailed:
  24. throw new Exception("Scanner capability setup failed");
  25. case AcquireResult.DeviceIDFailed:
  26. throw new Exception("Unable to determine device identity");
  27. case AcquireResult.InitFailed:
  28. throw new Exception("Scanner initialisation failed");
  29. case AcquireResult.UserInterfaceError:
  30. throw new Exception("Error with the Twain user interface");
  31. default:
  32. throw new Exception("Document scanning failed");
  33. }
  34. }
  35. }
  36.  
  37. case TwainCommand.Null:
  38. {
  39. EndingScan();
  40. tw.CloseSrc();
  41. Msgbox("There is no device or the scannning has been cancelled.");
  42. break;
  43. }
Add Comment
Please, Sign In to add comment