private static void CbReadersChanged(UInt32 nreaders, IntPtr slotList) { int structSize = Marshal.SizeOf(typeof(eid_slotdesc)); Console.WriteLine(structSize); theData.readersList = new ConcurrentQueue <ReadersMenuViewModel>(); for (int i = 0; i < nreaders; i++) { IntPtr data = new IntPtr(slotList.ToInt64() + structSize * i); eid_slotdesc slotDesc = (eid_slotdesc)Marshal.PtrToStructure(data, typeof(eid_slotdesc)); theData.logText += "Reader slotnr " + slotDesc.slot.ToString() + "\n"; theData.logText += "Reader name " + slotDesc.description.ToString() + "\n"; if (!slotDesc.description.Equals("\\\\?PnP?\\Notification")) { theData.readersList.Enqueue(new ReadersMenuViewModel(slotDesc.description, slotDesc.slot)); } else if (nreaders == 1) { theData.readersList.Enqueue(new ReadersMenuViewModel(" ", 0)); } } }
private static void CbReadersChanged(UInt32 nreaders, IntPtr slotList) { try { int structSize = Marshal.SizeOf(typeof(eid_slotdesc)); ConcurrentQueue <ReadersMenuViewModel> tempReadersList = new ConcurrentQueue <ReadersMenuViewModel>(); Console.WriteLine(structSize); // theData.readersList = new ConcurrentQueue<ReadersMenuViewModel>(); if (nreaders == 0) { theData.WriteLog("No card readers detected\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); } for (int i = 0; i < nreaders; i++) { IntPtr data = new IntPtr(slotList.ToInt64() + structSize * i); eid_slotdesc slotDesc = (eid_slotdesc)Marshal.PtrToStructure(data, typeof(eid_slotdesc)); if (slotDesc.description == null) { theData.WriteLog("CbReadersChanged called without a reader description\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); break; } theData.WriteLog("Reader slotnr " + slotDesc.slot.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); theData.WriteLog("Reader name " + slotDesc.description.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_NORMAL); if (!slotDesc.description.Equals("\\\\?PnP?\\Notification")) { tempReadersList.Enqueue(new ReadersMenuViewModel(slotDesc.description, slotDesc.slot)); } else if (nreaders == 1) { tempReadersList.Enqueue(new ReadersMenuViewModel(" ", 0)); } } theData.readersList = tempReadersList; } catch (Exception e) { theData.WriteLog("CbReadersChanged encountered an error " + e.ToString() + "\n", eid_vwr_loglevel.EID_VWR_LOG_ERROR); } }