10

我最近购买了 Metrologic 条码扫描仪(USB 端口),因为每个人都知道它可以作为开箱即用的键盘模拟器。

如何配置扫描仪和我的应用程序,以便我的应用程序可以直接处理条形码数据?也就是说,我不希望用户专注于“文本字段”,然后在 KeyPress 事件触发时处理数据。

4

4 回答 4

7

通常条形码扫描仪可以配置为在字符串之前和之后发送一些字符。因此,如果您在条形码字符串之前附加例如“F12”,您可以捕获它并将焦点移动到正确的字段。

检查条形码扫描仪手册如何做到这一点。

于 2010-04-22T06:33:16.657 回答
3

虽然您的条形码有一个 USB 连接器。它可以编程为键盘楔形或 RS232。请参阅此页面 http://www.instrumentsandequipmentco.com/support/faq-metrologic.htm 它说

问:USB 键盘和 USB 销售点有什么区别? 当 MX009 设置为作为 USB 键盘进行通信时,扫描的数据将出现在您 PC 上当前处于活动状态的应用程序中。就像在键盘上按下键一样输入数据。当 MX009 设置为作为 USB 销售点设备进行通信时,数据会像 RS232 数据一样传输到 USB 端口,并且 USB 端口必须像 COM 端口一样配置。MX009 出厂设置为 USB 键盘或 USB 销售点。

当您的程序接受 RS232 时,您不再需要将焦点放在文本字段中。

  1. 将您的条形码重新编程为销售点 (RS232)
  2. 通常重新编程以发送后缀 - 回车/CR/$0D 在条形码的末尾。

查找回车以了解您的代码何时可以使用完整的条形码。

于 2010-04-23T02:18:10.893 回答
1

我猜想最简单的方法是拦截更高级别的按键,例如winforms中的PreviewKeyDownKeyDown (或在表单上使用,设置KeyPreviewtrue,并用于e.SuppressKeyPress停止向下传递到控件的键)。设备可能有直接的 API;可能没有。

于 2010-04-22T06:04:55.663 回答
0

您可以在表单上使用 OnShortcut 事件来拦截键盘按下。检查您在barcodescanner上配置的前缀是否出现,并设置为Handled al keypresses,直到您获得条形码扫描仪后缀。在您的快捷方式处理程序中构建条形码字符串

以下代码改编自我自己使用的代码,但未经测试以目前的形式。

    // Variables defined on Form object
GettingBarcode : boolean;
CurrentBarcode : string;
TypedInShiftState: integer; // 16=shift, 17=ctrl, 18=alt

procedure Form1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
var
  Character:Char;
begin
  Character:=Chr(MapVirtualKey(Msg.CharCode,MAPVK_VK_TO_CHAR));
  if GettingBarcode then
  begin
    // Take care of case 
    if (TypedInShiftState<>16) and CharInSet(Character,['A'..'Z']) then
        Character:=Chr(Ord(Character)+32);
    TypedInShiftState:=0;
    // Tab and Enter programmed as suffix on barcode scanner
    if CharInSet(Character,[#9, #13]) then
    begin
      // Do something with your barcode string
      try
        HandleBarcode(CurrentBarcode);
      finally
        CurrentBarcode:='';
        Handled:=true;
        GettingBarcode:=False;
      end;
    end
    else if CharInSet(Character,[#0..#31]) then
    begin
      TypedInShiftState:=Msg.CharCode;
      Handled:=True;
    end
    else begin
      CurrentBarcode:=CurrentBarcode+Character;
      Handled:=true;
    end;
  end
  else begin
    if Character=#0 then
    begin
      TypedInShiftState:=Msg.CharCode;
    end
    else if (TypedInShiftState=18) and (Character='A') then
    begin
      GettingBarcode:=True;
      CurrentBarcode:='';
      Handled:=true;
    end;
  end;
end;
于 2010-04-22T08:33:54.407 回答