MagneticStripeReader MagneticStripeReader MagneticStripeReader MagneticStripeReader Class

Definition

Represents the magnetic stripe reader device.

public : sealed class MagneticStripeReader : IMagneticStripeReader, IClosablepublic sealed class MagneticStripeReader : IMagneticStripeReader, IDisposablePublic NotInheritable Class MagneticStripeReader Implements IMagneticStripeReader, IDisposable// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

This object is created when GetDefaultAsync or FromIdAsync method completes.

See the magnetic stripe reader sample for an example implementation.

Properties

Capabilities Capabilities Capabilities Capabilities

Gets the capabilities of the magnetic stripe reader.

public : MagneticStripeReaderCapabilities Capabilities { get; }public MagneticStripeReaderCapabilities Capabilities { get; }Public ReadOnly Property Capabilities As MagneticStripeReaderCapabilities// You can use this property in JavaScript.

DeviceAuthenticationProtocol DeviceAuthenticationProtocol DeviceAuthenticationProtocol DeviceAuthenticationProtocol

Device authentication protocol supported by the magnetic stripe reader.

public : MagneticStripeReaderAuthenticationProtocol DeviceAuthenticationProtocol { get; }public MagneticStripeReaderAuthenticationProtocol DeviceAuthenticationProtocol { get; }Public ReadOnly Property DeviceAuthenticationProtocol As MagneticStripeReaderAuthenticationProtocol// You can use this property in JavaScript.

DeviceId DeviceId DeviceId DeviceId

Gets the DeviceInformation.Id of the magnetic stripe reader.

public : PlatForm::String DeviceId { get; }public string DeviceId { get; }Public ReadOnly Property DeviceId As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The DeviceInformation.Id of the magnetic stripe reader.

SupportedCardTypes SupportedCardTypes SupportedCardTypes SupportedCardTypes

Gets the card types supported by the magnetic stripe reader.

public : unsigned int[] SupportedCardTypes { get; }public uint[] SupportedCardTypes { get; }Public ReadOnly Property SupportedCardTypes As uint[]// You can use this property in JavaScript.
Value
unsigned int[] uint[] uint[] uint[]

The card type identifier.

Methods

CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel) CheckHealthAsync(UnifiedPosHealthCheckLevel)

Tests the health of the magnetic stripe reader.

public : IAsyncOperation<PlatForm::String> CheckHealthAsync(UnifiedPosHealthCheckLevel level)public IAsyncOperation<string> CheckHealthAsync(UnifiedPosHealthCheckLevel level)Public Function CheckHealthAsync(level As UnifiedPosHealthCheckLevel) As IAsyncOperation( Of string )// You can use this method in JavaScript.
Parameters
Returns

A text description of the text result. Returns an error if the specified check level is not supported by the device.

ClaimReaderAsync() ClaimReaderAsync() ClaimReaderAsync() ClaimReaderAsync()

Attempts to get an exclusive access to the magnetic stripe reader.

public : IAsyncOperation<ClaimedMagneticStripeReader> ClaimReaderAsync()public IAsyncOperation<ClaimedMagneticStripeReader> ClaimReaderAsync()Public Function ClaimReaderAsync() As IAsyncOperation( Of ClaimedMagneticStripeReader )// You can use this method in JavaScript.
Returns

Examples

// Claims the magnetic stripe reader for exclusive use
task<void> Scenario1::ClaimReader()
{
    
    return create_task(_reader->ClaimReaderAsync()).then([this] (ClaimedMagneticStripeReader^ claimedReader)
    {
        _claimedReader = claimedReader;
        if (_claimedReader != nullptr)
        {
            // UpdateReaderStatusTextBlock("Magnetic stripe reader claimed successfully.");		
        }
        else
        {
            // UpdateReaderStatusTextBlock("Failed to claim the magnetic stripe reader.");
        }
    });
}
// Claims the magnetic stripe reader for exclusive use.

private async Task<bool> ClaimReader()
{
    if (_claimedReader == null)
    {
        _claimedReader = await _reader.ClaimReaderAsync();

        if (_claimedReader != null)
        {
            // UpdateReaderStatusTextBlock("Magnetic stripe reader claimed successfully.");
        }
        else
        {
            // UpdateReaderStatusTextBlock("Failed to claim a magnetic stripe reader.");
            return false;
        }
    }
    return true;
}
//Creates the magnetic stripe reader, claims it for exclusive use, adds a data event listener, 
//and enables it to receive data.
var _reader = null;
var _claimedReader = null;

