title: How to to read input stream from Magnetic stripe reader with keyboard support in Windows 10 universal app
body: <p>We have tried the approach suggested at:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/hardware/dn312121(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/hardware/dn312121(v=vs.85).aspx</a> 
  <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/dn303343(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/hardware/dn303343(v=vs.85).aspx</a></p>
  
  <p>We are able to find out list of all the magneticDevices using below code snippet</p>
  
  <pre class="lang-cs prettyprint-override"><code>var magneticDevices = await DeviceInformation.FindAllAsync(aqsFilter);
  </code></pre>
  
  <p>but we are not able to get HidDevice object from the below code. It is giving null.</p>
  
  <pre class="lang-cs prettyprint-override"><code>HidDevice device = await HidDevice.FromIdAsync(magneticDevices[0].Id
  </code></pre>
  
  <p>We have also set device capabilities in the app manifest file like below.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;DeviceCapability Name="humaninterfacedevice"&gt;
      &lt;Device Id="vidpid:0ACD 0520"&gt;
        &lt;Function Type="usage:0001 0006"/&gt;
      &lt;/Device&gt;
  &lt;/DeviceCapability&gt;
  
  &lt;DeviceCapability Name="usb"&gt;
      &lt;Device Id="vidpid:0ACD 0520"&gt;
        &lt;Function Type="winUsbId:4d1e55b2-f16f-11cf-88cb-001111000030"/&gt;
      &lt;/Device&gt;
  &lt;/DeviceCapability&gt;
  </code></pre>
  
  <p>Code for the complete Function</p>
  
  <pre class="lang-cs prettyprint-override"><code> private async Task&lt;bool&gt; HasCardReader()
          {
              bool hasCardReader = false;
              ushort usagePage = 0x0001;
              ushort usageId = 0x0006;
              ushort vendorId = 0x0ACD;
              ushort productId = 0x0520;
              var aqsFilter = HidDevice.GetDeviceSelector(usagePage, usageId, vendorId, productId);
              var magneticDevices = await DeviceInformation.FindAllAsync(aqsFilter);
              try
              {
                  if (magneticDevices != null &amp;&amp; magneticDevices.Count &gt; 0)
                  {
                      HidDevice device = await HidDevice.FromIdAsync(magneticDevices[0].Id, Windows.Storage.FileAccessMode.Read);
                      inputReportEventHandler = new TypedEventHandler&lt;HidDevice, HidInputReportReceivedEventArgs&gt;(this.OnInputReportEvent);
                      device.InputReportReceived += inputReportEventHandler;
                      var watcher = DeviceInformation.CreateWatcher(aqsFilter);
                      watcher.Added += WatcherAdded;
                      watcher.Removed += WatcherRemoved;
                      watcher.Start();
                      hasCardReader = true;
              }
                  else
                  {
  
                  }
              }
              catch (Exception ex)
              {
                  Logging.LoggingSessionScenario.LogMessageAsync(ex.Message, LoggingLevel.Error);
              }
              return hasCardReader;
              }
  </code></pre>