/// <summary> /// Enables the MSR completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RunWorkerCompletedEventArgs" /> instance containing the event data.</param> private void EnableMsrCompleted(object sender, RunWorkerCompletedEventArgs e) { var data = (CardSwipedEventArgs)e.Result; if (data.HasError || data.Response != CardReaderResponse.Success) { InvokeCardSwipedEvent(data); return; } try { var cardInfo = CardDataReader.GetCardInfo(data.TrackData); cardInfo.CardReaderResponse = data.Response; data.CardInfo = cardInfo; InvokeCardSwipedEvent(data); } catch (Exception ex) { var newEx = new CardReaderException("Failed processing card data.", ex); data.Exception = newEx; InvokeCardSwipedEvent(data); } }
/// <summary> /// Enables the MSR. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DoWorkEventArgs" /> instance containing the event data.</param> private void EnableMSR(object sender, DoWorkEventArgs e) { var response = CardReaderResponse.Unknown; try { var trackData = new byte[512]; var length = 0; var tracks = Convert.ToByte(e.Argument); // yes, i did this and i know it is terrible and will eventually cause a problem // but, i am at a loss on what else to do, this card reader keeps spitting back // a byte array that that has a length of 7 and there is no documentation that explains // why or how to prevent it, but doing this a couple of times fixes the problem // janky flush while (length <= 7) { // this pause allows the card reader to catch up // without it, two swipes are necessary Thread.Sleep(500); response = (CardReaderResponse)UniPay_EnableMSR(tracks, trackData, out length); // get out if this is the case if (response == CardReaderResponse.PortClosed || response == CardReaderResponse.Fail) { break; } } e.Result = new CardSwipedEventArgs(response) { TrackData = trackData, Length = length }; } catch (Exception ex) { var newEx = new CardReaderException($"Unable to read card reader. Response is {(byte)response}:{response}", ex); e.Result = new CardSwipedEventArgs(response, newEx); } }
public CardSwipedEventArgs(CardReaderResponse response, CardReaderException exception) { Response = response; Exception = exception; }