I am using python 3.5 and i am getting error ValueError: chr() arg not in range(0x110000)in my code while i was using python 2.7 i was getting ValueError: chr() arg not in range(256). at if temp == chr(ord(rbuff)+1) or temp == chr(ord(rbuff)-1) or temp == chr(ord(rbuff)+2) or temp == chr(ord(rbuff)-2) or temp == chr(ord(rbuff)):this line.If possible provide me a solution for both python version.

the problem is, if rbuff contains the very last unicode character then ord(rbuff) will return 0x10ffff, which you proceed to add 1 to and try to convert that back into a character, but chr(0x110000) is invalid because unicode values are 0 to 0x10ffff only.

This is the same problem you saw with Python2, but there characters are single bytes which can have values 0 to 255 rather than Python3's unicode charaters which can have values 0 to 0x10ffff. The moment you tried to get chr(256) it gave you the error because chr() will only accept values from 0 to 255.

You would also have a problem if rbuff has the first valid character chr(0) as later in that if statement you try to do chr(ord(rbuff)-1) and chr(-1) is invalid. Also you try with +2 and -2 so will fail if rbuff is chr(1) or chr(0x10fffe).

The python serial got an upgrade between python2 and python3: the return in python3 is a bytes like object (was character in python2).
So if you want to send characters or string over serial in p3, then you need to encode. But if you want to handle bytes, then things get more simple.
So rbuff=ser.read() will return an array, get a byte with rbuff[0].