次の方法で共有


PosExplorer クラス (POS for .NET v1.14 SDK ドキュメント)

PosExplorer は、Microsoft Point of Service for .NET (POS for .NET) サービスへの 1 つのエントリ ポイントを Point of Service (POS) アプリケーションに提供します。 PosExplorer は、次の方法でアプリケーションをサポートします。

  • インストールされている POS デバイスを列挙します。
  • サービス オブジェクトのインスタンスを作成します。
  • POS 周辺デバイスが接続されたとき、または切断されたときにプラグ アンド プレイ イベントを受信します。

PosExplorer のプロパティ

次の表では、PosExplorer のプロパティについて説明します。

プロパティ タイプ 説明
PosRegistryKey string HKEY_LOCAL_MACHINE を基準にした POS for .NET 構成ルート レジストリ キーを返します。
StatisticsFile string デバイスの統計情報が格納されているファイルへのパスを返します。
SynchronizingObject ISynchronizeInvoke ISynchronizeInvoke オブジェクトを保持します。

PosExplorer のメソッド

次の表では、PosExplorer のメソッドについて説明します。

メソッド 返り値の種類 説明
CreateInstance PosDevice デバイスのサービス オブジェクトのインスタンスを作成します。
GetDevice DeviceInfo 指定された入力値の型のデバイス (システム内に 1 つだけである必要があります) を返します。
GetDevice DeviceInfo 指定された論理名または別名を持つ型のデバイスを返します。
GetDevices DeviceCollection すべての POS デバイスを返します。
GetDevices DeviceCollection 指定された互換性レベルを持つすべての POS デバイスを返します。
GetDevices DeviceCollection 型の POS デバイスを返します。
GetDevices DeviceCollection 型と互換性レベルを持つ POS デバイスを返します。
更新 なし アタッチされている POS デバイスの一覧を再列挙し、内部データ構造を再構築します。

PosExplorer イベント

次の表では、PosExplorer のイベントについて説明します。

Event 説明
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;
         }
      }
    }
}

参照

概念

その他の参照情報