Brinda K
Brinda K

Reputation: 765

Send hex code to bluetooth

I have hex code like 0x38 , 0x39, 0xC0 and 0xE8 , i want to send this hex code as it is to blue-tooth, no need of conversion to hex or int. i used this code for sending in my app(blue-tooth Activity):

     byte[] hex_txt = {(byte)0x38, (byte)0x39, (byte)0xC0, (byte)0xE8};
     OutputStream outStream;
     try {
    outStream = socket.getOutputStream();
        outStream.write(hex_txt);
        System.out.println("byte sent: " + hex_txt);
         }

When i send this code to blue-tooth, it send further to Arduino board where it has to match these hex codes and do some operations.My arduino code is:

   if(Serial.available()>3)
    {

          if(Serial.read()==0x38 && Serial.read()==0x39)
          code=Serial.read()+Serial.read()*256;
          irsend.sendCode(code,16);
          Serial.println("code sent is");
          Serial.println(code,DEC);
   }

No Problem with this Arduino code but what 'm sending from my app to blue-tooth may be wrong..so it is not matching. In what type i need to send these hex codes?

Upvotes: 1

Views: 4665

Answers (1)

domsom
domsom

Reputation: 3171

-64 in decimal is probably a representation of 0xC0 (see http://en.wikipedia.org/wiki/Signed_number_representations). I'm not into Arduino code, but I'd suggest you make sure the values returned by Serial.read() is interpreted as an unsigned integers/bytes. This will get you around manually interpreting the signed bit representation and number output.

Upvotes: 2

Related Questions