次の方法で共有


LineDisplay のサンプル (POS for .NET v1.14 SDK ドキュメント)

他のサービス オブジェクトの Base クラスと比較して、LineDisplayBase クラスは比較的薄い抽象化レイヤーです。アプリケーションと物理デバイスの間に必要なコードはほとんどありません。 LineDisplay サービス オブジェクトで必要なのは、物理デバイスがサポートする機能をアドバタイズし、アプリケーションが設定した表示プロパティに従って出力を変更することだけです。

また、LineDisplay サービス オブジェクトは、デバイスを監視し、StatusUpdateEvent を使って電源や他の状態の変化をアプリケーションに報告することもできます。 これを行うには、Queue メソッドを使うか、またはたとえば PosCommon の電源レポート機能を使います。 この方法でデバイスを監視するには、通常、新しいスレッドを開始してハードウェア イベントを待機し、適切な StatusUpdateEvent をキューに登録する必要があります。 LineDisplay サービス オブジェクトは、DirectIOEvents をアプリケーションに送信することもできます。

LineDisplay クラスと属性を実装するには

  1. Microsoft.PointOfServiceMicrosoft.PointOfService.BaseServiceObject 名前空間の using ディレクティブを追加します。

  2. PosExplorer がこれを Microsoft Point of Service for .NET (POS for .NET) アセンブリとして認識するように、グローバル属性 PosAssemblyAttribute を追加します。

  3. LineDisplayBase から派生される新しいクラスを作成します。

  4. PosExplorer でサービス オブジェクトとして認識されるように、クラス レベルの属性 ServiceObjectAttribute を新しいクラスに追加します。

LineDisplayBase の抽象メンバーを実装するには

  1. すべての LineDisplay サービス オブジェクトは、少なくとも 1 つの画面モードをサポートする必要があります。 サポートされている画面モードに関する詳細をアプリケーションに提供するには、抽象プロパティ LineDisplayScreenModes を実装します。

  2. すべての LineDisplay サービス オブジェクトは、少なくとも、出力デバイスに文字を表示するための DisplayData(Cell[]) を実装する必要があります。

その他の機能

デバイスの機能のサポートをアドバタイズするには、サービス オブジェクトで機能プロパティを設定します。 このサンプルでは、LineDisplay の点滅機能を実装する方法を示します。

  1. コンストラクターで CapBlink プロパティを DisplayBlink.All または DisplayBlink.Each に設定し、このサービス オブジェクトでサポートする点滅モードを示します。

  2. CapBlink プロパティを true に設定し、アプリケーションで BlinkRate を呼び出すことによって点滅速度を設定できることを示します。

  3. DisplayData を実装するときは、これらおよび他の設定を考慮します。

using System;
using System.Collections.Generic;
using System.Text;

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

[assembly: PosAssembly("Service Object Contractors, Inc.")]

namespace SOSample.LineDisplay
{
    [ServiceObject(
            DeviceType.LineDisplay,
            "SampleLineDisplay",
            "Sample LineDisplay Service Object",
            1,
            9)]

    public class SampleLineDisplay : LineDisplayBase
    {
        SampleLineDisplay()
        {
            // The CapBlink property is initially set to
            // DisplayBlink.None in LineDisplayBase. This property
            // will be set here to indicate what mode of blinking
            // text our Service Object can support.
            Properties.CapBlink = DisplayBlink.All;

            // Set the CapBlinkRate property to true to indicate
            // that this device has the ability to change the
            // rate at which it blinks by setting the property
            // BlinkRate.
            Properties.CapBlinkRate = true;
        }

        #region Implement Abstract LineDisplayBase Members
        // LineDisplayScreenMode must be implemented to
        // allow the application to find out which screen modes
        // are supported by this device.
        protected override LineDisplayScreenMode[]
                                    LineDisplayScreenModes
        {
            get
            {
                LineDisplayScreenMode[] SupportedModes;

                // Create a LineDisplayScreenMode object; this SO
                // has a screen mode 10 columns wide and 2 rows deep.
                LineDisplayScreenMode mode =
                        new LineDisplayScreenMode(10, 2, 0, 0);

                // Allocate space for our screen mode array and
                // initialize it to hold our supported screen
                // mode(s).
                SupportedModes =
                        new LineDisplayScreenMode[] { mode };

                return SupportedModes;
            }
        }

        // DisplayData is the method called from the application
        // specifying what data should be displayed on the
        // device.
        protected override void DisplayData(Cell[] cells)
        {
            // Your code here:
            // Send the data to your device. Take settings such
            // as blink and blink rate into account here.
            return;
        }
        #endregion Implement Abstract LineDisplayBase Members

        #region Implement Abstract PosCommon Members
        private string MyHealthText = "";

        // PosCommon.CheckHealthText.
        public override string CheckHealthText
        {
            get
            {
                // VerifyState(mustBeClaimed,
                // mustBeEnabled).
                VerifyState(false, false);
                return MyHealthText;
            }
        }

        //  PosCommon.CheckHealth.
        public override string CheckHealth(
                        HealthCheckLevel level)
        {
            // Verify that the 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;
        }

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

            return new DirectIOData(data, obj);
        }
        #endregion Abstract PosCommon Members
    }
}

参照

その他の参照情報