function startRead() {
    Windows.Devices.PointOfService.MagneticStripeReader.getDefaultAsync().then(function (reader) {
        if (reader !== null) {
            _reader = reader;
            
            reader.claimReaderAsync().done(function (claimedReader) {
                _claimedReader = claimedReader;
                claimedReader.isDecodeDataEnabled = true;
               
                claimedReader.addEventListener("bankcarddatareceived", onBankCardDataReceived);
                claimedReader.enableAsync().done(function () {
                   
                    document.getElementById("startReadButton").disabled = true;
                    document.getElementById("endReadButton").disabled = false;
                }, function error(e) {
                    // "Failed to enable the magnetic stripe reader."
                });
            }, function error(e) {
                //"Could not claim the magnetic stripe reader."
            });
        }
        else {
            //"Could not claim the magnetic stripe reader."
        }
           
    }, function error(e) {
        //"Magnetic stripe reader not found. Connect a magnetic stripe reader."
    });
}
See Also

Close() Close() Close() Close()

Close the magnetic stripe reader session. For C++ and JavaScript, use Close(). For C# and Visual Basic, use Dispose().

public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()

FromIdAsync(String) FromIdAsync(String) FromIdAsync(String) FromIdAsync(String)

Creates a MagneticStripeReader object from DeviceInformation.Id.

public : static IAsyncOperation<MagneticStripeReader> FromIdAsync(PlatForm::String deviceId)public static IAsyncOperation<MagneticStripeReader> FromIdAsync(String deviceId)Public Static Function FromIdAsync(deviceId As String) As IAsyncOperation( Of MagneticStripeReader )// You can use this method in JavaScript.
Parameters
deviceId
PlatForm::String String String String

The DeviceInformation.Id that identifies a specific magnetic stripe reader, which can be retrieved from the DeviceId property.

Returns

The magnetic stripe reader specified by the unique device identifier. Returns a null object in the following cases:

  • The specific device is not found.
  • Access denied to the existing device. The user can deny access to a device, which is not treated as an exception.

GetDefaultAsync() GetDefaultAsync() GetDefaultAsync() GetDefaultAsync()

Returns the first magnetic stripe reader found.

public : static IAsyncOperation<MagneticStripeReader> GetDefaultAsync()public static IAsyncOperation<MagneticStripeReader> GetDefaultAsync()Public Static Function GetDefaultAsync() As IAsyncOperation( Of MagneticStripeReader )// You can use this method in JavaScript.
Returns

The first magnetic stripe reader found. Returns a null object in the following cases:

  • A device is not found.
  • Access denied to the existing device. The user can deny access to a device, which is not treated as an exception.

Examples

// Creates the magnetic stripe reader.
task<void> Scenario1::CreateDefaultReaderObject()
{
    return create_task(MagneticStripeReader::GetDefaultAsync()).then([this] (MagneticStripeReader^ reader)
    {
        _reader = reader;
        if (_reader != nullptr)
        {			
            // UpdateReaderStatusTextBlock("Magnetic stripe reader created.");
            // UpdateReaderStatusTextBlock("Device Id is:" + _reader->DeviceId);
        }
        else
        {
            // UpdateReaderStatusTextBlock("Magnetic stripe reader not found. Connect a magnetic stripe reader.");
        }
    });

}
//Creates a magnetic stripe reader.

private async Task<bool> CreateDefaultMagneticStripeReaderObject()
{
    if (_reader == null)
    {
        
        _reader = await MagneticStripeReader.GetDefaultAsync();

        if (_reader != null)
        {
            // UpdateReaderStatusTextBlock("Magnetic stripe reader created.");
            // UpdateReaderStatusTextBlock("Device Id is:" + _reader.DeviceId);
        }
        else
        {
            // UpdateReaderStatusTextBlock("Magnetic stripe reader not found. Connect a magnetic stripe reader.");
            return false;
        }
    }
    return true;
}
//Creates the magnetic stripe reader, claims it for exclusive use, adds a data event listener, 
//and enables it to receive data.
var _reader = null;
var _claimedReader = null;

