dcsimg
Results 1 to 14 of 14

Thread: Stopping scanning process

  1. #1

    Thread Starter
    Hyperactive Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    344

    Stopping scanning process

    I am doing a scan and wish to stop the scanning process when the scanner does not respond.
    I have put a timer on 60 seconds. How do I stop the routine which started the scanning when that time expires?

    Thanks
    PK

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,420

    Re: Stopping scanning process

    What routine?

    If your "routine" is a loop running on the UI thread then Timer events won't fire. You'd be starving the message loop and Windows should already have you marked "not responsive."

    We'll need more context to offer useful suggestions.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,868

    Re: Stopping scanning process

    Urgghh..... stuff like that should be outsourced to a dll, so it runs in its own thread, and doesn't block the main UI.
    It's kinda like "Shoot and forget" with all the toys in between (dll raises event "Notify" with Messages "ScanStart", "ScanInProgress", "ScanFinish", "ScannerNotResponding" which your main app can process and react to it)
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  4. #4

    Thread Starter
    Hyperactive Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    344

    Re: Stopping scanning process

    dilettante,
    This i my code (it works quite well when the scanner is available):

    Code:
    With Twain1
        On Error GoTo ErrorHandler
        .CurrentDevice = cboScanners.ListIndex            ' Select the device shown in the combobox
        If .Connected Then            ' Only continue of the device is connected
            If chkUseInt.Value Then     ' Either use the interface, or set properties from the various text boxes and the combobox
                .UseInterface = True
            Else
                .PixelType = cboPixType.ListIndex
                If IsNumeric(txtRes.Text) Then
                    .Resolution = Val(txtRes.Text)
                End If
                If IsNumeric(txtTop.Text) And IsNumeric(txtLeft.Text) And IsNumeric(txtRight.Text) And IsNumeric(txtBtm.Text) Then .SetImageLayout Val(txtLeft.Text), Val(txtRight.Text), Val(txtTop.Text), Val(txtBtm.Text)
            End If
            .UseInterface = False
        End If
        
        If chkMultiPagePDF.Value = 0 Then
            .Acquire        ' Acquire the image and transfer it to the image box
            imgDisplay.Picture = .Picture
        Else
            .ClearPDF
            '.SelectDevice
            Reply = vbYes
            Do While EndScan = False
                i = i + 1
                .Acquire
                .AddToPDF i
                Reply = MsgBox("Do you wish to scan another page?", vbYesNo)
                If Reply = vbNo Then
                    EndScan = True
                    '.MultiImage = False
                End If
            Loop
        End If
        On Error GoTo 0
    End With
    Zvoni,
    I think your proposal is valid, but I need some more info on that as it is dllhell for me. Must I write my own or are there such classes available?

    Thanks
    PK

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,420

    Re: Stopping scanning process

    Looks like that Acquire method is synchronous. Game over.

    No idea what library you are using but you may have to look at its documentation or ask on the vendor's support forum. You need an asynchronous call that supports a progress callback or event supporting an abort flag. Some may have an option to display an acquire/transfer dialog the user can cancel.

  6. #6

    Thread Starter
    Hyperactive Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    344

    Re: Stopping scanning process

    LaVolpe has an excellent program apparently, which he said he would update, but the link does not show any update. If LaVolpe can maybe comment on this.

    http://www.vbforums.com/showthread.p...roject-Scanner

    Thanks
    PK
    Last edited by Peekay; Sep 11th, 2019 at 12:15 PM.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,273

    Re: Stopping scanning process

    Quote Originally Posted by Peekay View Post
    LaVolpe has an excellent program apparently, which he said he would update, but the link does not show any update. If LaVolpe can maybe comment on this.

    http://www.vbforums.com/showthread.p...roject-Scanner

    Thanks
    PK
    Yeah, whenever I revisit that project, I get distracted by something else (real life or another project). It's on my backburner. But that said, the project has nothing to do with hardware scanners.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    Member
    Join Date
    May 2017
    Posts
    59

    Re: Stopping scanning process

    Ignore me, Sorry. I misread what type of scanning you were talking about.
    Last edited by MikeSW17; Sep 11th, 2019 at 05:50 PM.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,420

    Re: Stopping scanning process

    It is hard to imagine a still-imaging device like a page scanner sold in the last 15+ years that doesn't have WIA drivers shipped in the box. Even Windows Me supported WIA drivers that connected through the old WIA 1.x model.

    Going that way you eliminate a 3rd party dependency because WIA 2.0 has shipped in everything from Windows Vista forward.

  10. #10
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Stopping scanning process

    PK, What ActiveX or API are you using? (Twain1 in your code)
    And on what method does the non-responding issue occur?

    I'm assuming your non-responding issue happens when you call the "Acquire" method.
    Typically in a (Twain) scanning library, .Acquire would return an error code or boolean that you could test for.
    Similarly if you get the issue when selecting the scanner (I'm guessing .CurrentDevice does a SelectDevice) you would expect a return code.

    There may be something like an "OnAquire" or "OnCancel" event you can check.

    Or there could be a 'Connected' property to show if a scanner is physically connected.
    Last edited by VB6 Programming; Sep 11th, 2019 at 11:46 PM.

  11. #11

    Thread Starter
    Hyperactive Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    344

    Re: Stopping scanning process

    VB6
    I am using the twain control by Ciansoft TwainControlX and it has the .connected property. It somehow strangles itself after that.
    You can see in my code that I do call the .connected property.

    dilettante also has an excellent demo of a Scancard in 2006, but things get very involved with WIA and I do not know whether it is a good idea to go to those lengths to include scanning in my document management program. I would think every user can scan with their own scanning software which accompanied their hardware.

    The routine I published above worked very well previously. I thought I could find the gremlin on tracing, but it just vanishes into the deep.

    PK

  12. #12
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Stopping scanning process

    Ah yes, I can see the .connected property (though not all scanner manufacturers implement this well, so no surprise it isn't working for you).

    Does the same issue happen whether or not you use the Twain UI?

    Is there an option to display a progress bar (when the Twain UI is disabled)? This may allow you to press Cancel.

    A further note:
    Is there a Wait or WaitForAcquire property?
    If so, you probably want this off (False). Otherwise if there is a scanner problem you would never exit the Acquire method. And events such as the "onAcquire" I mentioned earlier may not trigger.

    And another note:
    When you are selecting your device (.CurrentDevice) you may see your scanner appearing twice on the list, one of these being as a WIA device (Windows includes a virtual twain driver that makes WIA devices appear as Twain devices). You should select the native Twain device, not the WIA version.
    Last edited by VB6 Programming; Sep 12th, 2019 at 02:26 AM. Reason: Further Notes

  13. #13

    Thread Starter
    Hyperactive Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    344

    Re: Stopping scanning process

    VB6,

    Yes, it has those properties and some crucial events.
    The problem is (I now find out) that certain scanners will not let you use their scanning interface in which case you must create your own.
    My HP does allow it and my Canon does not.

    PK
    Last edited by Peekay; Sep 12th, 2019 at 11:00 AM.

  14. #14
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Stopping scanning process

    PK,

    It's unusual that a scanner wouldn't let you use their Twain UI. I've never seen that before (though I have seen scanner drivers that don't let you switch the UI off). Your '.UseInterface = True' should have some effect.


    Are you sure it isn't that you are setting .UseInterface = False and that the HP Scanner is ignoring this and displaying the UI anyway?
    Your posted code seems to always set .UseInterface = False. (It is outside the If..then..else code).


    It could be you need to reinstall the Canon Twain scanner driver (sometimes an update to the Windows OS can upset this).

    I use mainly Fujitsu fi-series scanners, but also Kodak i-series and Canon DR-series scanners.
    The larger Canon scanners are very good, but I don't use their lower-end models.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width