PosExplorer 类(POS for .NET v1.14 SDK 文档)

PosExplorer 为 Point of Service (POS) 应用程序提供一个进入 Microsoft Point of Service for .NET (POS for .NET) 服务的入口点。 PosExplorer 通过以下方式支持应用程序:

  • 枚举已安装的 POS 设备。
  • 实例化服务对象。
  • 在 POS 外围设备连接或断开连接时接收即插即用事件。

PosExplorer 属性

下表描述了 PosExplorer 属性。

属性 类型​​ 说明
PosRegistryKey 字符串 返回相对于 HKEY_LOCAL_MACHINE 的 POS for .NET 配置根注册表项。
StatisticsFile 字符串 返回包含设备统计信息的文件的路径。
SynchronizingObject ISynchronizeInvoke 保留 ISynchronizeInvoke 对象。

PosExplorer 方法

下表描述了 PosExplorer 方法。

方法 返回类型 说明
CreateInstance PosDevice 实例化设备的服务对象。
GetDevice DeviceInfo 返回指定类型的设备(在系统中必须只有一个)。
GetDevice DeviceInfo 返回具有指定逻辑名称或别名的类型的设备。
GetDevices DeviceCollection 返回所有 POS 设备。
GetDevices DeviceCollection 返回具有指定兼容性级别的所有 POS 设备。
GetDevices DeviceCollection 返回类型的 POS 设备。
GetDevices DeviceCollection 返回类型和兼容性级别的 POS 设备。
刷新 重新枚举附加的 POS 设备列表并重新生成内部数据结构。

PosExplorer 事件

下表描述了 PosExplorer 事件。

事件 说明
DeviceAddedEvent 在即插即用兼容的 POS 设备连接时接收。
DeviceRemovedEvent 在即插即用兼容的 POS 设备断开连接时接收。

示例

下面的代码示例演示如何创建 PosExplorer 的实例、连接到即插即用事件,以及使用它标识所有连接的磁条阅读器 (MSR) 设备。 代码示例将有关 MSR 的信息打印到控制台,并在完成后关闭设备。

// Creates a new instance of an MSR.
void CreateMsr(DeviceInfo msrinfo)
{
    msr = (Msr)explorer.CreateInstance(msrinfo);
    msr.Open();
    msr.Claim(1000);
    msr.DeviceEnabled = true;
}

static void Main(string[] args)
{

    // Create a new instance of PosExplorer and use it to
    // collect device information.
    PosExplorer explorer = new PosExplorer();
    DeviceCollection devices = explorer.GetDevices();

    // Search all connected devices for an MSR, print its service
    // object name to the console, and close it when finished.
    foreach (DeviceInfo device in devices)
    {
      if (device.Type == DeviceType.Msr)
      {
         if (device.ServiceObjectName == currentMsr)
         {
            CreateMsr(device);
            Console.WriteLine(device.ServiceObjectName);

            // It is important that applications close all open
            // Service Objects before terminating.
            msr.Close();
            msr = null;
         }
      }
    }
}

另请参阅

概念

其他资源