Dosadi home  

Go Back   Dosadi Forum > Dosadi > EZTwain Pro Library

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-15-2006, 09:27 PM
fisherdean fisherdean is offline
Participant
 
Join Date: Mar 2006
Posts: 2
Default Reading values from barcodes in VB6

I new to EZtwain and I have the trial version of EZtwain Pro 3.09b27.

I am trying to figure out the best way to read barcodes from images I scan. I will be scanning to mulitpage pdf's with a cover sheet placed on top of the pages to be scanned.

I noticed in the user guide that I have to use the Barcode_GetText method with VB 6. What I dont' know is how to use it correctly.

Here is my code, most of which was generated by the Code Wizard except for the barcode portions:
Code:
Private Sub Command1_Click()
    Dim i As Integer
    Dim hdib As Long
    Dim n As Integer
    Dim z As Integer
    ' Change this to your value:
    n = 2
    Call TWAIN_LogFile(1)
    Call TWAIN_SetHideUI(1)
    Call TWAIN_SetJpegQuality(75)
    If BARCODE_IsAvailable = 0 Then
        MsgBox "Barcode Function Not Available"
    End If
    If TWAIN_OpenDefaultSource() <> 0 Then
        Call TWAIN_SelectFeeder(1)
        Call TWAIN_EnableDuplex(1)
        ' Not guaranteed to work, check return = 1:
        Call TWAIN_SetPixelType(2)
        Call TWAIN_SetLightPath(0)
        Call TWAIN_SetXferCount(n)
        If TWAIN_SetAutoScan(0) = 0 Then
            MsgBox "SetAutoScan(FALSE) failed - scanner cannot single-scan?"
        End If
        Call TWAIN_SetMultiTransfer(1)
        If TWAIN_BeginMultipageFile("c:\image.pdf") = 0 Then
            For i = 1 To n
                ' If you can't use Me.hwnd, pass 0:
                hdib = TWAIN_Acquire(Me.hwnd)
                If hdib = 0 Then
                    Exit For
                End If
                ' <your image processing here>
                ' Get int of the barocde that is recognized
                z = BARCODE_Recognize(hdib, 1, -1)
                If z > 0 Then

                [b]' this is the part I am having trouble with. I'm don't know how to use this function
                    MsgBox BARCODE_GetText(z, "")[/b]                
                End If
                    
                Call TWAIN_DibWritePage(hdib)
                Call DIB_Free(hdib)
            Next i
            Call TWAIN_EndMultipageFile
        End If
        Call TWAIN_CloseSource
    End If
    If TWAIN_LastErrorCode() <> 0 Then
        Call TWAIN_ReportLastError("Unable to scan.")
    End If
End Sub
How do I use the Barcode_GetText function?

Thanks
Reply With Quote
  #2  
Old 03-16-2006, 05:09 PM
Spike's Avatar
Spike Spike is offline
Administrator
 
Join Date: Oct 2004
Location: Northampton, MA
Posts: 1,664
Default recognizing barcode in VB6

Hi fisherdean - I think this is a weakness in our documentation. Since you have version 3.09, you can just do this:

Dim text As String
text = BARCODE_Text(0) ' get text of first barcode patch recognized

It was so awkward to return string parameters in VB, that we added a bunch of small functions at the end of the eztwain.bas file, to take care of it and return the strings as function values.

Two other comments: Your code is looking for the barcode on each scanned page, but it sounded like maybe your barcode is on the separator page, or on the first page of the document? And your code loop is going to scan exactly 2 pages (n = 2) - we recommend telling the Code Wizard you want to scan 'all available images', and then counting pages and handling the different cases inside the loop.
__________________
-spike _/\_
Reply With Quote
  #3  
Old 03-20-2006, 02:03 PM
fisherdean fisherdean is offline
Participant
 
Join Date: Mar 2006
Posts: 2
Default

I changed my code to get all available images but I'm trying to figure out where to put my code to read the barcode. This is what I have but it is not working:

Code:
    Call TWAIN_LogFile(1)
    Call TWAIN_SetHideUI(0)
    Call TWAIN_SetFileAppendFlag(0)
    Call TWAIN_SetJpegQuality(75)
    If TWAIN_OpenDefaultSource() <> 0 Then
        Call TWAIN_EnableDuplex(0)
        ' If you can't use Me.hwnd, pass 0:
                strBarcode = BARCODE_Text(0)
                MsgBox strBarcode
        Call TWAIN_AcquireMultipageFile(Me.hwnd, "c:\test2.pdf")
    End If
    If TWAIN_LastErrorCode() <> 0 Then
        Call TWAIN_ReportLastError("Unable to scan.")
    End If

