Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scanner Integration

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,795
10
38
JP
Hi All,
Has anyone done any scanner integration with VFP? What I'm trying to achieve is, click a button that allows an attached scanner to accept an image when scanned in, save the image (automatically) to a pre-defined directory, and attach it to a table at the same time. Would appreciate any guidance here.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Haven't done it in VFP but did scanner programming in VB without any external (or bought) software. Pure VB.

Source code I based my solution upon can be found here (download)

Don't know if YOU are able to translate VB into VFP but it is also possible to make a VB.DLL and call that from within VFP.
 
Ok, started to dig into this today. Very cool, I downloaded EZTWAIN and installed it.

Now the code from Mike's page states Declare your Function:

Code:
DECLARE INTEGER TWAIN_SelectImageSource ;
  IN Eztw32.DLL INTEGER hWnd
DECLARE INTEGER TWAIN_GetSourceList ;
  IN Eztw32.dll
DECLARE INTEGER TWAIN_GetNextSourceName ;
  IN Eztw32.dll STRING @cSourceName
DECLARE INTEGER TWAIN_OpenSource ;
  IN Eztw32.DLL STRING cSourceName
DECLARE INTEGER TWAIN_AcquireNative ;
  IN Eztw32.DLL INTEGER nAppWind, INTEGER nPixelTypes
DECLARE INTEGER TWAIN_WriteNativeToFilename ;
  IN Eztw32.DLL INTEGER nDIB, STRING cFilename
DECLARE INTEGER TWAIN_FreeNative ;
  IN Eztw32.DLL INTEGER nDIB
DECLARE INTEGER TWAIN_SetMultiTransfer ;
  IN Eztw32.dll INTEGER nFlag

This kind of "systems programming" (as I will call it) is really not my forte. So I'm unclear where this should go?
Do I put it in the command button that I've created "Scan Image", or does this go into COMMON.PRG that becomes part of my global code base? I assume I don't put this into a procedure.

Sorry if these questions are ignorant, but I can admit my ignorance. :)

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Once declaed functions can be used anywhere in code. If you would be a regular at news2news you'd know they most often put it into an initialisation process. Also take a look at the regsitry ffc class and you find a how to and where to put these. Declaring multiple times doesn't hurt and protects against CLEAR DLL. Many ways are possible, it's a matter of your taste alone.

Bye, Olaf.
 
