.NET용 Microsoft POS(POS for .NET)는 UnifiedPOS(Unified Point of Service) 사양에 따라 비동기 출력을 지원합니다. 비동기 출력 모델에서 서비스 개체는 가능한 한 빨리 애플리케이션에 제어를 반환할 수 있도록 출력 요청을 큐에 대기해야 합니다. 그런 다음, 두 번째 스레드는 OutputCompleteEvent 또는 ErrorEvent 이벤트를 사용하여 디바이스에 출력을 디스패치하고 요청이 처리되면 애플리케이션에 알려야 합니다.
.NET용 POS 클래스 라이브러리는 비동기 출력 디바이스와 동기 출력 전용 디바이스 간의 차이가 거의 없도록 Service Object 개발자를 위해 이러한 함수의 대부분을 처리합니다.
프로젝트를 만들려면
Visual Studio 클래스 라이브러리 프로젝트를 만듭니다.
아래 샘플 코드를 프로젝트에 추가합니다.
Microsoft.PointOfService 어셈블리에 대한 참조를 추가합니다.
서비스 개체를 컴파일하여 Service Object 어셈블리 로드 경로의 디렉터리 중 하나에 복사합니다.
서비스 개체와 함께 애플리케이션 샘플을 사용하려면
- 이 서비스 개체는 이벤트 처리기 샘플에 제공된 애플리케이션 샘플과 함께 사용할 수 있습니다.
예
PosPrinter 디바이스로 출력하기 위해 애플리케이션은 가장 일반적으로 PrintNormal(PrinterStation, String) 메서드를 사용합니다. 아래의 PosPrinter 서비스 개체 코드는 이 메서드에 대한 구현을 제공하지 않습니다. 대신 PrintNormalImpl(PrinterStation, PrinterState, String)이 구현됩니다. 이 메서드는 동기 및 비동기 출력 요청 모두에 대한 .NET용 POS 라이브러리에서 호출합니다.
애플리케이션이 PrintNormal과 같은 출력 메서드를 호출하는 경우 .NET용 POS 구현에서는 AsyncMode 속성 값을 확인합니다. 이 값이 false이면 .NET용 POS 라이브러리가 즉시 PrintNormalImpl에 요청을 보내고 요청이 반환되기를 기다립니다. 그러나 값이 true이면 PrintNormal의 .NET용 POS 구현은 내부에서 관리하는 큐에 요청을 추가합니다. 큐에 여러 항목이 있을 때 .NET용 POS 관리 스레드는 PrintNormalImpl을 호출하여 각 요청을 FIFO(선입선출) 순서로 디바이스로 보냅니다. PrintNormalImpl이 반환되면 라이브러리 구현은 애플리케이션에서 OutputCompleteEvent을 발생시킵니다. 한마디로, 사용 중인 출력 모드를 알 필요 없이 동일한 서비스 개체 코드가 동기 및 비동기 출력을 모두 지원할 수 있습니다.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.PointOfService;
using Microsoft.PointOfService.BaseServiceObjects;
[assembly: PosAssembly("Service Object Contractors, Inc.")]
namespace SOSamples.AsyncOutput
{
[ServiceObject(
DeviceType.PosPrinter,
"AsyncOutputPrinter",
"Sample Async Printer",
1,
9)]
public class AsyncOutputSimulator : PosPrinterBase
{
public AsyncOutputSimulator()
{
DevicePath = "Sample Async Printer";
// Indicate that the Service Object supports
// the receipt printer.
Properties.CapRecPresent = true;
}
// Note that this method will be called by the POS for .NET
// library code, regardless of whether the print request
// is synchronous or asynchronous. The print request
// queue is managed completely by POS for .NET so the
// Service Object should simply write data to the device
// here.
protected override PrintResults PrintNormalImpl(
PrinterStation station,
PrinterState printerState,
string data)
{
// Your code to print to the actual hardware would go
// here.
// For demonstration, however, the code simulates
// that fulfilling this print request took 4 seconds.
Thread.Sleep(4000);
PrintResults results = new PrintResults();
return results;
}
// This method must be implemented by the Service
// Object, and should validate the data to be printed,
// including any escape sequences. This method should throw
// a PosControlException to indicate failure.
protected override void ValidateDataImpl(
PrinterStation station,
string data)
{
// Insert your validation code here.
return;
}
#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 device is open, claimed, and enabled.
VerifyState(true, true);
// Insert 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 Implement Abstract PosCommon Members
}
}
이벤트 처리기 샘플의 애플리케이션 코드는 이 서비스 개체를 사용하여 컴파일하고 실행할 수 있습니다.