I currently use pcsc-sharp to read ids from NFC tags. I got this methode to lists all available readers. But this replys me all readers I ever used. There are also old readers listed that aren´t plugged in. Does anyone know how to fix that?
public void SelectDevice()
{
List<string> availableReaders = this.ListReaders();
this.RdrState = new Card.SCARD_READERSTATE();
readername = availableReaders[0].ToString();
this.RdrState.RdrName = readername;
}
public List<string> ListReaders()
{
int ReaderCount = 0;
List<string> AvailableReaderList = new List<string>();
retCode = Card.SCardListReaders(hContext, null, null, ref ReaderCount);
if (retCode != Card.SCARD_S_SUCCESS)
{
MessageBox.Show(Card.GetScardErrMsg(retCode));
}
byte[] ReadersList = new byte[ReaderCount];
retCode = Card.SCardListReaders(hContext, null, ReadersList, ref ReaderCount);
if (retCode != Card.SCARD_S_SUCCESS)
{
MessageBox.Show(Card.GetScardErrMsg(retCode));
}
string rName = "";
int indx = 0;
if (ReaderCount > 0)
{
while (ReadersList[indx] != 0)
{
while (ReadersList[indx] != 0)
{
rName = rName + (char)ReadersList[indx];
indx = indx + 1;
}
AvailableReaderList.Add(rName);
rName = "";
indx = indx + 1;
}
}
return AvailableReaderList;
}