Autoconnect MSR-100 Magnetic Stripe Card Reader Throught RS232 Port and returns MagneticCardInfo class with data on Swipe event.
This Reader:
https://en.wikipedia.org/wiki/ISO/IEC_7811
Install-Package MSR-100-Magnetic-Stripe-Parser -Version 1.0.1
or
dotnet add package MSR-100-Magnetic-Stripe-Parser --version 1.0.1
Instance a MSR100Controller
object, attach a custom method to OnCardSwiped
event.
Constructor has two parameters:
PortName
is a optional string parameter that will override the port name, default is COM1baudRate
is a optional integer parameter that will override the baud rate, default is 9600
MSR100Controller Class has one public event:
OnCardSwiped
is event that will fire every time a card is swiped on the device, return an object of typeMagneticCardInfo
static void Main(string[] args)
{
using (var controller = new MSR100Controller())
{
controller.OnCardSwiped += Controller_OnCardSwiped;
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
private static void Controller_OnCardSwiped(MagneticCardInfo cardinfo)
{
Console.WriteLine("Card Swiped!");
Console.WriteLine($"PAN: {cardinfo.Track1.PAN}");
Console.WriteLine($"NN: {cardinfo.Track1.Name}");
Console.WriteLine($"ED: {cardinfo.Track1.ExpirationDate}");
Console.WriteLine($"SC: {cardinfo.Track1.ServiceCode}");
Console.WriteLine($"DD: {cardinfo.Track1.DiscretionaryData}");
}