function startRead() {
    Windows.Devices.PointOfService.MagneticStripeReader.getDefaultAsync().then(function (reader) {
        if (reader !== null) {
            _reader = reader;
            
            reader.claimReaderAsync().done(function (claimedReader) {
                _claimedReader = claimedReader;
                claimedReader.isDecodeDataEnabled = true;
               
                claimedReader.addEventListener("bankcarddatareceived", onBankCardDataReceived);
                claimedReader.enableAsync().done(function () {
                   
                    document.getElementById("startReadButton").disabled = true;
                    document.getElementById("endReadButton").disabled = false;
                }, function error(e) {
                    // "Failed to enable the magnetic stripe reader."
                });
            }, function error(e) {
                //"Could not claim the magnetic stripe reader."
            });
        }
        else {
            //"Could not claim the magnetic stripe reader."
        }
           
    }, function error(e) {
        //"Magnetic stripe reader not found. Connect a magnetic stripe reader."
    });
}
See Also

GetDeviceSelector() GetDeviceSelector() GetDeviceSelector() GetDeviceSelector()

Returns an Advanced Query Syntax (AQS) string that is used to enumerate available magnetic stripe readers.

public : static PlatForm::String GetDeviceSelector()public static string GetDeviceSelector()Public Static Function GetDeviceSelector() As string// You can use this method in JavaScript.
Returns
PlatForm::String string string string

An Advanced Query Syntax (AQS) string that is used to enumerate available magnetic stripe readers.

GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes) GetDeviceSelector(PosConnectionTypes)

Gets an Advanced Query Syntax (AQS) string that you can use to list the magnetic stripe readers available over the specified connection types

public : static PlatForm::String GetDeviceSelector(PosConnectionTypes connectionTypes)public static string GetDeviceSelector(PosConnectionTypes connectionTypes)Public Static Function GetDeviceSelector(connectionTypes As PosConnectionTypes) As string// You can use this method in JavaScript.
Parameters
connectionTypes
PosConnectionTypes PosConnectionTypes PosConnectionTypes PosConnectionTypes

A list of the connection types to check for available magnetic stripe readers.

Returns
PlatForm::String string string string

An Advanced Query Syntax (AQS) string that is used to enumerate the magnetic stripe readers available over the specified connection types

Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

GetErrorReportingType() GetErrorReportingType() GetErrorReportingType() GetErrorReportingType()

Gets the error reporting type the application wants to receive.

public : MagneticStripeReaderErrorReportingType GetErrorReportingType()public MagneticStripeReaderErrorReportingType GetErrorReportingType()Public Function GetErrorReportingType() As MagneticStripeReaderErrorReportingType// You can use this method in JavaScript.
Returns

RetrieveStatisticsAsync(IIterable) RetrieveStatisticsAsync(IIterable) RetrieveStatisticsAsync(IIterable) RetrieveStatisticsAsync(IIterable)

Retrieves the requested statistics from the magnetic stripe reader.

public : IAsyncOperation<IBuffer> RetrieveStatisticsAsync(IIterable<PlatForm::String> statisticsCategories)public IAsyncOperation<IBuffer> RetrieveStatisticsAsync(IEnumerable<String> statisticsCategories)Public Function RetrieveStatisticsAsync(statisticsCategories As IEnumerable<String>) As IAsyncOperation( Of IBuffer )// You can use this method in JavaScript.
Parameters
statisticsCategories
IIterable<PlatForm::String> IEnumerable<String> IEnumerable<String> IEnumerable<String>

The list of statistics to retrieve.

  • An empty string ("") retrieves all statistics.
  • "U_" retrieves all UnifiedPOS defined statistics.
  • "M_" retrieves all manufacturer defined statistics.
  • "name1" and/or "name2" retrieves specific named statistics as defined by the UnifiedPOS or manufacturer.
  • Any combination of individual and groups names ("name3", "U_", "M_").
Returns
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The result does not contain any duplicate statistics even if the input contains duplicates.

Events

StatusUpdated StatusUpdated StatusUpdated StatusUpdated

Occurs when the device detects an operation status change.

public : event TypedEventHandler StatusUpdated<MagneticStripeReader,  MagneticStripeReaderStatusUpdatedEventArgs>public event TypedEventHandler StatusUpdated<MagneticStripeReader,  MagneticStripeReaderStatusUpdatedEventArgs>Public Event StatusUpdated<MagneticStripeReader,  MagneticStripeReaderStatusUpdatedEventArgs>// You can use this event in JavaScript.