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

Microsoft Point of Service for .NET (POS for .NET) のエラー処理は、"例外" を使用して実装されます。 .POS for .NET の 4 つの例外クラスは次のとおりです。

標準の Unified Point Of Service (UnifiedPOS) のエラー コードは、ErrorCode 列挙体によって表されます。

PosException

PosException は、PosControlException、PosManagementException、および PosLibraryException の基底例外クラスです。 PosException は System.Exception から派生します。

PosControlException

PosControlException は、サービス オブジェクトによって POS for .NET アプリケーションにスローされる標準の例外です。

PosManagementException

PosManagementException は、POS for .NET のデバイス管理によってスローされます。 アプリケーションとサービス オブジェクトでは、PosManagementException をスローしてはいけません。

PosLibraryException

PosLibraryException は PosExplorer によってスローされます。 アプリケーションとサービス オブジェクトでは、PosLibraryException をスローしてはいけません。

エラー コード

次の表は、UnifiedPOS の標準エラー コードと、POS for .NET で提供される ErrorCode 値のマッピングを示したものです。

POS の ErrorCode メンバー UnifiedPOS のエラー コード エラーの原因
ビジー E_BUSY 現在のサービス オブジェクトの状態では、この要求は許可されません。
Claimed E_CLAIMED 別のサービス オブジェクト インスタンスがこの POS デバイスを既に要求しています。
解決済み E_CLOSED POS デバイスが閉じられています。
非推奨 E_DEPRECATED このメソッドは非推奨となり、利用できなくなりました。
無効 E_DISABLED デバイスが無効になっている間は、操作を実行できません。
Exists E_EXISTS ファイル名、または指定されたその他の値は既に存在します。
Extended E_EXTENDED デバイス固有のエラー状態が発生しました。
障害 E_FAILURE この POS デバイスは、システムに接続されていてアクティブであっても、要求された手順を実行できません。
Illegal E_ILLEGAL POS アプリケーションがデバイスに対して無効またはサポートされていない操作を試行したか、無効なパラメーター値を使用しました。
NoExist E_NOEXIST ファイル名、または指定されたその他の値が存在しません。
NoHardware E_NOHARDWARE POS デバイスがシステムに接続されていないか、電源が入っていません。
NoService E_NOSERVICE サービス オブジェクトがデバイスと通信できません (通常は、セットアップまたは構成のエラーが原因です)。
NotClaimed E_NOTCLAIMED POS アプリケーションが排他使用デバイスにアクセスしようとしましたが、メソッドまたはプロパティ設定アクションを使用するには、まずこのデバイスを要求する必要があります。
オフライン E_OFFLINE POS デバイスがオフラインです。
タイムアウト E_TIMEOUT POS デバイスからの応答を待機しているサービス オブジェクトがタイムアウトしました。

例

次のコード例は、MSR が POS の例外を処理し、それらの例外に含まれる ErrorCode を使用して、それらに関する情報を収集する方法を示しています。

// Create a new instance of the MSR and opens the device.
msr = (Msr)explorer.CreateInstance(msrinfo);
msr.Open();

// Try to enable the device without first claiming it.
// This will throw a PosControlException which, through
// its ErrorCode, will yield information about the exception.
try
{
   msr.DeviceEnabled = true;
}
catch (PosControlException e)
{

   // Examine the ErrorCode to determine the cause of the error.
   if (e.ErrorCode == ErrorCode.NoHardware)
   {
      Console.WriteLine("The POS device is not connected ");
      Console.WriteLine("to the system or is not turned on.");
   }
   if (e.ErrorCode == ErrorCode.Timeout)
   {
      Console.WriteLine("The Service Object timed out
            waiting for a response from the POS device.");
   }

   // The example has not claimed the MSR, which is an
   // exclusive-access device, before trying to enable
   // it. This will throw the PosControlException
   // and trigger the following conditional block.
   // Once triggered, the MSR will be claimed and enabled.
   if (e.ErrorCode == ErrorCode.NotClaimed)
   {
      Console.WriteLine("The POS application attempted to access ");
      Console.WriteLine("an exclusive-use device that must be ");
      Console.WriteLine("claimed before the method or property ");
      Console.WriteLine("set action can be used.")
      msr.Claim(1000);
      msr.DeviceEnabled = true;
   }
}

参照

リファレンス

概念

その他の参照情報