Exemplo n.º 1
1
        public void Process(IZvtApdu requestApdu, IZvtApdu responseApdu)
        {
            PrintDocument printDocument;

            if (_printDocuments.Count == 0)
            {
                printDocument = new PrintDocument();
                _printDocuments.Add(printDocument);
            }
            else
                printDocument = (PrintDocument)_printDocuments[_printDocuments.Count - 1];

            printDocument.AddRange(((PrintLineApduResponse)responseApdu).ConvertToPrintLine());

            if (((PrintLineApduResponse)responseApdu).LastLine)
            {
                printDocument = new PrintDocument();
                _printDocuments.Add(printDocument);
            }
        }
        /// <summary>
        /// Checks if this handler is compatible with the specified apdu
        /// </summary>
        /// <param name="responseApdu"></param>
        /// <returns></returns>
        public bool IsCompatibleHandler(IZvtApdu responseApdu)
        {
            foreach (byte[] compatibleApdu in _compatibleApdus)
            {
                if (responseApdu.ControlField.Equals(compatibleApdu))
                    return true;
            }

            return false;
        }
 /// <summary>
 /// Finds the handlers of the specified response apdu
 /// </summary>
 /// <param name="apdu"></param>
 /// <returns></returns>
 private void CallResponseApduHandlers(IZvtApdu requestApdu, IZvtApdu responseApdu)
 {
     foreach (IApduHandler handler in _apduHandlers)
     {
         if (handler.IsCompatibleHandler(responseApdu))
         {
             handler.Process(requestApdu, responseApdu);
         }
     }
 }
        /// <summary>
        /// Checks if this handler is compatible with the specified apdu
        /// </summary>
        /// <param name="responseApdu"></param>
        /// <returns></returns>
        public bool IsCompatibleHandler(IZvtApdu responseApdu)
        {
            foreach (byte[] compatibleApdu in _compatibleApdus)
            {
                if (responseApdu.ControlField.Equals(compatibleApdu))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks if this handler is compatible with the specified apdu
        /// </summary>
        /// <param name="responseApdu"></param>
        /// <returns></returns>
        public bool IsCompatibleHandler(IZvtApdu responseApdu)
        {
            Console.WriteLine("Received: {0:x2}, {1:x2}", responseApdu.ControlField.Class, responseApdu.ControlField.Instruction);
            foreach (byte[] compatibleApdu in _compatibleApdus)
            {
                if (responseApdu.ControlField.Equals(compatibleApdu))
                {
                    return(true);
                }
            }

            return(false);
        }
        public ApduCollection TransmitAPDU(IZvtApdu apdu)
        {
            foreach (IApduHandler apduHandler in _apduHandlers)
            {
                apduHandler.StartCommand();
            }


            _transport.Transmit(_transport.CreateTpdu(apdu));

            ApduCollection responses = new ApduCollection();

            while (true)
            {
                byte[] apduData = _transport.ReceiveResponsePacket();
                byte[] apduCopy = new byte[apduData.Length];
                Array.Copy(apduData, apduCopy, apduData.Length);
                IZvtApdu responseApdu = ApduResponse.Create(apduData);

                if (responseApdu == null)
                {
                    throw new ArgumentException("Could not retrieve response");
                }

                if (this.ResponseReceived != null)
                {
                    ResponseReceived(responseApdu);
                }

                responses.Add(responseApdu);

                CallResponseApduHandlers(apdu, responseApdu);

                if (IsCompletionPacket == null && InternalIsCompletionPacket(apdu, responseApdu))
                {
                    break;
                }
                else if (IsCompletionPacket != null && IsCompletionPacket(apdu, responseApdu))
                {
                    break;
                }
            }

            return(responses);
        }
Exemplo n.º 7
0
        public void Process(IZvtApdu requestApdu, IZvtApdu responseApdu)
        {
            PrintDocument printDocument;

            if (_printDocuments.Count == 0)
            {
                printDocument = new PrintDocument();
                _printDocuments.Add(printDocument);
            }
            else
            {
                printDocument = (PrintDocument)_printDocuments[_printDocuments.Count - 1];
            }

            printDocument.AddRange(((PrintLineApduResponse)responseApdu).ConvertToPrintLine());

            if (((PrintLineApduResponse)responseApdu).LastLine)
            {
                printDocument = new PrintDocument();
                _printDocuments.Add(printDocument);
            }
        }
        private bool InternalIsCompletionPacket(IZvtApdu transmittedApdu, IZvtApdu responseApdu)
        {
            if (transmittedApdu.SendsCompletionPacket)
            {
                byte[] apduData = responseApdu.GetRawApduData();

                if (apduData[0] == 0x80 && apduData[1] == 0x00)
                {
                    _transport.MasterMode = false;
                }
                if (responseApdu is CompletionApduResponse || responseApdu is AbortApduResponse ||
                    (responseApdu is StatusApdu && ((StatusApdu)responseApdu).Status != StatusCodes.ErrorIDEnum.NoError))
                {
                    _transport.MasterMode = true;
                    return(true);
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 9
0
 protected virtual void ResponseReceived(IZvtApdu responseApdu)
 {
 }
Exemplo n.º 10
0
 private void _commandTransmitter_ResponseReceived(IZvtApdu responseApdu)
 {
 }
Exemplo n.º 11
0
 public RS232Tpdu(IZvtApdu apdu)
     : this(apdu.GetRawApduData())
 {
 }
Exemplo n.º 12
0
 public void Process(IZvtApdu requestApdu, IZvtApdu responseApdu)
 {
     _transport.Transmit(_transport.CreateTpdu(new StatusApdu()));
 }
Exemplo n.º 13
0
 public RS232Tpdu(IZvtApdu apdu)
     : this(apdu.GetRawApduData())
 {
 }
Exemplo n.º 14
0
 public IZvtTpdu CreateTpdu(IZvtApdu apdu)
 {
     return new RS232Tpdu(apdu);
 }
Exemplo n.º 15
0
 public NetworkTpdu(IZvtApdu apdu)
     : this(apdu.GetRawApduData())
 {
 }
Exemplo n.º 16
0
 public IZvtTpdu CreateTpdu(IZvtApdu apdu)
 {
     return(new RS232Tpdu(apdu));
 }
Exemplo n.º 17
0
 public IZvtTpdu CreateTpdu(IZvtApdu apdu)
 {
     return(new NetworkTpdu(apdu));
 }
 public void Process(IZvtApdu requestApdu, IZvtApdu responseApdu)
 {
     _intermediateStatusCallback(responseApdu as IntermediateStatusApduResponse);
 }
Exemplo n.º 19
0
 private void _commandTransmitter_ResponseReceived(IZvtApdu responseApdu)
 {
 }
 public void Process(IZvtApdu requestApdu, IZvtApdu responseApdu)
 {
     _intermediateStatusCallback(responseApdu as IntermediateStatusApduResponse);
 }
Exemplo n.º 21
0
 public NetworkTpdu(IZvtApdu apdu)
     : this(apdu.GetRawApduData())
 {
 }