Jump to content

(Solved) Trigger event when receiving input from USB device


Recommended Posts

Hey all.  I have a project I am working on for my company, and part of it requires the use of a bar code scanner to scan a large number of packages into an excel spread sheet.  However, the way that the bar code scanner interfaces with excel is not ideal (essentially between each scan we have to readjust the position of the currently active cell, which is very disruptive to workflow).  I would like to write a script which can automatically update the active cell right after the bar code scanner has input the scanned data into the previous cell, but I have absolutely no experience writing code that interfaces with hardware.  Is this something that would be beyond the scope of what AutoIT is able to do, or can someone at least point me in the right direction?  Thank you.

Edited by MattHiggs
Link to comment
Share on other sites

Can't you change the suffix code for the scanner to either a TAB or a CR?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

6 minutes ago, AutoBert said:

I think a GUI with 1 Input and using the Excel.au3 functions can do this job.

See here is the thing, I am not sure HOW to actually read information from a hardware device.  If it a UDF?  Also what exactly do you mean by one input?  Sorry, programming knowledge is not the best.  Also, Brewman, your idea sounds interesting, but how would I go about accessing the scanner's suffix code?

Edited by MattHiggs
Link to comment
Share on other sites

I'm making an assumption here....does scanning a barcode immediately type the "read" barcode like keystrokes?  If you open notepad and scan a barcode does show up in the notepad window?  I'm assuming it does.   If that is the case you don't have to do anything special or worry about reading form the hardware.  If this is not the case I apologize.

Otherwise, a GUI with 1 (a single) input field would allow you to "capture" the barcode output and then automate it using the Excel UDF.

I'd recommend starting with the GUI (easier piece), then check out the Excel UDF and look for examples on how to select cells and update their values. Let us know if you get stuck.

Link to comment
Share on other sites

Just build a Gui with 1 GuiCtrlCreateInput and test what happens when a barcode is scanned. I excpect same result as userinput on keyboard.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    GUICreate(" My GUI input accept Barcode", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
    Local $idFile = GUICtrlCreateInput("", 10, 5, 300, 20)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idFile
                MsgBox($MB_SYSTEMMODAL, "drag drop file", GUICtrlRead($idFile))
                ;your actions here
                GUICtrlSetData($idFile,''); clear input for next scan
        EndSwitch
    WEnd

EndFunc   ;==>Example

 

Edited by AutoBert
Link to comment
Share on other sites

8 minutes ago, AutoBert said:

Just build a Gui with 1 GuiCtrlCreateInput and test what happens when a barcode is scanned. I excpect same result as userinput on keyboard.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    GUICreate(" My GUI input accept Barcode", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
    Local $idFile = GUICtrlCreateInput("", 10, 5, 300, 20)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idFile
                MsgBox($MB_SYSTEMMODAL, "drag drop file", GUICtrlRead($idFile))
                ;your actions here
                GUICtrlSetData($idFile,''); clear input for next scan
        EndSwitch
    WEnd

EndFunc   ;==>Example

 

OHH.  Now I see what you mean.  Brilliant!  Thanks.  I will get to work immediately.  Thanks for the advice.

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...