我正在尝试让我的串行GSM调制解调器与AT命令和PySerial一起使用。不幸的是,我总是遇到以下错误。
read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
我的代码如下:
serialSource = serial.Serial('/dev/ttyACM3', baudrate=115200, timeout=0.5, write_timeout=None)
serialSource.write(b'AT+CMGR=1\r\n')
chunkSize = 200
encodedRead = b''
while True:
byteChunk = serialSource.read(size=chunkSize)
encodedRead += byteChunk
if not len(byteChunk) == chunkSize:
break
print(encodedRead)
奇怪的是,我只会定期收到此错误,但并非总是如此。
read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
b'AT+CMGR=1\r\n\r\nOK\r\n'
read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
如果我在写入和读取之间放置一个time.sleep(0.1)
,那么我不会收到任何错误,但是它返回的是一个空字节数组b''
。有什么想法吗?