1

We are trying to read RFID tags using raspberry pi b+. We used following script in the python .

import serial import time serial=serial.Serial("/dev/ttyUSB0", baudrate=2400) while True: if serial.inWaiting()>0: read_result=serial.read(12) print("Read card {0}",format(read_result.decode("utf-8","replace"))) print("Sleeping 2 sec") time.sleep(2) serial.flushInput() 

On reading the tag it gives the error as:

File "/home/pi/rfidtry/try.py",line 7, in <module> print("Read card {0}",format(read_result.decode("utf-8","replace"))) UnicodeEncodeError: 'ascii' codac can't encode character u'\uffd' in position 2 :ordinal not in range(128) 
1
  • Can you omit the replace and show the output? (It should give you a slightly different error message) Commented Mar 28, 2015 at 10:52

3 Answers 3

0

As suggested in this post, it might work if you encoded your unicode string first to ascii and then decode it.

read_result.encode('ascii','replace').decode('utf-8') 

Of course, you will lose the non-working characters.

Sign up to request clarification or add additional context in comments.

Comments

0

Did you try this

print read_result 

and see if it works (instead of )

print("Read card {0}",format(read_result.decode("utf-8","replace"))) 

1 Comment

This should most likely have been a comment.
0

The problem was with the baudrate. The earlier reader i used was 2400 but the one i am using now is 9600.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.