void OnSerialReaderListInstantiated(SCardReaderList_CcidOverSerial SerialReaders) { if (InvokeRequired) { IAsyncResult ar = this.BeginInvoke(new OnSerialReaderListInstantiatedInvoker(OnSerialReaderListInstantiated), SerialReaders); this.EndInvoke(ar); return; } if (SerialReaders == null) { MessageBox.Show(this, "Failed to connect to the serial reader. Please check your hardware and your configuration, and click the 'Reader' link to try to re-open the reader, or to select another reader.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } SCardReader_CcidOver SerialReader = SerialReaders.GetReader(0); if (SerialReader == null) { MessageBox.Show(this, "The serial reader has not been correctly activated. Please click the 'Reader' link to try to re-open the reader, or to select another reader.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } ReaderList = SerialReaders; Reader = SerialReader; DisplayReaderPresent(); SerialReader.StartMonitor(new SCardReader_CcidOver.StatusChangeCallback(ReaderStatusChanged)); }
void MainFormShown(object sender, EventArgs e) { if (AppConfig.ReadBoolean("reader_reconnect")) { if (AppConfig.ReadString("reader_mode") == "serial") { SCardReaderList_CcidOverSerial.BackgroundInstantiate( new SCardReaderList_CcidOverSerial.BackgroundInstantiateCallback(OnSerialReaderListInstantiated), AppConfig.ReadString("serial_port"), true, AppConfig.ReadBoolean("serial_use_lpcd")); } else { ReaderList = new SCardReaderList(); if (ReaderList != null) { string reader_name = AppConfig.ReadString("reader_name"); Logger.Trace("Looking for PC/SC reader '" + reader_name + "'"); if (ReaderList.Contains(reader_name)) { Logger.Trace("Found!"); Reader = new SCardReader(reader_name); DisplayReaderPresent(); Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged)); return; } else { Logger.Trace("Not found!"); MessageBox.Show(this, "Failed to reconnect to the previous PC/SC reader. Please click the 'Reader' link to select another reader.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } ReaderList = null; } else { MessageBox.Show(this, "The PC/SC subsystem doesn't seem to be running. Please check your system's configuration.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } }
void SelectReader() { if ((ReaderList != null) || (Reader != null)) { if (!UserWantsToClose()) { return; } CloseDevice(); } ReaderSelectAnyForm f = new ReaderSelectAnyForm(); bool rc = (f.ShowDialog(this) == DialogResult.OK); if (rc) { if (f.Mode == "pc/sc") { string ReaderName; f.GetPCSCParameters(out ReaderName); ReaderList = new SCardReaderList(); if (ReaderList != null) { Reader = ReaderList.GetReader(ReaderName); if (Reader != null) { DisplayReaderPresent(); Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged)); } else { MessageBox.Show(this, "Failed to connect to the PC/SC reader. Please click the 'Reader' link to select another reader.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show(this, "The PC/SC subsystem doesn't seem to be running. Please check your system's configuration.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (f.Mode == "serial") { string PortName; bool UseNotifications; bool UseLpcdPolling; f.GetSerialParameters(out PortName, out UseNotifications, out UseLpcdPolling); SCardReaderList_CcidOverSerial.BackgroundInstantiate( new SCardReaderList_CcidOverSerial.BackgroundInstantiateCallback(OnSerialReaderListInstantiated), PortName, UseNotifications, UseLpcdPolling); } else if (f.Mode == "network") { string Address; ushort Port; f.GetNetworkParameters(out Address, out Port); SCardReaderList_CcidOverNetwork.BackgroundInstantiate( new SCardReaderList_CcidOverNetwork.BackgroundInstantiateCallback(OnNetworkReaderListInstantiated), Address, Port); } } }