Jul-13-2021, 12:48 PM
I'm running this code on a Raspberry Pi 4. If the program fails to close the port when it ends properly, the next time it runs it think there are more devices accessing the port.
Also, the documentation says to expect a status of AA 01 01 00 AC when MP3 has finished playing but the return appears to be 00 00 00, but the program is coded to accept the 00 00 00 to end.
I added print(" port ", ser.isOpen) in the read routine but how would I check to see if it thinks more devices are attempting to use the port?
What I saw after running this the second time is important! Shutting the RPi down and starting it fresh, I ran the program the first time with the print("port Open? ", isOpen) and the program ran and ended well printing the 00 00 00 return after the MP3 finished playing only. Makes me believe that the chip on the MP3 board can process only one thing at a time.
But the next observance is the real problem. When I ran the program again with no changes, I got the errors indicating that the device disconnected or multiple access on port. See output below.
Something needs to be closed or reset but at the end of the program is the ser.close() statement.
Also, the documentation says to expect a status of AA 01 01 00 AC when MP3 has finished playing but the return appears to be 00 00 00, but the program is coded to accept the 00 00 00 to end.
I added print(" port ", ser.isOpen) in the read routine but how would I check to see if it thinks more devices are attempting to use the port?
What I saw after running this the second time is important! Shutting the RPi down and starting it fresh, I ran the program the first time with the print("port Open? ", isOpen) and the program ran and ended well printing the 00 00 00 return after the MP3 finished playing only. Makes me believe that the chip on the MP3 board can process only one thing at a time.
But the next observance is the real problem. When I ran the program again with no changes, I got the errors indicating that the device disconnected or multiple access on port. See output below.
Something needs to be closed or reset but at the end of the program is the ser.close() statement.
Output:pi@raspberrypi:~ $ sudo python3 SerialTest3.py
Command = [170, 7, 2, 0, 4, 183]
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b'\xaa'
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b''
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b''
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b''
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b''
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b''
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb66e7bb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Status = b'\x00\x00\x00'
pi@raspberrypi:~ $ sudo python3 SerialTest3.py
Command = [170, 7, 2, 0, 4, 183]
Command = [170, 1, 0, 171]
port Open? <bound method SerialBase.isOpen of Serial<id=0xb664ebb0, open=True>(port='/dev/ttyS0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)>
Traceback (most recent call last):
File "/usr/lib/python3/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?)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "SerialTest3.py", line 37, in <module>
playing = read_status(ser)
File "SerialTest3.py", line 19, in read_status
return port.read(3)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 509, in read
raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)