示例#1
0
        protected override void OnAvailableBytes(byte[] buffer, int count)
        {
            foreach (Byte c in buffer)
            {
                if (this.ResponseState == ResponseParseState.Beginning)
                {
                    if (c != 0x40)  // @
                    {
                        throw new Exception("Invalid response format seen");
                    }

                    this.ResponseState = ResponseParseState.Middle;
                    continue;
                }

                // else

                // carriage return is end of response
                if (c == 0x0d)
                {
                    this.HandleFullResponse(this.PartialResponse);

                    this.PartialResponse = "";
                    this.ResponseState   = ResponseParseState.Beginning;
                    continue;
                }

                this.PartialResponse += (char)c;
            }
        }
示例#2
0
        protected override void OnAvailableBytes(byte[] buffer, int count)
        {
            // responses start with 0x02 and end with 0x03. everything in between is payload
            foreach (Byte b in buffer)
            {
                if (this.ResponseState == ResponseParseState.Beginning)
                {
                    if (b != 0x02)
                    {
                        throw new Exception("Unknown response format from TV");
                    }

                    this.ResponseState = ResponseParseState.Middle;
                    continue;
                }

                // else we must be in the middle

                // end of transmission
                if (b == 0x03)
                {
                    this.HandleFullResponse(this.PartialResponse);
                    this.ResponseState   = ResponseParseState.Beginning;
                    this.PartialResponse = "";
                    continue;
                }

                this.PartialResponse += (char)b;
            }
        }
示例#3
0
        protected override void OnAvailableBytes(byte[] buffer, int count)
        {
            foreach(Byte c in buffer) {
                if(this.ResponseState == ResponseParseState.Beginning) {
                    if(c != 0x40) { // @
                        throw new Exception("Invalid response format seen");
                    }

                    this.ResponseState = ResponseParseState.Middle;
                    continue;
                }

                // else

                // carriage return is end of response
                if(c == 0x0d) {
                    this.HandleFullResponse(this.PartialResponse);

                    this.PartialResponse = "";
                    this.ResponseState = ResponseParseState.Beginning;
                    continue;
                }

                this.PartialResponse += (char)c;
            }
        }
示例#4
0
        protected override void OnAvailableBytes(byte[] buffer, int count)
        {
            // responses start with 0x02 and end with 0x03. everything in between is payload
            foreach(Byte b in buffer) {
                if(this.ResponseState == ResponseParseState.Beginning) {
                    if(b != 0x02) {
                        throw new Exception("Unknown response format from TV");
                    }

                    this.ResponseState = ResponseParseState.Middle;
                    continue;
                }

                // else we must be in the middle

                // end of transmission
                if(b == 0x03) {
                    this.HandleFullResponse(this.PartialResponse);
                    this.ResponseState = ResponseParseState.Beginning;
                    this.PartialResponse = "";
                    continue;
                }

                this.PartialResponse += (char)b;
            }
        }