Input on how to capture hand scanner input

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Input on how to capture hand scanner input

Post by Grovkillen » Tue May 18, 2021 10:33 am

I'm automating a workshop and we are using integrated hand scanners to speed up data input into the production system. I have this working but is there a better way?

Code: Select all

Dialog>Dialog_get_scanner_data
object Dialog_get_scanner_data: TForm
  Width = 0
  Height = 0
  BorderIcons = []
  BorderStyle = bsNone
  object editClipBoard: TEdit
    Left = 0
    Top = 0
    Width = 0
    Height = 0
    Text = ''
  end
end
EndDialog>Dialog_get_scanner_data

Show>Dialog_get_scanner_data
Let>WIN_USEHANDLE=1
Let>MAX_TIME_TO_LISTEN=10
Let>TEXT_CAPTURED=
ResizeWindow>Dialog_get_scanner_data.HANDLE,0,0
MoveWindow>Dialog_get_scanner_data.HANDLE,0,0
Label>RECHECK
Let>WAIT_MORE=no
SetDialogObjectFocus>Dialog_get_scanner_data,editClipBoard
Wait>1
GetDialogProperty>Dialog_get_scanner_data,editClipBoard,Text,TEXT_CAPTURED_NOW
If>TEXT_CAPTURED_NOW=
  Let>WAIT_MORE=yep
Endif>
IfNot>TEXT_CAPTURED_NOW=TEXT_CAPTURED
  Let>WAIT_MORE=yep
Endif>
If>{(%TEXT_CAPTURED_NOW% = %TEXT_CAPTURED%) and (%WAIT_MORE% = "no")}
  Let>MAX_TIME_TO_LISTEN=0
Endif>
Let>TEXT_CAPTURED=TEXT_CAPTURED_NOW
Sub>MAX_TIME_TO_LISTEN,1
If>MAX_TIME_TO_LISTEN<1
  Let>WAIT_MORE=no
Endif>
If>WAIT_MORE=yep
  Goto>RECHECK
Endif>
MDL>TEXT_CAPTURED
The idea is that the script will monitor the edit field and as long as characters is being added to the edit field the script will wait some more.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Input on how to capture hand scanner input

Post by Djek » Tue May 18, 2021 7:36 pm

hi Grov
i (ab)use the memo object for this usage;
because the handheld scanners i use i have programmed the handheld scanner a CRLF to be added after the barcode is scanned.

hope this helps,
Kind regards
Djek

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 438
  Top = 165
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 151
  ClientWidth = 281
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSMemo1: tMSMemo
    Left = 25
    Top = 30
    Width = 184
    Height = 27
    ImeMode = imOpen
    VertScrollBarStyles.ButtonSize = 16
    HorzScrollBarStyles.ButtonSize = 16
    TabOrder = 0
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,DoClose
AddDialogHandler>Dialog1,MSMemo1,OnKeyUp,DoKeyPress

show>Dialog1

label>loop
wait>1
if>Terminated=TRUE
  goto>endall
endif
goto>loop

SRT>DoKeyPress
  GetDialogProperty>Dialog1,MSMemo1,text,scaninput
  StringReplace>scaninput,%CRLF%,,scaninput
  GetDialogProperty>Dialog1,MSMemo1,linecount,Lcount
  if>Lcount>1
    Message>scaninput
    // scaninput is the output for your data
    wait>0.3
    SetDialogProperty>Dialog1,MSMemo1,text,
  endif
END>DoKeyPress

SRT>DoClose
 Let>Terminated=TRUE
End>DoClose


label>endall


User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Input on how to capture hand scanner input

Post by Grovkillen » Wed May 19, 2021 8:04 am

That's darn clever! THANK YOU! :)

PS. the scanner is placing a line break after each scan for me as well.
Last edited by Grovkillen on Wed May 19, 2021 4:55 pm, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Input on how to capture hand scanner input

Post by Grovkillen » Wed May 19, 2021 9:02 am

I ended up with a "while" loop like this:

Code: Select all

Dialog>Dialog_get_scanner_data
object Dialog_get_scanner_data: TForm
  BorderIcons = []
  BorderStyle = bsNone
  object inputMemo: tMSMemo
    Left = 0
    Top = 0
    Width = 300
    Height = 40
  end
end
EndDialog>Dialog_get_scanner_data
AddDialogHandler>Dialog_get_scanner_data,inputMemo,OnKeyUp,DoKeyPress

show>Dialog_get_scanner_data

Let>WIN_USEHANDLE=1
ResizeWindow>Dialog_get_scanner_data.HANDLE,300,40
MoveWindow>Dialog_get_scanner_data.HANDLE,0,0
Let>WAIT_TIME=0.1
Let>MAX_TIME_TO_LISTEN=30
While>MAX_TIME_TO_LISTEN>0
  Wait>WAIT_TIME
  Let>MAX_TIME_TO_LISTEN=MAX_TIME_TO_LISTEN-WAIT_TIME
EndWhile>

MDL>QR_CAPTURED
  
SRT>DoKeyPress
  SetDialogObjectFocus>Dialog_get_scanner_data,inputMemo
  GetDialogProperty>Dialog_get_scanner_data,inputMemo,Text,QR_CAPTURED
  StringReplace>QR_CAPTURED,%CRLF%,,QR_CAPTURED
  GetDialogProperty>Dialog_get_scanner_data,inputMemo,LineCount,INPUT_CAPTURED
  If>INPUT_CAPTURED>1
    Let>MAX_TIME_TO_LISTEN=0
  Endif>
END>DoKeyPress
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts