ClaimedMagneticStripeReader.BankCardDataReceived ClaimedMagneticStripeReader.BankCardDataReceived ClaimedMagneticStripeReader.BankCardDataReceived ClaimedMagneticStripeReader.BankCardDataReceived ClaimedMagneticStripeReader.BankCardDataReceived Event

Definition

Occurs when a bank card is swiped.

public : event TypedEventHandler<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs> BankCardDataReceived
// Register
event_token BankCardDataReceived(TypedEventHandler<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs> const& handler) const;

// Revoke with event_token
void BankCardDataReceived(event_token const& cookie) const;

// Revoke with event_revoker
BankCardDataReceived_revoker BankCardDataReceived(auto_revoke_t, TypedEventHandler<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs> const& handler) const;
public event TypedEventHandler<ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs> BankCardDataReceived
Public Event BankCardDataReceived As TypedEventHandler (Of ClaimedMagneticStripeReader, MagneticStripeReaderBankCardDataReceivedEventArgs)
function onBankCardDataReceived(eventArgs){/* Your code */}


claimedMagneticStripeReader.addEventListener("bankcarddatareceived", onBankCardDataReceived);
claimedMagneticStripeReader.removeEventListener("bankcarddatareceived", onBankCardDataReceived);

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 handler to get the bank card data each time a bank card is swiped through the magnetic stripe reader.

See also