ClaimedMagneticStripeReader
ClaimedMagneticStripeReader
ClaimedMagneticStripeReader
ClaimedMagneticStripeReader
Class
Definition
Represents the claimed magnetic stripe reader.
public : sealed class ClaimedMagneticStripeReader : IClaimedMagneticStripeReader, IClosablepublic sealed class ClaimedMagneticStripeReader : IClaimedMagneticStripeReader, IDisposablePublic NotInheritable Class ClaimedMagneticStripeReader Implements IClaimedMagneticStripeReader, IDisposable// You can use this class in JavaScript.
- Attributes
| 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 ClaimReaderAsync method completes.
Properties
DataEncryptionAlgorithm DataEncryptionAlgorithm DataEncryptionAlgorithm DataEncryptionAlgorithm
Gets or sets the MagneticStripeReaderEncryptionAlgorithms that will be used to encrypt the track data.
public : unsigned int DataEncryptionAlgorithm { get; set; }public uint DataEncryptionAlgorithm { get; set; }Public ReadWrite Property DataEncryptionAlgorithm As uint// You can use this property in JavaScript.
- Value
- unsigned int uint uint uint
The encryption algorithm the will be used to encrypt the track data.
Remarks
This property can only be updated when the device is opened and claimed; it cannot be updated when the device is enabled.
DeviceId DeviceId DeviceId DeviceId
Gets the DeviceInformation.Id of the claimed 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 claimed magnetic stripe reader.
IsDecodeDataEnabled IsDecodeDataEnabled IsDecodeDataEnabled IsDecodeDataEnabled
Indicates whether to provide raw or decoded data from the most recently swiped card.
public : PlatForm::Boolean IsDecodeDataEnabled { get; set; }public bool IsDecodeDataEnabled { get; set; }Public ReadWrite Property IsDecodeDataEnabled As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
Set to true if decoded data is provided to the application; otherwise, false.
Remarks
Use this property to decide whether to pass the data from the card swipe in the original raw form or to decode it first.
If set to true, each byte of track data is mapped from its original encoded bit sequence, as it exists in the magnetic card, to its corresponding decoded ASCII bit sequence. This conversion is not relevant to 7-bit format, which is not encoded.
For each card type, the decoding takes place as follows:
| Card type | Track data property | Raw data format | Raw bytes | Decoded Values |
|---|---|---|---|---|
| ISO | Track 1 data | 6-bit | 0x00-0x3F | 0x20 through 0x5F |
| ISO | Track 2 data | 4-bit | 0x00-0x3F | 0x30 through 0x3F |
| ISO | Track 3 data | 4-bit | 0x00-0x3F | 0x30 through 0x3F |
| JIS-I | Track 1 data | 6-bit | 0x00-0x3F | 0x20 through 0x5F |
| JIS-I | Track 1 data | 7-bit | 0x00-0x7F | Data unaltered |
| JIS-I | Track 2 data | 4-bit | 0x00-0x0F | 0x20 through 0x3F |
| JIS-I | Track 3 data | 4-bit | 0x00-0x0F | 0x20 through 0x3F |
| JIS-I | Track 3 data | 7-bit | 0x00-0x7F | Data unaltered |
| JIS-II | Track 4 data | 7-bit | 0x00-0x7F | Data unaltered |
| AAMVA | Track 1 data | 6-bit | 0x00-0x3F | 0x20 through 0x5F |
| AAMVA | Track 2 data | 4-bit | 0x00-0x0F | 0x30 through 0x3F |
| AAMVA | Track 3 data | 6-bit | 0x00-0x3F | 0x20 through 0x5F |
This property is initialized to false.
IsDeviceAuthenticated IsDeviceAuthenticated IsDeviceAuthenticated IsDeviceAuthenticated
Indicates whether the device is authenticated.
public : PlatForm::Boolean IsDeviceAuthenticated { get; }public bool IsDeviceAuthenticated { get; }Public ReadOnly Property IsDeviceAuthenticated As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
True is the device is authenticated; otherwise, false.
Remarks
This property is only valid in the devices that support authentication.
When the device authentication state changes, the StatusUpdated event occurs to indicate the change.
IsDisabledOnDataReceived IsDisabledOnDataReceived IsDisabledOnDataReceived IsDisabledOnDataReceived
Gets or sets a Boolean value that indicates whether the magnetic stripe reader is disabled after receiving the data from the most recently swiped card.
public : PlatForm::Boolean IsDisabledOnDataReceived { get; set; }public bool IsDisabledOnDataReceived { get; set; }Public ReadWrite Property IsDisabledOnDataReceived As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
Set to true if the application wants to receive and process only one input or only one input at a time.
Remarks
IsDisabledOnDataReceived provides the application the option to disable the magnetic stripe reader after receiving the data. When set to true, the device is disabled as soon as it receives the data from the most recently swiped card. The application must call EnableAsync to get the device ready for the next data event.
This property is initialized to false.
IsEnabled IsEnabled IsEnabled IsEnabled
Indicates whether the magnetic stripe reader is ready to receive data events.
public : PlatForm::Boolean IsEnabled { get; }public bool IsEnabled { get; }Public ReadOnly Property IsEnabled As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
True if the device is operational; otherwise, false.
IsTransmitSentinelsEnabled IsTransmitSentinelsEnabled IsTransmitSentinelsEnabled IsTransmitSentinelsEnabled
Indicates whether the track data contains start and end sentinel values.
public : PlatForm::Boolean IsTransmitSentinelsEnabled { get; set; }public bool IsTransmitSentinelsEnabled { get; set; }Public ReadWrite Property IsTransmitSentinelsEnabled As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
True if the track data contains start and end sentinel values. False if the track data properties only contain track data between sentinels.
Remarks
This property is initialized to false.
TracksToRead TracksToRead TracksToRead TracksToRead
Gets or sets the track data that the application wants to receive following a card swipe.
public : MagneticStripeReaderTrackIds TracksToRead { get; set; }public MagneticStripeReaderTrackIds TracksToRead { get; set; }Public ReadWrite Property TracksToRead As MagneticStripeReaderTrackIds// You can use this property in JavaScript.
- Value
- MagneticStripeReaderTrackIds MagneticStripeReaderTrackIds MagneticStripeReaderTrackIds MagneticStripeReaderTrackIds
The card track.
Remarks
TracksToRead determines which tracks the application wants to receive following a card swipe. This does not indicate the capability of the device hardware; instead, it is an application configurable property representing which tracks to read. There are cases when the desired data cannot be obtained, such as cards not having data for a particular track.
Decreasing the required number of tracks may provide a greater success rate and somewhat greater responsiveness by removing the processing for inaccessible data.
This property is initialized for all tracks (Track1 | Track 2 | Track3 | Track4).
Methods
AuthenticateDeviceAsync(Byte[]) AuthenticateDeviceAsync(Byte[]) AuthenticateDeviceAsync(Byte[]) AuthenticateDeviceAsync(Byte[])
Puts the device into an authenticated state.
public : IAsyncAction AuthenticateDeviceAsync(Byte[] responseToken)public IAsyncAction AuthenticateDeviceAsync(Byte[] responseToken)Public Function AuthenticateDeviceAsync(responseToken As Byte[]) As IAsyncAction// You can use this method in JavaScript.
- responseToken
- Byte[] Byte[] Byte[] Byte[]
A buffer containing the response token generated from the challenge token retrieved from a previous call to the RetrieveDeviceAuthenticationDataAsync method.
Remarks
The method is only valid for devices that support authentication.
To authenticate a device, the application calls the RetrieveDeviceAuthenticationDataAsync method to retrieve a challenge token. The application typically passes this token to another entity that has special knowledge of a shared secret and is able to create a proper response token. This response token is then passed into the AuthenticateDeviceAsync method that uses it to validate the authentication request.
Close() Close() Close() Close()
Releases the exclusive claim to the magnetic strip reader.
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.
DeAuthenticateDeviceAsync(Byte[]) DeAuthenticateDeviceAsync(Byte[]) DeAuthenticateDeviceAsync(Byte[]) DeAuthenticateDeviceAsync(Byte[])
Puts the device into an unauthenticated state.
public : IAsyncAction DeAuthenticateDeviceAsync(Byte[] responseToken)public IAsyncAction DeAuthenticateDeviceAsync(Byte[] responseToken)Public Function DeAuthenticateDeviceAsync(responseToken As Byte[]) As IAsyncAction// You can use this method in JavaScript.
- responseToken
- Byte[] Byte[] Byte[] Byte[]
A buffer containing the response token generated from the challenge token retrieved from a previous call to the RetrieveDeviceAuthenticationDataAsync method.
Remarks
When successful, the IsDeviceAuthenticated property changes to false.
DisableAsync() DisableAsync() DisableAsync() DisableAsync()
Puts the ClaimedMagneticStripeReader into a state where it cannot receive data events.
public : IAsyncAction DisableAsync()public IAsyncAction DisableAsync()Public Function DisableAsync() As IAsyncAction// You can use this method in JavaScript.
No object or value is returned when this method completes.
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()
EnableAsync() EnableAsync() EnableAsync() EnableAsync()
Gets the magnetic stripe reader into a ready state to receive data events.
public : IAsyncAction EnableAsync()public IAsyncAction EnableAsync()Public Function EnableAsync() As IAsyncAction// You can use this method in JavaScript.
No object or value is returned by this method when it completes.
Examples
// Enables the magnetic stripe reader to receive data.
task<void> Scenario1::EnableReader()
{
return create_task(_claimedReader->EnableAsync()).then([this](void)
{
// UpdateReaderStatusTextBlock("Magnetic stripe reader enabled successfully.");
});
}
// Enables the magnetic stripe reader to receive data
private async Task<bool> EnableReader()
{
await _claimedReader.EnableAsync();
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
ResetStatisticsAsync(IIterable)
ResetStatisticsAsync(IIterable)
ResetStatisticsAsync(IIterable)
ResetStatisticsAsync(IIterable)
Resets the specified statistics to zero for all statistics that can be reset.
public : IAsyncAction ResetStatisticsAsync(IIterable<PlatForm::String> statisticsCategories)public IAsyncAction ResetStatisticsAsync(IEnumerable<String> statisticsCategories)Public Function ResetStatisticsAsync(statisticsCategories As IEnumerable<String>) As IAsyncAction// You can use this method in JavaScript.
- statisticsCategories
- IIterable<PlatForm::String> IEnumerable<String> IEnumerable<String> IEnumerable<String>
The list of names of the statistics to reset.
- 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.
No object or value is returned by this method when it completes.
RetainDevice() RetainDevice() RetainDevice() RetainDevice()
Retains exclusive claim to the magnetic stripe reader.
public : void RetainDevice()public void RetainDevice()Public Function RetainDevice() As void// You can use this method in JavaScript.
Remarks
When the application receives a request to release its exclusive claim to the magnetic stripe reader, it must call RetainDevice, otherwise it will lose its claim to the device.
- See Also
RetrieveDeviceAuthenticationDataAsync() RetrieveDeviceAuthenticationDataAsync() RetrieveDeviceAuthenticationDataAsync() RetrieveDeviceAuthenticationDataAsync()
Retrieves a challenge token from the device.
public : IAsyncOperation<IBuffer> RetrieveDeviceAuthenticationDataAsync()public IAsyncOperation<IBuffer> RetrieveDeviceAuthenticationDataAsync()Public Function RetrieveDeviceAuthenticationDataAsync() As IAsyncOperation( Of IBuffer )// You can use this method in JavaScript.
Buffer used to store the resulting challenge token from the device.
Remarks
This method is only valid for devices that support authentication.
SetErrorReportingType(MagneticStripeReaderErrorReportingType) SetErrorReportingType(MagneticStripeReaderErrorReportingType) SetErrorReportingType(MagneticStripeReaderErrorReportingType) SetErrorReportingType(MagneticStripeReaderErrorReportingType)
Sets the type of error to report by the ErrorOccurred event.
public : void SetErrorReportingType(MagneticStripeReaderErrorReportingType value)public void SetErrorReportingType(MagneticStripeReaderErrorReportingType value)Public Function SetErrorReportingType(value As MagneticStripeReaderErrorReportingType) As void// You can use this method in JavaScript.
- value
- MagneticStripeReaderErrorReportingType MagneticStripeReaderErrorReportingType MagneticStripeReaderErrorReportingType MagneticStripeReaderErrorReportingType
Error reporting type.
- See Also
UpdateKeyAsync(String, String) UpdateKeyAsync(String, String) UpdateKeyAsync(String, String) UpdateKeyAsync(String, String)
Provides a new encryption key to the device.
public : IAsyncAction UpdateKeyAsync(PlatForm::String key, PlatForm::String keyName)public IAsyncAction UpdateKeyAsync(String key, String keyName)Public Function UpdateKeyAsync(key As String, keyName As String) As IAsyncAction// You can use this method in JavaScript.
- key
- PlatForm::String String String String
The HEX-ASCII or base64-encoded value for the new key.
- keyName
- PlatForm::String String String String
The name used to identify the key.
Remarks
This method is only used for those encryption algorithms in which the new key values are sent to the terminal as a field in standard messages from the host.
UpdateStatisticsAsync(IIterable<>>)
UpdateStatisticsAsync(IIterable<>>)
UpdateStatisticsAsync(IIterable<>>)
UpdateStatisticsAsync(IIterable<>>)
Updates the specified statistics.
public : IAsyncAction UpdateStatisticsAsync(IIterable<IKeyValuePair<PlatForm::String, PlatForm::String>> statistics)public IAsyncAction UpdateStatisticsAsync(IEnumerable<KeyValuePair<String, String>> statistics)Public Function UpdateStatisticsAsync(statistics As IEnumerable<KeyValuePair<String, String>>) As IAsyncAction// You can use this method in JavaScript.
- statistics
- IIterable<IKeyValuePair<PlatForm::String, PlatForm::String>> IEnumerable<KeyValuePair<String, String>> IEnumerable<KeyValuePair<String, String>> IEnumerable<KeyValuePair<String, String>>
The list of key-value pairs of statistics to update.
- An empty string ("", "value1") sets all statistics that can be set to value1.
- "U_", "value2" sets all UnifiedPOS defined statistics that can be set to value2.
- "M_", "value3" sets all manufacturer defined statistics that can be set to value3.
- "name1", "value4" sets specific named statistics as defined by the UnifiedPOS or manufacturer to value4.
No object or value is returned by this method when it completes.
Events
AamvaCardDataReceived AamvaCardDataReceived AamvaCardDataReceived AamvaCardDataReceived
Occurs when a motor vehicle card is swiped.
public : event TypedEventHandler AamvaCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderAamvaCardDataReceivedEventArgs>public event TypedEventHandler AamvaCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderAamvaCardDataReceivedEventArgs>Public Event AamvaCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderAamvaCardDataReceivedEventArgs>// You can use this event in JavaScript.
Remarks
An application can register for this event handler to receive data from driver licenses or other cards formatted according to American Association Motor Vehicles Administrators (AAMVA) card specification.
- See Also
BankCardDataReceived BankCardDataReceived BankCardDataReceived BankCardDataReceived
Occurs when a bank card is swiped.
public : event TypedEventHandler BankCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs>public event TypedEventHandler BankCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs>Public Event BankCardDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs>// You can use this event in JavaScript.
Examples
The following example shows how to setup the magnetic stripe reader to receive data after a scanning event.
void Scenario1::ScenarioStartReadButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
create_task(CreateDefaultReaderObject()).then([this](void)
{
if (_reader != nullptr)
{
// Claim the magnetic stripe reader for exclusive use by your application.
create_task(ClaimReader()).then([this](void)
{
if (_claimedReader)
{
// Add a release device requested event handler. If this event is not handled,
// another app can claim the magnetic stripe reader.
_releaseDeviceRequestedToken = _claimedReader->ReleaseDeviceRequested::add(ref new EventHandler<ClaimedMagneticStripeReader^>(this, &Scenario1::OnReleaseDeviceRequested));
// Add a data receive event handler.
_bankCardDataReceivedToken = _claimedReader->BankCardDataReceived::add(ref new TypedEventHandler<ClaimedMagneticStripeReader^, MagneticStripeReaderBankCardDataReceivedEventArgs^>(this, &Scenario1::OnBankCardDataReceived));
UpdateReaderStatusTextBlock("Attached the BankCardDataReceived event handler..");
// Set the app to decode the raw data from the magnetic stripe reader.
_claimedReader->IsDecodeDataEnabled = true;
// Enable the magnetic stripe reader.
create_task(EnableReader()).then([this](void)
{
UpdateReaderStatusTextBlock("Ready to Swipe..");
// Reset the button state
ScenarioEndReadButton->IsEnabled = true;
ScenarioStartReadButton->IsEnabled = false;
});
}
});
}
});
}
private async void ScenarioStartReadButton_Click(object sender, RoutedEventArgs e)
{
if (await CreateDefaultMagneticStripeReaderObject())
{
if (_reader != null)
{
// Claim the reader for exclusive use by your application.
if (await ClaimReader())
{
if (_claimedReader != null)
{
/// Add a release device requested event handler. If this event is not handled,
// another app can claim the magnetic stripe reader.
_claimedReader.ReleaseDeviceRequested += OnReleaseDeviceRequested;
// Add a data receive event handler.
_claimedReader.BankCardDataReceived += OnBankCardDataReceived;
UpdateReaderStatusTextBlock("Attached the BankCardDataReceived Event handler..");
// Set the app to decode the raw data from the magnetic stripe reader.
_claimedReader.IsDecodeDataEnabled = true;
// Enable the magnetic stripe reader.
if (await EnableReader())
{
UpdateReaderStatusTextBlock("Ready to Swipe..");
// Reset the button state
ScenarioEndReadButton.IsEnabled = true;
ScenarioStartReadButton.IsEnabled = false;
}
}
}
}
}
}
void Scenario1::OnBankCardDataReceived(Windows::Devices::PointOfService::ClaimedMagneticStripeReader^sender, Windows::Devices::PointOfService::MagneticStripeReaderBankCardDataReceivedEventArgs^args)
{
// Read the data and display
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler(
[this,args]()
{
ScenarioOutputAccountNumber->Text = args->AccountNumber;
ScenarioOutputExpirationDate->Text = args->ExpirationDate;
ScenarioOutputFirstName->Text = args->FirstName;
ScenarioOutputMiddleInitial->Text = args->MiddleInitial;
ScenarioOutputServiceCode->Text = args->ServiceCode;
ScenarioOutputSuffix->Text = args->Suffix;
ScenarioOutputSurname->Text = args->Surname;
ScenarioOutputTitle->Text = args->Title;
}));
}
async void OnBankCardDataReceived(object sender, MagneticStripeReaderBankCardDataReceivedEventArgs args)
{
// Read the data and display
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
ScenarioOutputAccountNumber.Text = args.AccountNumber;
ScenarioOutputExpirationDate.Text = args.ExpirationDate;
ScenarioOutputFirstName.Text = args.FirstName;
ScenarioOutputMiddleInitial.Text = args.MiddleInitial;
ScenarioOutputServiceCode.Text = args.ServiceCode;
ScenarioOutputSuffix.Text = args.Suffix;
ScenarioOutputSurname.Text = args.Surname;
ScenarioOutputTitle.Text = args.Title;
});
}
//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."
});
}
function onBankCardDataReceived(args) {
WinJS.log && WinJS.log("Got data", "sample", "status");
document.getElementById("expirationDate").textContent = args.expirationDate;
document.getElementById("firstName").textContent = args.firstName;
document.getElementById("middleInitial").textContent = args.middleInitial;
document.getElementById("serviceCode").textContent = args.serviceCode;
document.getElementById("suffix").textContent = args.suffix;
document.getElementById("surname").textContent = args.surname;
document.getElementById("title").textContent = args.title;
}
Remarks
An application can register for this event event handler to get the bank card data each time a bank card is swiped through the magnetic stripe reader.
- See Also
ErrorOccurred ErrorOccurred ErrorOccurred ErrorOccurred
Occurs when the magnetic stripe reader detects an error when reading a card.
public : event TypedEventHandler ErrorOccurred<ClaimedMagneticStripeReader, MagneticStripeReaderErrorOccurredEventArgs>public event TypedEventHandler ErrorOccurred<ClaimedMagneticStripeReader, MagneticStripeReaderErrorOccurredEventArgs>Public Event ErrorOccurred<ClaimedMagneticStripeReader, MagneticStripeReaderErrorOccurredEventArgs>// You can use this event in JavaScript.
ReleaseDeviceRequested ReleaseDeviceRequested ReleaseDeviceRequested ReleaseDeviceRequested
Occurs when the device gets a request to release its exclusive claim.
public : event EventHandler ReleaseDeviceRequested<ClaimedMagneticStripeReader>public event EventHandler ReleaseDeviceRequested<ClaimedMagneticStripeReader>Public Event ReleaseDeviceRequested<ClaimedMagneticStripeReader>// You can use this event in JavaScript.
Examples
The following example shows how to setup the event handler.
void Scenario1::ScenarioStartReadButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
create_task(CreateDefaultReaderObject()).then([this](void)
{
if (_reader != nullptr)
{
// Claim the magnetic stripe reader for exclusive use by your application.
create_task(ClaimReader()).then([this](void)
{
if (_claimedReader)
{
// Add a release device requested event handler. If this event is not handled,
// another app can claim the magnetic stripe reader.
_releaseDeviceRequestedToken = _claimedReader->ReleaseDeviceRequested::add(ref new EventHandler<ClaimedMagneticStripeReader^>(this, &Scenario1::OnReleaseDeviceRequested));
// Add a data receive event handler.
_bankCardDataReceivedToken = _claimedReader->BankCardDataReceived::add(ref new TypedEventHandler<ClaimedMagneticStripeReader^, MagneticStripeReaderBankCardDataReceivedEventArgs^>(this, &Scenario1::OnBankCardDataReceived));
UpdateReaderStatusTextBlock("Attached the BankCardDataReceived event handler..");
// Set the app to decode the raw data from the magnetic stripe reader.
_claimedReader->IsDecodeDataEnabled = true;
// Enable the magnetic stripe reader.
create_task(EnableReader()).then([this](void)
{
UpdateReaderStatusTextBlock("Ready to Swipe..");
// Reset the button state
ScenarioEndReadButton->IsEnabled = true;
ScenarioStartReadButton->IsEnabled = false;
});
}
});
}
});
}
private async void ScenarioStartReadButton_Click(object sender, RoutedEventArgs e)
{
if (await CreateDefaultMagneticStripeReaderObject())
{
if (_reader != null)
{
// Claim the reader for exclusive use by your application.
if (await ClaimReader())
{
if (_claimedReader != null)
{
/// Add a release device requested event handler. If this event is not handled,
// another app can claim the magnetic stripe reader.
_claimedReader.ReleaseDeviceRequested += OnReleaseDeviceRequested;
// Add a data receive event handler.
_claimedReader.BankCardDataReceived += OnBankCardDataReceived;
UpdateReaderStatusTextBlock("Attached the BankCardDataReceived Event handler..");
// Set the app to decode the raw data from the magnetic stripe reader.
_claimedReader.IsDecodeDataEnabled = true;
// Enable the magnetic stripe reader.
if (await EnableReader())
{
UpdateReaderStatusTextBlock("Ready to Swipe..");
// Reset the button state
ScenarioEndReadButton.IsEnabled = true;
ScenarioStartReadButton.IsEnabled = false;
}
}
}
}
}
}
void Scenario1::OnReleaseDeviceRequested(Platform::Object ^sender, Windows::Devices::PointOfService::ClaimedMagneticStripeReader ^args)
{
// Always retain the device. If it is not retained, this exclusive claim will be lost.
args->RetainDevice();
}
void OnReleaseDeviceRequested(object sender, ClaimedMagneticStripeReader args)
{
// Always retain the device. If it is not retained, this exclusive claim will be lost.
args.RetainDevice();
}
- See Also
VendorSpecificDataReceived VendorSpecificDataReceived VendorSpecificDataReceived VendorSpecificDataReceived
Occurs when a vendor-specific card is swiped.
public : event TypedEventHandler VendorSpecificDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderVendorSpecificCardDataReceivedEventArgs>public event TypedEventHandler VendorSpecificDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderVendorSpecificCardDataReceivedEventArgs>Public Event VendorSpecificDataReceived<ClaimedMagneticStripeReader, MagneticStripeReaderVendorSpecificCardDataReceivedEventArgs>// You can use this event in JavaScript.