Well I know enough to know that there are many ways, but some ways are better than others (and some don't matter). I'd like to avoid the "bad ways" or bad practices at least, so that's part why I asked.

So I can simply declare them in initialization in my "Common.PRG" which is established very early with "SET PROC TO" command.
Any danger in doing that?

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Putting them in your proc file isn't a problem, but SET PROC does not execute any of the code in the proc file.

You need to execute the code.
 
Yes, dan says it. The difference of a DECLARE function IN some.DLL and a definiton of a PROECEDURE or FUNCTION is, that the declaration needs to be executed.
There is nothing you can do wrong here. You can do the declaration multiple times and have no stack filling up or overflowing. You can do them once and it's enough. Anywhere before using them the first time. So startup is fine, but SET PROC is insufficient.

If you need a recipe, put them all in a API.PRG and in your main.prg DO API or call API() if the PRG is in your PATH, then you're set up. Never do any CLEAR DLLs and you can use the API functions anywhere. It doesn't cost performance as the declarations are through in a blink of an eye, it doesn't cost much memory, either.

BYe, Olaf.
 
Right. It's a packaging issue. Don't stumble over whether you should tape the box closed or tie it with twine when you really need to use what's in the box.

Put the code wherever it makes sense to you, but make sure you run the declaration code before calling the functions you're declaring. It doesn't hurt if you declare multiple times, although basic programming sensibilities say you shouldn't do something like this in a tight repetitive loop if you can do it once outside the loop instead.

But, again, that's packaging.
 
Yes, I get that it has to be executed to be used.
I'll put them in the startup procedure.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Oh... have any of you used this recently???
Dosadi sold it to Altalasoft. The license fee is now $999 for 1 license, PER YEAR!
While it's very capable, I need this for a single stand-alone application. That is a ridiculous fee.
Guess I'll need to find another TWAIN interface source.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Scott, there has always been a licence fee for the full product. The one I used was the so-called Classic version, which was - and still is - free. It should meet all your requirements.

The Classic version doesn't come with official support, but I found that the product's author, Spike McLarty, was always willing to answer questions. (But that might have changed now that Altasoft is the owner.)

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I just tested the classic and it works. Example, thanks to Mike:
You can choose to output to a file or to the clipboard

Code:
do eztwain   && .PRG provided in the EZTwain download in the VFP folder

LOCAL lcFile, lnImageHandle, lnReply, scantarget
scantarget=1  && 0=Clipboard  1=File

* Show or not show interface
TWAIN_SetHideUI(1)  && 0=Show standard user interface, 1=no interface

if scantarget=0
	* Get the image to the clipboard (Paste with Ctrl+V)
	lnReply = 1-TWAIN_AcquireToClipboard(0,0)   && A Twain return value of 1 indicates success, 0 indicates failure.
	lcFile='Clipboard'
else
	* Get the image in a file
	lcFile = "f:\test_image.bmp"
	lnImageHandle = TWAIN_AcquireNative(0,0)
	* Write the image to a disk file
	lnReply = TWAIN_WriteNativeToFilename(lnImageHandle,lcFile)
endif

* Release the image handle
TWAIN_FreeNative(lnImageHandle)

* Check for errors
IF lnReply = 0
  messagebox('Image successfully written to '+lcFile)
ELSE
   messagebox('Something went wrong')
ENDIF
 
Any idea where I can get that version of the DLL?

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Scott, it is in the eztw1.zip
see my link as mentioned earlier

In the zip file you find the dll in \VC\release

You can use third party programs like irfanview 's command mode to convert bmp to jpg or rotate the image etc.

B.t.w. without interface I seem not to be able to set the DPI. It says that it's only possible to change the DPI in State 4 (Twain_source_open). But when the scanner is idle the state is allways 1 (presession). In my VB program, see answer #3, that has never been a problem.
Edit: Got it!
TWAIN_OpenDefaultSource()
TWAIN_SetCurrentResolution(300)
TWAIN_SetCurrentPixelType(2) && 0,1,2 = B/W,Gray,RGB

Next problem is how to set a scan region or frame instead of the whole A4 area. I don't think that is possible in EZTwain Classic without the scanners interface.
 
Jack,
Thanks for the info, and based on what you've said here, it's really not going to meet my needs. I'm using a very modern scanner, which can duplex scan, and that's of particular interest. I also got this one specifically so I don't have to do full A4 scanning when the image is the size of a business card... I don't mind paying a license, I just find $999 to be excessive, free doesn't give me the functionality I need. I was fine for a $200 option, but now I'm trying to balance the lesser of all evils... It's not the programming that's frustrating, its the fiddle bits...


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Scott, Take a look at the VB example. It works great in VB and you CAN determine the scan area.
My VB-program, based on that, can scan a business card format but has to do it twice, front and back, and than combine the two together in one JPG (With help of Irfanview)

Today I was/am trying to get this VB method to work within VFP, but i'm getting an error i haven't solved yet.
 
Jack,
I'll have a look. For clarity, I don't want to combine the images. I've created dedicated space for front and back of card. And I'm using Canon P-208II scanner, which does front and back simultaneously, and only scans the area, no need to define or monkey with all that. It's actually a very impressive compact scanner. It's meant as a "Document" scanner, for full A4 size, but has a resizeable "input". I have stacked 10 cards on it, and got front and back scans for all of them (in fact, it automatically discards blank backs).
I've got it sort of working with EZTWAIN4, but very disappointed at the $999 price tag on it. I may discuss with them for a "lighter" license, not sure if I'll get anywhere with that. But it does a very nice job with their "code generator", it really did everything I needed in about 10 minutes, aside from the fact that they make a "TWAIN_WriteToFileName" function that doesn't exists in the EZTWAIN4.PRG code. So I assume there is some kind of low-level file handling that is supposed to go on to write the files out, but it's missing. I sent their tech support an email, and raised a case on their website, but since it's Sunday, I don't think I'm going to hear back from them anytime soon. So for now, I'm "holding", because even if I don't use this driver, I think a lot of their generated code is really good starting point for modifying, since this is a little off the "normal" path.
My intention is first to get front/back card scans automatically adding to the contact record, and then later (maybe much later) deploying some OCR and using the card scan to populate the contact record automatically, but that is not as critical an issue for me as getting the cards in initially. It's certainly a "Version 2 or 3 or 4" focus. First, need to get the images in.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top