次の方法で共有


サービス オブジェクト作成のサンプル (POS for .NET v1.14 SDK ドキュメント)

前のトピックでは、プラグ アンド プレイのサポートを使って基本的なサービス オブジェクト テンプレートを作成する方法について説明しました。 このセクションでは、次の新しい機能を使って限定されたサンプルを作成する方法を追加します。

  • 必要な抽象的メソッドを実装し、サンプルのコンパイルが正常に行われるようにします。
  • サービス オブジェクトは、たとえば SDK に含まれる POS for .NET テスト アプリケーションのように、PosExplorer を使うアプリケーションによって認識されます。
  • アプリケーションは、サービス オブジェクトのメソッドを呼び出したり、プロパティにアクセスできますが、有用な結果は返されません。

要件

このサンプルをコンパイルするには、プロジェクトに正しい参照とグローバル属性が必要です。

using System;
using Microsoft.PointOfService;
using Microsoft.PointOfService.BaseServiceObjects;

namespace Samples.ServiceObjects.MSR
{
    [HardwareId(@"HID\Vid_05e0&Pid_038a", @"HID\Vid_05e0&Pid_038a")]

    [ServiceObject(DeviceType.Msr,
        "SampleMsr",
        "Sample Msr Service Object",
        1,
        9)]
    public class SampleMsr : MsrBase
    {
        //  String returned from CheckHealth
        private string MyHealthText;

        public SampleMsr()
        {
            // Initialize device capability properties.
            Properties.CapIso = true;
            Properties.CapTransmitSentinels = true;
            Properties.DeviceDescription = "Sample MSR";

            // Initialize other class variables.
            MyHealthText = "";
        }

        ~SampleMsr()
        {
            Dispose(false);
        }

        // Release any resources managed by this object.
        protected override void Dispose(bool disposing)
        {
            try
            {
                // Your code here.
            }
            finally
            {
                // Must call base class Dispose.
                base.Dispose(disposing);
            }
        }

        #region PosCommon overrides
        // Returns the result of the last call to CheckHealth().
        public override string CheckHealthText
        {
            get
            {
                // MsrBasic.VerifyState(mustBeClaimed,
                // mustBeEnabled). This may throw an exception.
                VerifyState(false, false);

                return MyHealthText;
            }
        }

        public override string CheckHealth(
                    HealthCheckLevel level)
        {
            // Verify that device is open, claimed, and enabled.
            VerifyState(true, true);

            // Your code here:
            // check the health of the device and return a
            // descriptive string.

            // Cache result in the CheckHealthText property.
            MyHealthText = "Ok";
            return MyHealthText;
        }

        public override DirectIOData DirectIO(
                        int command,
                        int data,
                        object obj)
        {
            // Verify that device is open.
            VerifyState(false, false);

            return new DirectIOData(data, obj);
        }
        #endregion // PosCommon overrides

        #region MsrBasic Overrides
        protected override MsrFieldData ParseMsrFieldData(
                        byte[] track1Data,
                        byte[] track2Data,
                        byte[] track3Data,
                        byte[] track4Data,
                        CardType cardType)
        {
            // Your code here:
            // Implement this method to parse track data
            // into fields which will be returned as
            // properties to the application
            // (for example, FirstName,
            // AccountNumber, etc.)
            return new MsrFieldData();
        }

        protected override MsrTrackData ParseMsrTrackData(
                        byte[] track1Data,
                        byte[] track2Data,
                        byte[] track3Data,
                        byte[] track4Data,
                        CardType cardType)
        {

            // Your code here:
            // Implement this method to convert raw track data.
            return new MsrTrackData();
        }
        #endregion
    }
}

このサンプルを簡単にするため、コードにはグローバリゼーション機能を実装していません。 たとえば、Properties.DeviceDescription の値は、通常、ローカライズされた文字列リソース ファイルから読み取られます。

参照

タスク

概念

その他の参照情報