Reputation: 187
I'm trying to read data from an RFID (RMD6300) to Raspberry Pi 1 in python but after reading for 30-40 secs whitout interruptions it crashes with the following error message:
Traceback (most recent call last): File "tmp.py", line 7, in string = ser.read(20) File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 501, in read 'device reports readiness to read but returned no data ' serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
this is my code:
import serial
ser = serial.Serial('/dev/ttyAMA0',9600, timeout=1)
IDs = ["xxxxxxxxxx","xxxxxxxxxx"]
while True:
bool = False;
string = ser.read(20)
if len(string) == 0:
print "Insert tag"
continue
else:
for i in range(len(IDs)):
for l in range(len(string)):
if IDs[i] in string:
print IDs[i]
bool = True
break
else:
string = string[1:]+string[0]
if bool:
break
if not bool:
print "Not found"
Upvotes: 1
Views: 6239
Reputation: 15513
Question: ... device reports readiness to read but returned no data
Increase your timeout
:
ser = serial.Serial('/dev/ttyAMA0',9600, timeout=1)
Use try ... except
try:
string = ser.read(20)
except serial.serialutil.SerialException:
except_counter +=1
if except_counter == 5:
break
time.sleep(1)
Question: ...device disconnected or multiple access on port?
Can you exclude this two points?
Upvotes: 3