Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

TWAIN - Get Button Press

Posted on 2003-03-19
8
Medium Priority
?
453 Views
Last Modified: 2010-04-03
How can i get an event if the button on the scanner is pressed.

I tried to send a CAP_DEVICEEVENT with a TWDE_CUSTOMEVENTS but i get allway an error.
Regardles which Events i try to set, i get every time an error.

Thanxs in advance
0
Comment
Question by:Andi4553
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:steve_hsk
ID: 8169273
Hi Andi ...

MS do ship a twain Active X component with Windows, which you could install into delphi and test with. Alternatively, you can use one of the VCL components from Torry's site :
http://www.torry.net/mmtwain.htm

Also available at this site is an Unofficial Translation of the Twain Header File, which you could interface directly through this too. Extract as below :-

TWDE_CUSTOMEVENTS = $8000;
TWDE_CHECKAUTOMATICCAPTURE = 0;
TWDE_CHECKBATTERY = 1;
TWDE_CHECKDEVICEONLINE = 2;
TWDE_CHECKFLASH = 3;
TWDE_CHECKPOWERSUPPLY = 4;
TWDE_CHECKRESOLUTION = 5;
TWDE_DEVICEADDED = 6;
TWDE_DEVICEOFFLINE = 7;
TWDE_DEVICEREADY = 8;
TWDE_DEVICEREMOVED = 9;
TWDE_IMAGECAPTURED = 10;
TWDE_IMAGEDELETED = 11;
TWDE_PAPERDOUBLEFEED = 12;
TWDE_PAPERJAM = 13;
TWDE_LAMPFAILURE = 14;
TWDE_POWERSAVE = 15;
TWDE_POWERSAVENOTIFY = 16;

The components with source demo the bindings to these events.

Hope this helps,
STeve
0
 

Author Comment

by:Andi4553
ID: 8172307
which component does support events ?
The translation of the Twain Header File, i allready have, but i don't know how to use them !
0
 
LVL 2

Expert Comment

by:steve_hsk
ID: 8172621
Hi Andi ...

1) This link maybe useful, with resource, FAQ's and documents available :-
http://www.twain.org/

I'm assuming that you have your twain code running in a thread. In order to capture the messages sent from the scanner, you will need a message loop running inside your Execute Function of your thread, similar to below :-

PROCEDURE TThreadBase.Execute;
VAR
    Msg    : TMsg;
    dError : Boolean;
BEGIN
    WHILE NOT (Terminated) DO
    BEGIN
        dError := GetMessage(Msg,0,0,0);

        IF (dError = TRUE) THEN
        BEGIN
            DecipherMessage(Msg);

            WHILE (peekmessage(Msg,0,0,0,PM_REMOVE) = True) DO
            BEGIN
                DecipherMessage(Msg);
            END;
        END
        ELSE IF (dError = FALSE) THEN
        BEGIN
           Terminate;
        END;
    END;
END;

2) Chapter 3-27 (page 30)
http://www.twain.org/archive/spec16.pdf

The following code method (Chapter 3-29, page 32) can then be used in the DecipherMessage Function :-

PROCEDURE TThreadBase.DecipherMessage (Msg : TMsg);
VAR
   twEvent : TW_EVENT;
   rc      : TW_INT16;
BEGIN
     // Have only done an approximate delphi conversion from the C++ example ... PLEASE CHECK FIRST !
     twEvent.pEvent    = TW_MEMREF(msg);
     twEvent.TWMessage = MSG_NULL;
     rc = pDSM_Entry (pAppId, pSourceId, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, TW_MEMREF(twEvent));

     // Place break point on case statement below
     CASE twEvent.TWMessage OF
     BEGIN
          MSG_XFERREADY  : SetupAndTransferImage(NIL);

          MSG_CLOSEDSREQ : DisableAndCloseSource(NIL);
     END;
END;

You will then need to play with this msg loop to capture the msg you want that indicates the button - press. By placing a breakpoint on the CASE statement, and then pressing the scanner button, you can then capture, interpret and add this perhaps new msg to your code.

I really would recommend reading chapter 3 of the 2nd document reference !

Hope this helps,
STeve
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Andi4553
ID: 8173089
hi steve

I allready have the messageloop, and scanning works fine, but if i press the button no message is sent.
Therefore i think that i have to tell the TWAIN Driver that i need a message if the button is pressed.
0
 
LVL 2

Accepted Solution

by:
steve_hsk earned 1600 total points
ID: 8173482
Hi Andi ...

This is site is the result of a search for button press and has some general intersting discussion points :
http://services2k.jflinc.com/twain/Default.asp?target=%22button+press%22

This site describes in more detail the registering process :
http://services2k.jflinc.com/twain/archive/twain-004015.asp

It is possible that there is no programmatic support by the scanner for this feature !

This PDF Doc is the TWAIN spec and desribes all events in chapter 9 :
http://www.twain.org/docs/Spec1_9_197.pdf
http://www.pca.com.gr/ts/twain1/chap9.html

there are two sides now I think :
1) Check the Capability :
MSG_GET(CAP_SUPPORTEDCAPS) or MSG_GET(CAP_EXTENDEDCAPS)
2) MSG_SET(CUST_???) << which should be returned by step(1)

I'm not sure if I can be of more use Andi !

STeve
0
 

Expert Comment

by:CleanupPing
ID: 9316675
Andi4553:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question