예제 #1
0
        /// <summary>
        /// Receives a response TPDU
        /// </summary>
        /// <returns></returns>
        public byte[] ReceiveResponsePacket()
        {
            int receiveCounter = 0;

            while (receiveCounter < MAX_BLOCKREPEATS)
            {
                byte[] tpduFrameData = ReceiveTpduFrame();

                if (tpduFrameData == null)
                {
                    throw new ConnectionTimeOutException();
                }

                RS232Tpdu receivedTpdu = RS232Tpdu.CreateFromTPDUBytes(tpduFrameData);

                if (receivedTpdu.CheckCRC(tpduFrameData[tpduFrameData.Length - 2], tpduFrameData[tpduFrameData.Length - 1]))
                {
                    SendStatus(ACK);
                    return(receivedTpdu.GetAPDUData());
                }

                receiveCounter++;
                SendStatus(NAK);
            }

            return(null);
        }
예제 #2
0
        public static RS232Tpdu CreateFromTPDUBytes(byte[] data)
        {
            if (data == null)
                return null;

            RS232Tpdu tpdu = new RS232Tpdu();

            List<byte> apduBytes = new List<byte>(data);
            apduBytes.RemoveRange(0, 2);
            apduBytes.RemoveRange(apduBytes.Count - 4, 4);

            tpdu.ApduData = UnescapeAPDU(apduBytes.ToArray());

            return tpdu;
        }
예제 #3
0
        public static RS232Tpdu CreateFromTPDUBytes(byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            RS232Tpdu tpdu = new RS232Tpdu();

            List <byte> apduBytes = new List <byte>(data);

            apduBytes.RemoveRange(0, 2);
            apduBytes.RemoveRange(apduBytes.Count - 4, 4);

            tpdu.ApduData = UnescapeAPDU(apduBytes.ToArray());

            return(tpdu);
        }
예제 #4
0
        /// <summary>
        /// Receives a response TPDU
        /// </summary>
        /// <returns></returns>
        public byte[] ReceiveResponsePacket()
        {
            int receiveCounter = 0;

            while (receiveCounter < MAX_BLOCKREPEATS)
            {
                byte[]    tpduFrameData = ReceiveTpduFrame();
                RS232Tpdu receivedTpdu  = RS232Tpdu.CreateFromTPDUBytes(tpduFrameData);
                if (tpduFrameData != null && receivedTpdu.CheckCRC(tpduFrameData[tpduFrameData.Length - 2], tpduFrameData[tpduFrameData.Length - 1]))
                {
                    SendStatus(ACK);
                    return(receivedTpdu.GetAPDUData());
                }
                else
                {
                    receiveCounter++;
                    SendStatus(NAK);
                }
            }

            return(null);
        }