다음을 통해 공유


서비스 지점 디바이스 클레임 및 모델 사용

서비스 포인트 디바이스 클레임을 사용하고, API가 디바이스를 클레임하도록 하고, API를 I/O 작업에 사용하도록 설정합니다.

독점적 사용에 대해 클레임 걸기

PointOfService 디바이스 개체를 만든 뒤, 디바이스 형식에 적합한 클레임 메서드를 사용하여 클레임해야 입력 또는 출력에 장치를 사용할 수 있습니다. 클레임은 애플리케이션에 디바이스의 여러 기능에 대한 독점적인 액세스를 부여하여 한 애플리케이션이 다른 애플리케이션의 디바이스 사용을 방해하지 않도록 합니다. PointOfService 디바이스의 독점적 사용에 대해 클레임을 보낼 때, 한 번에 하나의 애플리케이션에 대해서만 할 수 있습니다.

참고

클레임 작업은 디바이스에 대한 배타적 잠금을 설정하지만 작동 상태로 전환하지 않습니다. 자세한 내용은 디바이스를 I/O 작업에 사용하도록 설정을 참조하세요.

클레임/릴리스에 사용되는 API

디바이스 클레임 Release
Barcode Scanner BarcodeScanner.ClaimScannerAsync ClaimedBarcodeScanner.Close
Cash Drawer CashDrawer.ClaimDrawerAsync ClaimedCashDrawer.Close
Line Display LineDisplay.ClaimAsync ClaimedineDisplay.Close
MagneticStripeReader MagneticStripeReader.ClaimReaderAsync ClaimedMagneticStripeReader.Close
PosPrinter PosPrinter.ClaimPrinterAsync ClaimedPosPrinter.Close

디바이스를 I/O 작업에 사용하도록 설정

클레임 작업은 장치에 대한 독점적 권한을 설정하지만 작동 상태로 전환하지는 않습니다. 이벤트를 수신하거나 출력 작업을 수행하려면 EnableAsync를 사용하여 디바이스를 사용하도록 설정해야 합니다. 반대로, DisableAsync를 호출하여 디바이스에서 이벤트 수신을 중지하거나 출력 수행을 중지할 수 있습니다. IsEnabled를 사용하여 디바이스의 상태를 확인할 수도 있습니다.

API 사용/사용 안 함

디바이스 사용 사용 안 함 IsEnabled?
ClaimedBarcodeScanner EnableAsync DisableAsync IsEnabled
ClaimedCashDrawer EnableAsync DisableAsync IsEnabled
ClaimedLineDisplay 해당 없음¹ 해당 없음¹ 해당 없음¹
ClaimedMagneticStripeReader EnableAsync DisableAsync IsEnabled
ClaimedPosPrinter EnableAsync DisableAsync IsEnabled

¹ 라인 디스플레이에서는 디바이스를 I/O 작업에 사용하도록 명시적으로 설정할 필요가 없습니다. I/O를 수행하는 PointOfService LineDisplay API가 자동으로 사용하도록 설정합니다.

코드 샘플: 클레임 및 사용

이 샘플은 성공적으로 바코드 스캐너 개체를 만든 후 바코드 스캐너 디바이스를 주장하는 방법을 보여 줍니다.


    BarcodeScanner barcodeScanner = await BarcodeScanner.FromIdAsync(DeviceId);

    if(barcodeScanner != null)
    {
        // after successful creation, claim the scanner for exclusive use 
        claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

        if(claimedBarcodeScanner != null)
        {
            // after successful claim, enable scanner for data events to fire
            await claimedBarcodeScanner.EnableAsync();
        }
        else
        {
            Debug.WriteLine("Failure to claim barcodeScanner");
        }
    }
    else
    {
        Debug.WriteLine("Failure to create barcodeScanner object");
    }
    

Warning

클레임은 다음과 같은 환경에서 실패할 수 있습니다.

  1. 다른 앱이 동일한 디바이스에 대한 클레임을 요청하였으며 앱이 ReleaseDeviceRequested 이벤트에 대한 응답으로 RetainDevice를 발급하지 않았습니다. (자세한 정보는 아래의 클레임 협상 섹션을 참조하세요.)
  2. 앱이 일시 중단되어 디바이스 개체가 종료되고 그 결과로 클레임이 더 이상 유효하지 않습니다. (자세한 내용은 디바이스 개체 수명 주기를 참조하세요.)

클레임 협상

Windows는 멀티태스킹 환경이기 때문에, 동일한 컴퓨터의 여러 애플리케이션이 협력하는 방식으로 주변 디바이스에 액세스해야 합니다. PointOfService API는 여러 애플리케이션이 컴퓨터에 연결된 주변 디바이스를 공유할 수 있도록 협상 모델을 제공합니다.

동일한 컴퓨터의 두 번째 애플리케이션이 이미 다른 애플리케이션에서 요청된 PointOfService 주변 디바이스에 대한 클레임을 요청하면 ReleaseDeviceRequested 이벤트 알림이 게시됩니다. 활성 클레임이 있는 애플리케이션이 디바이스를 사용하고 있는 경우 현재 클레임을 잃지 않기 위해 RetainDevice를 호출하여 이벤트 알림에 응답해야 합니다.

활성 클레임이 있는 애플리케이션이 즉시 RetainDevice로 응답하지 않는 경우 해당 애플리케이션이 일시 중단되었거나 디바이스가 필요하지 않은 것으로 간주되며 클레임이 취소되고 새 애플리케이션에 제공됩니다.

첫 번째 단계는 RetainDevice를 사용하여 ReleaseDeviceRequested 이벤트에 응답하는 이벤트 처리기를 만드는 것입니다.

    /// <summary>
    /// Event handler for the ReleaseDeviceRequested event which occurs when 
    /// the claimed barcode scanner receives a Claim request from another application
    /// </summary>
    void claimedBarcodeScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner myScanner)
    {
        // Retain exclusive access to the device
        myScanner.RetainDevice();
    }

다음으로, 클레임을 보냈던 장치와 연결된 이벤트 처리기를 등록합니다

    BarcodeScanner barcodeScanner = await BarcodeScanner.FromIdAsync(DeviceId);

    if(barcodeScanner != null)
    {
        // after successful creation, claim the scanner for exclusive use 
        claimedBarcodeScanner = await barcodeScanner.ClaimScannerAsync();

        if(claimedBarcodeScanner != null)
        {
            // register a release request handler to prevent loss of scanner during active use
            claimedBarcodeScanner.ReleaseDeviceRequested += claimedBarcodeScanner_ReleaseDeviceRequested;

            // after successful claim, enable scanner for data events to fire
            await claimedBarcodeScanner.EnableAsync();          
        }
        else
        {
            Debug.WriteLine("Failure to claim barcodeScanner");
        }
    }
    else
    {
        Debug.WriteLine("Failure to create barcodeScanner object");
    }

클레임 협상에 사용되는 API

클레임한 디바이스 해제 알림 디바이스 보유
ClaimedBarcodeScanner ReleaseDeviceRequested RetainDevice
ClaimedCashDrawer ReleaseDeviceRequested RetainDevice
ClaimedLineDisplay ReleaseDeviceRequested RetainDevice
ClaimedMagneticStripeReader ReleaseDeviceRequested RetainDevice
ClaimedPosPrinter ReleaseDeviceRequested RetainDevice