Пример #1
0
        public override bool SelectDevice()
        {
            CommonDialogClass wiaCommonDialog = new CommonDialogClass();
            Device            device          = null;

            try
            {
                device = wiaCommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, true);
                if (device != null)
                {
                    m_DeviceID = device.DeviceID;
                    FillDeviceData(device);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (COMException ex)
            {
                if ((WiaScannerError)ex.ErrorCode == WiaScannerError.ScannerNotAvailable)
                {
                    return(false);
                }
                else
                {
                    WiaScannerException se = BuildScannerException(device, ex);
                    throw se;
                }
            }
        }
Пример #2
0
        public override void AcquireImages(bool showUI)
        {
            CommonDialogClass wiaCommonDialog = new CommonDialogClass();

            if (m_DeviceID == null)
            {
                SelectDevice();
            }

            //Create DeviceManager
            Device WiaDev = CreateDeviceManager();

            WIA.Item scanningItem = GetScanningProperties(showUI, wiaCommonDialog, WiaDev);
            if (scanningItem == null)
            {
                return;
            }

            WIA.ImageFile imgFile = null;
            WIA.Item      item    = null;

            PrepareImagesList();

            //Start Scan
            while (HasMorePages(WiaDev))
            {
                item = scanningItem;

                try
                {
                    imgFile = ScanImage(wiaCommonDialog, imgFile, item);
                }
                catch (COMException ex)
                {
                    if ((WiaScannerError)ex.ErrorCode == WiaScannerError.PaperEmpty)
                    {
                        break;
                    }
                    else
                    {
                        WiaScannerException se = BuildScannerException(WiaDev, ex);
                        throw se;
                    }
                }
                catch (Exception ex)
                {
                    WiaScannerException se = BuildScannerException(WiaDev, ex);
                    throw se;
                }
                finally
                {
                    item = null;
                }
            }
        }
Пример #3
0
        private WiaScannerException BuildScannerException(Device WiaDev, Exception exception)
        {
            WiaScannerException scannerException = new WiaScannerException(exception);

            if (exception is COMException)
            {
                scannerException.ErrorCode = (exception as COMException).ErrorCode;
            }

            if (m_ScannerDeviceData != null)
            {
                scannerException.ScannerDeviceData = m_ScannerDeviceData;
                scannerException.WiaVersion        = m_WiaVersion;
            }
            return(scannerException);
        }
Пример #4
0
        private bool HasMorePages(Device WiaDev)
        {
            try
            {
                bool hasMorePages = false;
                //determina si hay mas de una pagina en espera
                Property documentHandlingSelect = null;
                Property documentHandlingStatus = null;
                foreach (Property prop in WiaDev.Properties)
                {
                    if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
                    {
                        documentHandlingSelect = prop;
                    }
                    if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
                    {
                        documentHandlingStatus = prop;
                    }
                }

                if (documentHandlingSelect != null) //may not exist on flatbed scanner but required for feeder
                {
                    //check for document feeder
                    if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                    {
                        hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                    }
                }
                return(hasMorePages);
            }
            catch (COMException ex)
            {
                WiaScannerException se = BuildScannerException(WiaDev, ex);
                throw se;
            }
        }