Thanks for the response.

]
Reply With Quote
  #4  
Old 03-20-2006, 06:45 PM
Spike's Avatar
Spike Spike is offline
Administrator
 
Join Date: Oct 2004
Location: Northampton, MA
Posts: 1,664
Default recognizing barcode in VB6

Hi fisherdean - Tell the Code Wizard that you want to "process each image in memory" - there's a checkbox for that. That will create a loop that brings each page into memory before writing it to your .pdf file. Look for the comment that says "your processing here" and put the call to BARCODE_Recognize there, followed by the call to BARCODE_Text(0).

If you are scanning a single document (everything in the feeder goes into one file) and you know which page has the barcode, you could also use the code you have with TWAIN_AcquireMultipageFile, and then read back the page with the barcode and recognize it then i.e. after scanning the entire file. We can read back any page from a file with DIB_LoadPage. If that sounds interesting, let me know and I'll explain how to do that.

I know, we need to improve the Code Wizard so it knows how to program barcode recognition. Maybe in EZTwain 3.10.
__________________
-spike _/\_
Reply With Quote
  #5  
Old 03-20-2006, 08:13 PM
Guest
 
Posts: n/a
Default Barcode

Ideally, I will be scanning single documents. After scanning the singe document I want to read the barcode and the first page and then save the pdf file use the barcode text as the name of the file. I also want to use the barcode text later in the code in a SQL statement.

Can you give a little more detail in using the DIB_LoadPage and reading the barcode and saving the file using the barcode text

Thanks
Reply With Quote
  #6  
Old 03-20-2006, 08:48 PM
Spike's Avatar
Spike Spike is offline
Administrator
 
Join Date: Oct 2004
Location: Northampton, MA
Posts: 1,664
Default recognizing barcode in VB6

Sure. Here's one way you could code that. This is about the simplest code to do this, but it does require creating and then moving or renaming the PDF file.
Code:
' Scan the document from the ADF into a temporary name:
TWAIN_AcquireMultipageFile(hwnd, tempfilename.pdf)
if TWAIN_LastErrorCode() <> 0 Then
    ' something went wrong, complain to operator:
    TWAIN_ReportLastError("During scan")
    goto tryAgain
end if
' File scanned successfully, read back first page
hdib = DIB_LoadPage(0, tempfilename.pdf)
' Look on page for 1 barcode:
z = BARCODE_Recognize(hdib, 1, -1)
DIB_Free(hdib)   ' do not leak memory!
if (z > 0) then
    ' Found one barcode, get the barcode text:
    text = BARCODE_Text(0)
    <rename tempfilename.pdf to actual filename based on barcode>
    <continue with processing document>
else
    ' panic - could not find barcode, probably need operator action
end if
__________________
-spike _/\_
Reply With Quote
  #7  
Old 03-21-2006, 01:46 PM
Guest
 
Posts: n/a
Default Error

I am getting an error "Expected = " on this line:

TWAIN_AcquireMultipageFile(hwnd, tempfilename.pdf)

Any idea what is wrong. I don't see anything wrong with this.


Thanks
Reply With Quote
  #8  
Old 03-21-2006, 11:11 PM
Spike's Avatar
Spike Spike is offline
Administrator
 
Join Date: Oct 2004
Location: Northampton, MA
Posts: 1,664
Default barcodes in VB6

Sorry about the pseudo-code, I just don't write enough VB to be able to write correct VB code outside the IDE. Maybe quotes around the filename? Or it's a function so it needs either a Call or a result = TWAIN_AcquireMultipage(...
__________________
-spike _/\_
Reply With Quote
  #9  
Old 03-30-2006, 04:36 PM
sidtrey sidtrey is offline
Wizard
 
Join Date: Aug 2005
Posts: 124
Send a message via MSN to sidtrey
Default LOL

Yep exactly what you did. Of course we wont get into C# or C++ You'd have still broken it.. :-)

heheh
Reply With Quote
Reply

Bookmarks
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:35 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content 2007-2009 Dosadi