1

If I insert a Card in my SmartCard reader on my device. I want to trigger an event in my WPF project. Any idea's to achieve that?

1 Answers1

2

This question was a while ago but I can confirm it is possible. You can reference UWP assemblies. Calling Windows 10 APIs From a Desktop Application details how to add the references.

Right click on References. Select “Add Reference…” from the context menu. On the left of the Reference Manager, choose Browse and find the following file: C:Program Files (x86)Windows Kits10UnionMetadatawinmd. Add it to your project as a reference. Note: You will need to change the filter to “All Files”.

Right click on References. Select “Add Reference…” from the context menu. On the left of the Reference Manager, go to Browse and find the directory “C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETCorev4.5”. Add System.Runtime.WindowsRuntime.dll to your project.

From there I follow this example Getting all Cards simply cutting and pasting the major part. Once you have reader you can then add the Card Added Event

string selector = SmartCardReader.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);

foreach (DeviceInformation device in devices)
{
    SmartCardReader reader = await SmartCardReader.FromIdAsync(device.Id);

    // For each reader, we want to find all the cards associated
    // with it.  Then we will create a SmartCardListItem for
    // each (reader, card) pair.
    IReadOnlyList<SmartCard> cards = await reader.FindAllCardsAsync();

    foreach (SmartCard card in cards)
    {
        SmartCardProvisioning provisioning = await SmartCardProvisioning.FromSmartCardAsync(card);

        SmartCardListItem item = new SmartCardListItem()
        {
            ReaderName = card.Reader.Name,
            CardName = await provisioning.GetNameAsync()
        };

        cardItems.Add(item);
    }
}
MAXE
  • 4,978
  • 2
  • 45
  • 61
darbid
  • 2,545
  • 23
  • 55