} //CheckResponseFrame

        internal void InitMsg(MBUS_message TransmitedMbusMessage)
        {
            userDataLength = userBuffLength;
            offset         = 0;
            switch (TransmitedMbusMessage.CheckFrameType())
            {
            case MBusFrameTypes.ShortFrame:
                switch (TransmitedMbusMessage.ShortFrameControlField)
                {
                case MBUSControlCodes.REQ_UD1:
                case MBUSControlCodes.REQ_UD1_FCBSet:
                case MBUSControlCodes.REQ_UD2:
                case MBUSControlCodes.REQ_UD2_FCBSet:
                    expectedframetype = MBusFrameTypes.LongFrame;
                    break;

                case MBUSControlCodes.SND_NKE:
                    expectedframetype = MBusFrameTypes.SingleCharacter;
                    break;

                default:
                    myAssert.Assert(false, 449);
                    break;
                }
                break;

            case MBusFrameTypes.LongFrame:
                switch (TransmitedMbusMessage.ShortFrameControlField)
                {
                case MBUSControlCodes.SND_UD:
                case MBUSControlCodes.SND_UD_FCBSet:
                    expectedframetype = MBusFrameTypes.SingleCharacter;
                    break;

                default:
                    myAssert.Assert(false, 461);
                    break;
                }
                break;

            default:
                myAssert.Assert(false, 466);
                break;
            }
            crc.clear();
        }
        public override CheckResponseResult CheckResponseFrame(ProtocolALMessage TransmitedMessage)
        {
            MBUS_message transmitedMbusMessage = (MBUS_message)TransmitedMessage;

            MBUSTrace(TraceEventType.Verbose, 266, "CheckResponseFrame:" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + this.ToString());
            switch (expectedframetype)
            {
            case MBusFrameTypes.LongFrame:
                #region MBusFrameTypes.LongFrame
                crc.clear();
                // wyslana ramka typu short - powinnismy otrzymac odpowiedz dluga ramke typu UserData
                if (this.userDataLength < 9)
                {
                    return(CheckResponseResult.CR_Incomplete);
                }
                // sprawdzamy start 68h
                if (this.startbyte != MBUSConstans.StartLong)
                {
                    return(CheckResponseResult.CR_Invalid);
                }
                //sprawdzamy dlugosc
                if (this[LongFrame_Length1Pos] != this[LongFrame_Length2Pos])
                {
                    return(CheckResponseResult.CR_Invalid);
                }
                int UserApplicationDataLength = this[LongFrame_Length1Pos] - 3;
                //sprawdzamy drugi start 68h
                if (this[LongFrame_MiddleStartPos] != (byte)MBUSConstans.StartLong)
                {
                    return(CheckResponseResult.CR_Invalid);
                }
                //sprawdzamy code (function) field (C)
                if (!(this[LongFrame_ControlFieldPos] == (byte)MBUSControlCodes.RSP_UD ||
                      this[LongFrame_ControlFieldPos] == (byte)MBUSControlCodes.RSP_UD_ACDSet ||
                      this[LongFrame_ControlFieldPos] == (byte)MBUSControlCodes.RSP_UD_ACDSet_DFCSet ||
                      this[LongFrame_ControlFieldPos] == (byte)MBUSControlCodes.RSP_UD_DFCSet
                      ))
                {
                    return(CheckResponseResult.CR_Invalid);
                }
                crc.CRC_Calc(this[LongFrame_ControlFieldPos]);
                //sprawdzamy addesss field (A)
                if (this.LongFrameStation != transmitedMbusMessage.ShortFrameStation && transmitedMbusMessage.ShortFrameStation != 254)
                {
                    //we accept any address if request was sent to bradcast address (254)
                    return(CheckResponseResult.CR_OtherStation);
                }
                crc.CRC_Calc(this.LongFrameStation);
                //sprawdzamy ControlInformation Field (CI)
                //MZNI: co zrobic z ControlInformation Field
                crc.CRC_Calc(this[LongFrame_ControlInformationFieldPos]);

                // teraz przegladamy userdata
                offset = LongFrame_StartUserDataPos;
                for (int idx = 0; idx < UserApplicationDataLength; idx++)
                // tutaj czytamy ramke - ale wazne jest ze nie mozemy przekroczycdlugosci calej ramki - 2 (na CRC +bajt stopu)
                {
                    byte userbyte = ReadByte();
                    crc.CRC_Calc(userbyte);
                    if (offset == userDataLength - 1)
                    {
                        return(CheckResponseResult.CR_Incomplete);
                    }
                }
                //teraz sprawdzamy sume kontrolna i stop byte na koncu:
                byte currentCRC = ReadByte();
                byte lastByte   = ReadByte();
                //crc:
                if (crc.CurrentCRC != currentCRC)
                {
                    return(CheckResponseResult.CR_CRCError);
                }
                //czy na koncu jest bajt stopu:
                if (lastByte != (byte)MBUSConstans.Stop)
                {
                    return(CheckResponseResult.CR_Invalid);
                }
                // teraz robimy przetworzenie danych w application layer i zwracamy wynik
                return(MbusApplicationLayerMessageAnalyser.AnalyseFrame(this, LongFrame_StartUserDataPos,
                                                                        transmitedMbusMessage.ExpectedDataAnalysisMode, myTrace));

                #endregion //MBusFrameTypes.LongFrame
            case MBusFrameTypes.ShortFrame:
            case MBusFrameTypes.ControlFrame:
            default:
                myAssert.Assert(false, 311);
                break;
            }
            return(CheckResponseResult.CR_Invalid);
        } //CheckResponseFrame