I trying to open two serial ports in Python with the following code:
for i in range(0, 2): if platform.system() == "Darwin": pos = 2+i else: pos = i port = serial.Serial(current_ports[pos], BAUD_RATE, timeout=TIMEOUT) time.sleep(1.516) port.write('#') time.sleep(1.516) out = '' print "Reading MAC Address...." while port.inWaiting() > 0: out += port.read(1) print out if out == '04:E9:E5:00:EC:51': led_port = port elif out == '04:E9:E5:01:0C:E0': matrix_port = port Sometimes the ports open successfully, sometimes they don't. When they don't, I get this error message:
Reading MAC Address....Traceback (most recent call last): File "animation.py", line 227, in <module> main() File "animation.py", line 208, in main led_port, matrix_port = get_ports() File"/Users/collinschupman/Documents/FutureCities/MurmurWall/Onsite/Raspi/helper_functions.py", line 41, in get_portswhile port.inWaiting() > 0: File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 449, in inWaiting s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)IOError: [Errno 6] Device not configuredAs you can see, it gets to the inWaiting() call and then throws this error.
For a little reference, the code is sending a message to a couple Arduinos so they can be identified by their MAC addresses.
Is there anything blatantly incorrect I'm doing Python-side which would cause this setup to fail once and a while? I'd say this code works 50% of the time right now.
Thanks,
Collin