Slow input on a READ with a scanner

688 views
Skip to first unread message

Tim J

unread,
Feb 13, 2024, 10:27:23 AM2/13/24
to Harbour Users
If I use a handheld scanner to scan a barcode, it is very slow in a Harbour compiled application.  The longer the barcode, the more time it takes to input the text.
It's as if a fairly fast typist is typing in the barcode.

If I scan the same barcode within a Command Prompt, it is instantaneous for all intents and purposes.

Is there anyway to speed this up?

If you have a scanner, you can try the following code:
FUNCTION MAIN
LOCAL ;
getlist := {}, ;
cString := space(25)
CLS
Do While .T.
cString := space(25)
@ 12, 30 say "Scan barcode:" GET cString
READ
@ 20, 0 say cString
Enddo
Return .T.

Thanks,
Tim



david...@gmail.com

unread,
Feb 14, 2024, 12:07:22 PM2/14/24
to Harbour Users
Hi Tim,

It's been a while since I programmed in console mode but why would you need the "Do While" for?
As I remember, READ will stop execution of following lines until it has been issued an Enter or esc key .
Could it be that the DO While is making it seem slow?

Regards,
David Field

Hurricane

unread,
Feb 14, 2024, 1:30:46 PM2/14/24
to Harbour Users
Hi Tim,
Initially just try this:

cString := space(25)
@ 12, 30 say "Scan barcode:" GET cString
READ


Some devices can send control characters, their looping code can make it difficult to understand and read.

In Clipper, x/Harbour I have already integrated with some devices (Code Reader, Data Collectors, Tax Printers, etc.) If approved, next week I will start integration with facial access controller.

Regards,

Damian Sz.

unread,
Feb 14, 2024, 1:37:11 PM2/14/24
to Harbour Users
Hi Tim

