PoMoCo: Write Timeouts For Additional Ports

I noticed that PoMoCo will not connect via USB when I have bluetooth turned on. It turns out that it gets stuck while trying to write to some other ports. I added a couple write timeouts in the serHandler.connect in servotorComm.py when it calls serial.Serial. See Below.

    def connect(self):
            comList = []
            comports = serial.tools.list_ports.comports()
            for comport in comports:
                    for thing in comport:
                            #print thing
                            comList.append(thing)
            
            comList = list(set(comList))
            print "Attempting to connect to Servotor"
            for port in comList:
                    try:
                            ser = serial.Serial(port, baudrate= BAUD_RATE, timeout=2, writeTimeout = 1) #Added Timeout
                            ser.write('V\n')
                            result = ser.readline()
                            if "SERVOTOR" in result:
                                    print "Connect Successful! Connected on port:",port
                                    self.ser = ser
                                    self.ser.flush()
                                    self.serOpen = True
                                    self.serNum = 1
                                    break
                    except:
                            pass
            if self.serOpen == False:
                print "Trying Windows Method"
                for i in range(1,100):
                    try:
                        try:
                            ser = serial.Serial(i, baudrate=BAUD_RATE, timeout=1, writeTimeout = 1) #Added Timeout
                            #print "ser",i
                        except:
                            #print "ser",i,"failed"
                            raise Exception
                        ser.flush()
                        time.sleep(0.1)
                        ser.write("V\n")
                        time.sleep(1)
                        readReply = ser.readline()
                        #print "read:",readReply
                        if "SERVOTOR" in readReply:
                            print "Connect Successful! Connected on port COM"+str(i+1)
                            ser.flush()
                            self.ser = ser
                            self.serNum = i
                            self.serOpen = True
                            break
                        else:
                            ser.close()
                            pass
                    except:
                        pass

Just wanted to add a note here that I came up with the same solution. Pyserial returns a com list including the two com ports created by the bluetooth pairing, but if it gets the wrong one, it waits until the timeout in the Controller init function is reached, and then reports failure.

I upped the timeout time and added a writetimeout to the serial.Serial() calls, and I can now control it every time.

Prior to this, nothing seemed to get bluetooth working reliably.