3

我有一个 Metro Technologies 的条形码扫描仪,我正在使用 Microsoft POS 来检测来自扫描仪的输入。它使用 USB 端口连接到我的系统。但是扫描仪没有被 POS 识别。

public Form1()
{
InitializeComponent();
explorer = new PosExplorer(this);
explorer.DeviceAddedEvent += new
DeviceChangedEventHandler(explorer_DeviceAddedEvent);
}


void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e)
{
if (e.Device.Type == "Scanner")
{
scanner = (Scanner)explorer.CreateInstance(e.Device);
scanner.Open();
scanner.Claim(1000);
scanner.DeviceEnabled = true;
scanner.DataEvent += new
DataEventHandler(activeScanner_DataEvent);
scanner.DataEventEnabled = true;
scanner.DecodeData = true;
}
}

void activeScanner_DataEvent(object sender, DataEventArgs e)
{
UpdateEventHistory("Data Event");
ASCIIEncoding encoder = new ASCIIEncoding();
try
{
// Display the ASCII encoded label text
txtbScanDataLabel.Text =
encoder.GetString(activeScanner.ScanDataLabel);
// Display the encoding type
txtbScanDataType.Text = activeScanner.ScanDataType.ToString();

// re-enable the data event for subsequent scans
activeScanner.DataEventEnabled = true;
}
catch (PosControlException)
{
// Log any errors
UpdateEventHistory("DataEvent Operation Failed");
}
}
4

4 回答 4

2

从一些论坛以及 POS SDK 文档中:

您必须将其添加到目录中的 xml 文件中:

C:\Program Files\Common Files\microsoft shared\Point Of Service\Control Configurations\


<PointOfServiceConfig Version="1.0">
 <ServiceObject Type="Scanner" Name="Example scanner">
  <HardwareId From="HID\VID_04B4&amp;PID_0100&amp;REV_0001" To="HID\VID_04B4&amp;PID_0100&amp;REV_0001" />
 </ServiceObject>
</PointOfServiceConfig>

您必须检查设备的硬件 ID 并将其替换在<HardwareId>标签内

这是即插即用配置。

于 2010-12-14T18:00:40.777 回答
0

这是整个代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.PointOfService;
using System.Collections;

namespace MicrosoftPOSScannerSample
{
    public partial class Form1 : Form
    {
        private PosExplorer explorer;
        private Scanner scanner;

        public Form1()
        {
            InitializeComponent();
            explorer = new PosExplorer(this);
            explorer.DeviceAddedEvent += new DeviceChangedEventHandler(explorer_DeviceAddedEvent);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void UpdateEventHistory(string newEvent)
        {
            txtbEventHistory.Text = newEvent + System.Environment.NewLine + txtbEventHistory.Text;
        }

        void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e)
        {
            if (e.Device.Type == "Scanner")
            {
                scanner = (Scanner)explorer.CreateInstance(e.Device);
                scanner.Open();
                scanner.Claim(1000);
                scanner.DeviceEnabled = true;
                scanner.DataEvent += new DataEventHandler(scanner_DataEvent);
                scanner.DataEventEnabled = true;
                scanner.DecodeData = true;
            }
        }

        void scanner_DataEvent(object sender, DataEventArgs e)
        {
            UpdateEventHistory("Data Event");
            ASCIIEncoding encoder = new ASCIIEncoding();
            try
            {
                // Display the ASCII encoded label text
                txtbScanDataLabel.Text = encoder.GetString(scanner.ScanDataLabel);
                // Display the encoding type
                txtbScanDataType.Text = scanner.ScanDataType.ToString();

                // re-enable the data event for subsequent scans
                scanner.DataEventEnabled = true;
            }
            catch (PosControlException)
            {
                // Log any errors
                UpdateEventHistory("DataEvent Operation Failed");
            }
        }

    }
}
于 2009-08-27T20:51:45.000 回答
0

我不熟悉您正在使用的扫描仪,但是在您通常希望确保扫描仪本身配置为正确的模式/设置/等之前,我已经使用过所有这些。通常这是通过手册中的配置序列来完成的,您将在其中扫描对设备进行编程的各种条形码。

如果不出意外,您可以排除硬件配置的问题,而不是您的代码。

explorer_DeviceAddedEvent永远火吗?

在哪里scanner 初始化activeScanner

[编辑]

检查扫描仪本身或随附的文档以获取硬件 ID (HID),尝试将以下行添加到您的代码中。

[HardwareId(@"this is where the HID goes")]

看看这是否能让你更进一步......有关更多信息,请参阅此处,你可以提供 HID 或将该信息添加到 XML 配置文件中

于 2009-08-27T18:13:28.097 回答
-1

我在这里找到了配置(Windows 7平台):

C:\Documents and Settings\All Users\Application Data\Microsoft\Point Of Service\Configuration\Configuration.xml

于 2012-02-15T01:06:09.213 回答