We help IT Professionals succeed at work.

Barcode reader

Lucky3664
Lucky3664 asked
on
1,741 Views
Last Modified: 2012-05-06
Hi
 I want to redirect barcode reader output to a specific edit. But Barcode reader is not provide the data from a COM, it behaves like keyboard.
How can I do that?
Thanks..
Comment
Watch Question

You may try to watch the keyboard and whenever data seems to come from the barcode reader (many digits in less time than one could type), redirect the focus to the specific edit.

Author

Commented:
I am watching the keyboard with ApplicationMessage(var Msg: TMsg;var Handled: Boolean) procedure, but for example I have two edit box the first edit is for something and second edit box for barcode data, when the first edit box focused and at that time the barcode reader started wit my procedure (ApplicationMessage(var Msg: TMsg;var Handled: Boolean)) can I write the data to the second edit box
but at same time the first edit box has the same barcode data. So I should prevent the barcode data to go any component on the form..
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
The way you say is difficult for me. is not there any function or command to prevent barcode data to for that form. for example like KeyPreview property
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
get a different scanner, like a serial port scanner
and get some tool like
http://www.taltech.com/products/bcwedge.html
that's the easiest way !


or if possible configure the scanner to send a fixed key sequence
so you know it's the scanner entering data

otherwise the only options is the timer like thehagman noted

Author

Commented:
Thanks very much both of you.
Using serial port scanning, yes it is easy way. But it comes expensive for our customers nowadays.
The second way you say it is possible solution if the scanner is configureble. But for the way of thehagman I think also I need fixed key sequence because I get all data via (WM_CHAR,WM_KEYDOWN, WM_KEYUP) messages, so the barcode scanner that I have, behaves like keybord. I think should be something that I can distinguish where from the data comes, because  whether keyboard or usb barcode reader takes different root in device menager. But how can I do, I do not know.
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
i don't think you will be able to distinguish the difference
you will however get 10, 17, 20 or a certain length X from the barcode scanner

you could start a timer for the first keystroke and if you get like X keystrokes within the timer elaps time, then you have the barcode ...
don't think windows distinguishes between barcode scanner WM_CHAR and keyboard WM_CHAR
Most barcode readers can be programmed to send a leading character such as a hash (#) in front of the barcode.  If you attach a generic OnKeyDown event to the controls on your form that could have focus, you should be able to redirect focus to your desired Edit when you dectect the hash.

Author

Commented:
Hm, I understood very well. But I have an other problem now. The procedure that I use for this become to late geting messages.

procedure ApplicationMessage(var Msg: TMsg;var Handled: Boolean);
begin
   case Msg.Message of
    WM_CHAR:
    begin
      if ToAsciiEx(Msg.wParam,MapVirtualKeyEx(Msg.wParam,2,1),KeyState,@LastKey,0,1)>0 then
      begin
         Key:=Ord(LastKey);
         BarcodeString := BarcodeString + IntToAscii(Key);
      end;
    end;
    WM_KEYDOWN, WM_KEYUP:
    case Msg.wParam of
    VK_RETURN:
      begin
       if BarcodeString <> '' then
       begin
           Edit2.SetFocus;
           Edit2.Text := BarcodeString;
           BarcodeString := '';
       end;
      end;
     end;
    end;
end;
 I use this procedure to get the barcode data, but when I push the button on barcode reader it gives me the data before my procedure. So I could not find a solution for this again. I think it will be difficult for me.
Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
i don't follow ... how do you get the data ?
what data and in what procedure (or object) ?

Author

Commented:
the procedure ApplicationMessage(var Msg: TMsg;var Handled: Boolean) works behind self when form is created. I say only  Application.OnMessage := ApplicationMessage; . Then I handel the message VM_CHAR. When I get #13 wparam (VK_RETURN) it automatically goes on  WM_KEYDOWN, WM_KEYUP: and then write the barcodestring to edit2;

Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
um ? this english looks a lot like chinese to me ... i have no clue what you are on about !

Author

Commented:
Sorry about my english.
The procedure that I send is working and I will do it again such before  thehagman and you said, so using timer and bufferin data. But in this case I should find a way to prevent the barcode reader comes before my procedure, because I noted that the procedure that I use comes to late to focusing related edit or doing something .
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.