Jump to content

Detect Read Barcode


Recommended Posts

Hi Loken

many barcode reader are connected "in the middle" between the keyboard and the ps/2 connector of the p.c.

so, when it reads the barcode, is like if you type that code directly on the keyboard.
What type of barcode reader is your?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Other readers use a USB interface and the most popular/cheap of them are driverless. They fake input by identifying as keyboard and emit ASCII codes by sending ALT+<value> sequences.

See >this thread.

Here are the code I've been using. Note that it may be a bit rusty but I know it already helped others.

All I can do quickly is join you the sample code. Look for a line wth @@@@@@@@@ for interesting point.
I haven't used this code for years...
You'll probably have to list HID devices properties to determine which is which, which makes the code somehow specific to a particular setup.
I hope this will help you out.

Barcode Reader Filter.au3

RawInput.au3

EDIT: attachments fixed.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Pincopanco ,  I use an usb barcode reader . It's model is ' HandHeld N10410 ' . I want to detect it's action to run a script which can do automate the IBS program. 

jchd , I cant download your attachments , I get this error ' Sorry, you don't have permission for that! ' . May you upload from your computer , please ?

I can't solve the problem yet , Thanks for all readers :shifty:

Link to comment
Share on other sites

Sorry. Fixed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Are you saying that your reader doesn't actually send barcode data to the PC?

The code posted only helps sorting out what comes from the keyboard and what is from BC reader. These are mostly snippets to be adjusted to your use case.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 2 years later...

Sorry but I don't have the time right now to go back thru this. The idea is to first enumerate the various HID devices and then determine which is the one of interest. After that you can pass the correct parameters to intercept raw input and perform the task you need. You'll need to read the code(s) posted and understand the different pieces to get the picture.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 4 weeks later...

Thanks anyway. Got it finally working. Used RawInput.au3 and input filtration "all but keyboard". Inside of _OnInput() i do some filtering for unacepted chars and proper string (accepted only those with letters A and K ald later certain stirng lenght is filtered out).

Func _OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_KD, $pRI_KD, $iRI_KB
    Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
    Local $iSize



    $tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
    $pRI_KD = DllStructGetPtr($tRI_KD)
    $iRI_KB = DllStructGetSize($tRI_KD)

    $tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
    $pRIDI_HID = DllStructGetPtr($tRIDI_HID)
    $iRIDI_HID = DllStructGetSize($tRIDI_HID)
    DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)

    _GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)

    If Not @error Then
        $hdevice = DllStructGetData($tri_kd, "hDevice")
        $vkey = DllStructGetData($tri_kd, "VKey")

        If $KEYBOARD_ID = "" Then
            $KEYBOARD_ID = 0x000B003F ; default keyboard ID on my PC
        EndIf


    EndIf

    _GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
    If Not @error Then
        $hDevice2  = DllStructGetData($tRI_KD, 'hDevice')
        $dwVendorId  = DllStructGetData($tRIDI_HID, 'dwVendorId')
        $dwProductId = DllStructGetData($tRIDI_HID, 'dwProductId')
        $dwType   = DllStructGetData($tRI_KD, 'dwType')
    EndIf


    If DllStructGetData($tRI_KD, 'hDevice') <> $KEYBOARD_ID Then

;~          $vKey    = DllStructGetData($tRI_KD, 'VKey');F3 = 114
;~          ConsoleWrite(Chr($vKey))

            If $on Then
                $t=$t& Chr($vKey)
    ;~          ConsoleWrite($t&@CR)
                $on=0
            Else
                $on=1
            EndIf

    EndIf

    $tRI_KD = 0


$t = StringRegExpReplace ( $t,  "(?i)[^0-9AK\.]", "" )

; K number
    If StringLen($t) = 10 Then
        If StringInStr($t, "K") Then

            _insert_barcode()

        EndIf
; ; A number
    ElseIf StringLen($t) = 8 Then
        If StringInStr($t, "A") Then


            _insert_barcode()

        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

I still do not know how to prevent dublication of strings, i use some loop in function _insert_barcode()... Code dirty... but it works...

Func _insert_barcode()
Local   $state_GUI6 = WinGetState($hGUI6)
        $state = WinGetState($hGUI7)

   $iLoop_Count += 1

If $iLoop_Count = 1 Then


    GUICtrlSetData($input_barcode, $t)


    $state_GUI6 = WinGetState($hGUI6)
    ConsoleWrite("$state GUI6..." & $state_GUI6 & @CRLF)
    If BitOR($state_GUI6 = 7, $state_GUI6 = 15) Then
;~      _listview_gui_close_to_barcode()

        GUICtrlSetData($input_barcode, $t)
    EndIf

        GUICtrlSetState($input_barcode, $GUI_FOCUS)
        $state = WinGetState($hGUI7)
        ConsoleWrite("$state GUI7..." & $state & @CRLF)
        
        If BitOR($state = 7, $state = 23) Then ; background (7) or minimized (23)

            If StringLen($t) <> 0 Then
                ConsoleWrite("StringLen($t): " & StringLen($t) & @CRLF)
                ConsoleWrite("$iLoop_Count: " & $iLoop_Count & @CRLF)
                ConsoleWrite("$t: " & $t & @CRLF)
                    ControlClick($name7, "", "[CLASS:Button; TEXT:OK]")

            EndIf
        ; should check for state to send click
        If $state_GUI6 = 5 And BitOR($state = 7, $state = 23) Then
                ControlClick($name7, "", "[CLASS:Button; TEXT:OK]")
        EndIf
    ElseIf $state = 15 Then ; foreground, focused
            GUICtrlSetData($input_barcode, $t)
; no need for click, accepted by scanner
    Else

        ConsoleWrite("$t empty. No Click here..." & @CRLF)
    EndIf
EndIf

    $iLoop_Count = 0
    $t = ""
EndFunc

 

Edited by juzis28
Link to comment
Share on other sites

Glad you found your way in this little mess.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...