?
Solved

TWAIN - Get Button Press

Posted on 2003-03-19
8
Medium Priority
?
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

764 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