Configure the barcode scanner to send a prefix before the barcode, e.g., the  ` (96) character, and a suffix  ENTER. Use the SetKey() function to call the code retrieval function when it detects the ~ character. Pass the function result to the GET variable.

#define K_BARCODE_PREFIX    96 
SetKey() with the implementation of "send the ENTER key" and "check if you are in the GET field that is ready receive the barcode":
SetKey( K_BARCODE_PREFIX, {|p,l,v| cB:=BarCodeRead(), iif( v == 'BARCODE', __KEYBOARD( Chr( K_CTRL_Y ) + cB + Chr( K_ENTER ) ), "" )} )

slightly different implementati:
SetKey( K_BARCODE_PREFIX, {|p,l,v|iif( v == "BARCODE", Eval( {|| cB := BarCodeRead(), GetList[1]:varPut( cB )} ), "") } )

FUNCTION BarcodeRead()
  LOCAL cBarcode  := ""
  LOCAL nKey          := 0
  LOCAL nTime       := Seconds()
  LOCAL nTimeOut := 5

   DO WHILE ( Seconds() - nTime ) < nTimeOut
         nKey := INKEY( 0.2 )
         IF nKey != K_ENTER
             IF nKey != 0
                 cBarcode += CHR( nKey )
             ENDIF
         ELSE
            EXIT
        ENDIF
   ENDDO

RETURN AllTrim( cBarcode )

nTimeOut is there to prevent an infinite loop in case you accidentally press ' and do not send the barcode.

Regards
Damian

Tim J

unread,
Feb 15, 2024, 6:20:24 AM2/15/24
to Harbour Users
David, The Do While loop was simply to enable me to scan multiple times with different barcodes and watch the results in my test.  
Thanks

Tim J

unread,
Feb 15, 2024, 6:37:58 AM2/15/24
to Harbour Users
Damien Sz, I can see where your proposal would work.  Thanks

Tim J

unread,
Feb 15, 2024, 6:38:54 AM2/15/24
to Harbour Users
Hurricane, that is what I do.  I should have left the Do While loop off the sample I posted.  Thanks

António

unread,
Feb 16, 2024, 5:09:10 AM2/16/24
to Harbour Users
I had the same issue.
Try adding

-gtwvt

to the hbm file.
Scan will be fast.
António

Tim J

unread,
Feb 16, 2024, 7:53:10 AM2/16/24
to Harbour Users
That did it!!!!
Thank you so much Antonio!

Paola Bruccoleri

unread,
Feb 21, 2024, 7:34:21 AM2/21/24
to harbou...@googlegroups.com
Hi Tim
Before get, put

CLEAR TYPEAHEAD
@fila1,col1 get cCodBar





De: "'Tim J' via Harbour Users" <harbou...@googlegroups.com>
Para: "Harbour Users" <harbou...@googlegroups.com>
Enviados: Martes, 13 de Febrero 2024 12:27:22
Asunto: [harbour-users] Slow input on a READ with a scanner
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/c0688870-f188-49e6-955f-dabdd6b68403n%40googlegroups.com.

Tim J

unread,
Feb 21, 2024, 9:45:17 AM2/21/24
to Harbour Users
Thanks Paola, but that didn't work for me.

Antonio's solution did make the scan basically instantaneous - which is terrific!

It added a few other consequences that I can live with, or work around, though:
1) It changed the font and font size, making the screen size different.
2) If the application is called from a batch file, if leaves the calling screen open.  Got around that by using the "START " command
3) It slowed down long intensive calculations by a factor of 33% or so.

AL67

unread,
Feb 23, 2024, 2:27:09 AM2/23/24
to Harbour Users
Harbour in console mode (text gt) very slow display screen

Try this code:

FUNCTION MAIN
LOCAL ;
getlist := {}, ;
cString := space(25)
CLS
@ 20, 0 SAY "Read:"

Do While .T.
cString := space(25)
DISPBEGIN()
        @ 0, -100 GET cString   //out of screen
READ
        DISPEND()
@ 20, 7 say cString
Enddo
Return .T.

Tim J

unread,
Feb 26, 2024, 7:34:50 AM2/26/24
to Harbour Users
Thanks AL67, but that didn't seem to help.
Antonio's solution is still my answer.

viktor....@googlemail.com

unread,
Jan 13, 2026, 7:58:43 AM (yesterday) Jan 13
to Harbour Users

I had a similar problem on a different topic. I wanted to enter entire CSV lists via copy & paste using GET fields in a CMD application. In case of an error, everything in the buffer should be cleared with

CLEAR TYPEAHEAD
KEYBOARD CHR( 0 )

Unfortunately, this did not work correctly when there were too many characters in the copy buffer. Only part of it was deleted. sometimes more, sometimes less.

With a bit of experimenting, I discovered some strange behavior. If, after calling INKEY(), LASTKEY() must be called at least twice then the readout speed from the key buffer increases enormously.

Example:

do while !EMPTY( ineky( 0.1) )
  lastkey()
  lastkey() 
enddo

As a result, adjustments in getlist.prg significantly accelerated GET input.

METHOD Reader( oMenu, aMsg ) CLASS HBGetList
......
      DO WHILE oGet:exitState == GE_NOEXIT .AND. ! ::lKillRead
         IF oGet:typeOut
            oGet:exitState := GE_ENTER
         ENDIF

         DO WHILE oGet:exitState == GE_NOEXIT .AND. ! ::lKillRead
            IF !EMPTY( Inkey( 0 ) ) .AND. !EMPTY( lastkey() )
#ifdef HB_COMPAT_C53
               SetCursor( iif( ::nSaveCursor == SC_NONE, SC_NORMAL, ::nSaveCursor ) )
               SetCursor( SC_NONE )
#endif
               ::GetApplyKey( lastkey(), oGet, oMenu, aMsg )
               nRow := Row()
               nCol := Col()
               ::ShowGetMsg( oGet, aMsg )
               SetPos( nRow, nCol )
            ENDIF
         ENDDO

#ifdef HB_COMPAT_C53
         IF ! ::nLastExitState == GE_SHORTCUT .AND. ;
            ! ::nLastExitState == GE_MOUSEHIT .AND. ;
            ! ::GetPostValidate( oGet, aMsg )
#else
         IF ! ::GetPostValidate( oGet, aMsg )
#endif
            oGet:exitState := GE_NOEXIT
         ENDIF
      ENDDO .......
Reply all
Reply to author
Forward
0 new messages