与其他服务对象基类相比,LineDisplayBase 类是一个相对精简的抽象层 - 应用程序和物理设备之间几乎不需要代码。 LineDisplay 服务对象只需播发物理设备支持的功能,并根据应用程序设置的显示属性修改其输出。
LineDisplay 服务对象还可以监视设备,并使用 StatusUpdateEvent 向应用程序报告电源或其他状态恢复情况。 这可以通过使用 Queue 方法来实现,例如,通过使用 PosCommon 中的电源报告功能。 以这种方式监视设备通常需要启动新线程以等待硬件事件并将相应的 StatusUpdateEvent 排队。 LineDisplay 服务对象还可以将 DirectIOEvents 发送到应用程序。
实现 LineDisplay 类和属性
为 Microsoft.PointOfService 和 Microsoft.PointOfService.BaseServiceObject 命名空间添加 using 指令。
添加全局属性 PosAssemblyAttribute,以便 PosExplorer 将其识别为 Microsoft Point of Service for .NET (POS for .NET) 程序集。
创建派生自 LineDisplayBase 的新类。
将类级属性 ServiceObjectAttribute 添加到新类,以便 PosExplorer 将其识别为服务对象。
实现抽象 LineDisplayBase 成员
所有 LineDisplay 服务对象必须支持至少一种屏幕模式。 若要向应用程序提供有关支持的屏幕模式的详细信息,请实现抽象属性 LineDisplayScreenModes。
至少,所有 LineDisplay 服务对象都必须实现 DisplayData(Cell[]) 才能在输出设备上显示字符。
其他功能
在服务对象中设置功能属性,以播发对设备功能的支持。 此示例演示如何实现 LineDisplay 闪烁功能。
实现闪烁功能
在构造函数中,将 CapBlink 属性设置为 DisplayBlink.All 或 DisplayBlink.Each 以指示此服务对象支持的闪烁模式。
将 CapBlink 属性设置为 true,指示闪烁速率可由应用程序通过调用 BlinkRate 来设置。
实现 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
}
}