Example #1
0
    def pyserInit(self, port, timeout, attemptlimit):
        """Open the serial port"""
        if self.connected == 0:
            if (not (attemptlimit == None)) and (attemptlimit <= 1):
                # it always takes at least 2 tries
                attemptlimit == 2

            # Make timeout None to wait forever, 0 for non-blocking mode.
            import serial

            if os.name == 'nt' and sys.version.find('64 bit') != -1:
                print "WARNING: PySerial requires a 32-bit Python build in Windows."

            if port is None and os.environ.get("GOODFET") != None:
                glob_list = glob.glob(os.environ.get("GOODFET"))
                if len(glob_list) > 0:
                    port = glob_list[0]
                else:
                    port = os.environ.get("GOODFET")
            if port is None:
                glob_list = glob.glob("/dev/tty.usbserial*")
                if len(glob_list) > 0:
                    port = glob_list[0]
            if port is None:
                glob_list = glob.glob("/dev/ttyUSB*")
                if len(glob_list) > 0:
                    port = glob_list[0]
            if port is None:
                glob_list = glob.glob("/dev/ttyU0")
                if len(glob_list) > 0:
                    port = glob_list[0]
            if port is None and os.name == 'nt':
                from scanwin32 import winScan
                scan = winScan()
                for order, comport, desc, hwid in sorted(scan.comports()):
                    try:
                        if hwid.index('FTDI') == 0:
                            port = comport
                            #print "Using FTDI port %s" % port
                    except:
                        #Do nothing.
                        a = 1

            baud = 115200

            self.serialport = serial.Serial(port,
                                            baud,
                                            parity=serial.PARITY_NONE,
                                            timeout=timeout)

            self.verb = 0
            self.data = ""
            attempts = 0
            self.connected = 0

            while self.connected == 0:
                self.serialport.setDTR(False)
                while self.verb != 0x7F or self.data != "http://goodfet.sf.net/":
                    if attemptlimit is not None and attempts >= attemptlimit:
                        return

                    attempts = attempts + 1
                    self.readcmd()
                    #Read the first command.
                    if self.verbose:
                        print "Got %02x,%02x:'%s'" % (self.app, self.verb,
                                                      self.data)

                #Here we have a connection, but maybe not a good one.
                #print "We have a connection."
                for foo in range(1, 30):
                    time.sleep(1)
                    if not self.monitorecho():
                        self.connected = 0
                        if self.verbose:
                            print "Comm error on try %i." % (foo)
                    else:
                        self.connected = 1
                        break
            if self.verbose:
                print "Connected after %02i attempts." % attempts
            self.serialport.setTimeout(12)
Example #2
0
    def pyserInit(self, port, timeout, attemptlimit):
        """Open the serial port"""
        # Make timeout None to wait forever, 0 for non-blocking mode.
        import serial
        fixserial = False

        if os.name == 'nt' and sys.version.find('64 bit') != -1:
            print "WARNING: PySerial requires a 32-bit Python build in Windows."

        if port is None and os.environ.get("GOODFET") != None:
            glob_list = glob.glob(os.environ.get("GOODFET"))
            if len(glob_list) > 0:
                port = glob_list[0]
            else:
                port = os.environ.get("GOODFET")
        if port is None:
            glob_list = glob.glob("/dev/tty.usbserial*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyUSB*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyU0")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None and os.name == 'nt':
            from scanwin32 import winScan
            scan = winScan()
            for order, comport, desc, hwid in sorted(scan.comports()):
                try:
                    if hwid.index('FTDI') == 0:
                        port = comport
                        #print "Using FTDI port %s" % port
                except:
                    #Do nothing.
                    a = 1

        baud = 115200
        if (os.environ.get("platform") == 'arduino'
                or os.environ.get("board") == 'arduino'):
            baud = 19200
            #Slower, for now.
        self.serialport = serial.Serial(
            port,
            #9600,
            baud,
            parity=serial.PARITY_NONE,
            timeout=timeout)

        self.verb = 0
        attempts = 0
        connected = 0
        while connected == 0:
            while self.verb != 0x7F or self.data != "http://goodfet.sf.net/":
                #while self.data!="http://goodfet.sf.net/":
                #print "'%s'!=\n'%s'" % (self.data,"http://goodfet.sf.net/");
                if attemptlimit is not None and attempts >= attemptlimit:
                    return
                elif attempts == 2 and os.environ.get("board") != 'telosb':
                    print "See the GoodFET FAQ about missing info flash."
                    self.serialport.setTimeout(0.2)
                elif attempts == 100:
                    print "Tried 100 times to connect and failed."
                    sys.stdout.write(
                        "Continuing to try forever.")  # No newline
                    sys.stdout.flush()
                    self.verbose = True  # Something isn't going right, give the user more info
                elif attempts > 100 and attempts % 10 == 0:
                    sys.stdout.write('.')
                    sys.stdout.flush()
                #self.serialport.flushInput()
                #self.serialport.flushOutput()

                #TelosB reset, prefer software to I2C SPST Switch.
                if (os.environ.get("board") == 'telosb'):
                    #print "TelosB Reset";
                    self.telosBReset()
                elif (os.environ.get("board") == 'z1'):
                    self.bslResetZ1(invokeBSL=0)
                elif (os.environ.get("board")
                      == 'apimote1') or (os.environ.get("board") == 'apimote'):
                    #Explicitly set RTS and DTR to halt board.
                    self.serialport.setRTS(1)
                    self.serialport.setDTR(1)
                    #RTS pin, not DTR is used for reset.
                    self.serialport.setRTS(0)
                    #print "Resetting Apimote not yet tested.";
                else:
                    #Explicitly set RTS and DTR to halt board.
                    self.serialport.setRTS(1)
                    self.serialport.setDTR(1)
                    #Drop DTR, which is !RST, low to begin the app.
                    self.serialport.setDTR(0)

                #self.serialport.write(chr(0x80));
                #self.serialport.write(chr(0x80));
                #self.serialport.write(chr(0x80));
                #self.serialport.write(chr(0x80));

                #self.serialport.flushInput()
                #self.serialport.flushOutput()
                #time.sleep(60);
                attempts = attempts + 1
                self.readcmd()
                #Read the first command.
                #print "Got %02x,%02x:'%s'" % (self.app,self.verb,self.data);
                if self.verb != 0x7f:
                    #Retry again. This usually times out, but helps connect.
                    self.readcmd()
                    #print "Retry got %02x,%02x:'%s'" % (self.app,self.verb,self.data);
            #Here we have a connection, but maybe not a good one.
            #print "We have a connection."
            connected = 1
            if attempts >= 100:
                print ""  # Add a newline
            olds = self.infostring()
            clocking = self.monitorclocking()
            for foo in range(1, 30):
                if not self.monitorecho():
                    if self.verbose:
                        print "Comm error on %i try, resyncing out of %s." % (
                            foo, clocking)
                    connected = 0
                    break
        if self.verbose: print "Connected after %02i attempts." % attempts
        self.mon_connected()
        self.serialport.setTimeout(12)
Example #3
0
    def pyserInit(self, port, timeout, attemptlimit):
        """Open the serial port"""
        # Make timeout None to wait forever, 0 for non-blocking mode.
        import serial
        fixserial=False
        
        if os.name=='nt' and sys.version.find('64 bit')!=-1:
            print("WARNING: PySerial requires a 32-bit Python build in Windows.")
        
        if port is None and os.environ.get("GOODFET")!=None:
            glob_list = glob.glob(os.environ.get("GOODFET"))
            if len(glob_list) > 0:
                port = glob_list[0]
            else:
                port = os.environ.get("GOODFET")
        if port is None:
            glob_list = glob.glob("/dev/tty.usbserial*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyUSB*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyU0")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None and os.name=='nt':
            from scanwin32 import winScan
            scan=winScan()
            for order,comport,desc,hwid in sorted(scan.comports()):
                try:
                    if hwid.index('FTDI')==0:
                        port=comport
                        #print("Using FTDI port %s" % port)
                except:
                    #Do nothing.
                    a=1
        
        baud=115200
        if(os.environ.get("platform")=='arduino' or os.environ.get("board")=='arduino'):
            baud=19200; #Slower, for now.
        self.serialport = serial.Serial(
            port,
            #9600,
            baud,
            parity = serial.PARITY_NONE,
            timeout=timeout
            )
        
        self.verb=0
        attempts=0
        connected=0
        while connected==0:
            while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
            #while self.data!="http://goodfet.sf.net/":
                #print("'%s'!=\n'%s'" % (self.data,"http://goodfet.sf.net/"))
                if attemptlimit is not None and attempts >= attemptlimit:
                    return
                elif attempts==2 and os.environ.get("board")!='telosb':
                    print("See the GoodFET FAQ about missing info flash.")
                    self.serialport.setTimeout(0.2)
                elif attempts == 100:
                  print("Tried 100 times to connect and failed.")
                  sys.stdout.write("Continuing to try forever.")	# No newline
                  sys.stdout.flush()
                  self.verbose=True	# Something isn't going right, give the user more info
                elif attempts > 100 and attempts % 10 == 0:
                  sys.stdout.write('.')
                  sys.stdout.flush()
                #self.serialport.flushInput()
                #self.serialport.flushOutput()

                #TelosB reset, prefer software to I2C SPST Switch.
                if (os.environ.get("board")=='telosb'):
                    #print("TelosB Reset")
                    self.telosBReset()
                elif (os.environ.get("board")=='z1'):
                    self.bslResetZ1(invokeBSL=0)
                elif (os.environ.get("board")=='apimote1') or (os.environ.get("board")=='apimote'):
                    #Explicitly set RTS and DTR to halt board.
                    self.serialport.setRTS(1)
                    self.serialport.setDTR(1)
                    #RTS pin, not DTR is used for reset.
                    self.serialport.setRTS(0)
                    #print("Resetting Apimote not yet tested.")
                else:
                    #Explicitly set RTS and DTR to halt board.
                    self.serialport.setRTS(1)
                    self.serialport.setDTR(1)
                    #Drop DTR, which is !RST, low to begin the app.
                    self.serialport.setDTR(0)
                
                #self.serialport.write(chr(0x80))
                #self.serialport.write(chr(0x80))
                #self.serialport.write(chr(0x80))
                #self.serialport.write(chr(0x80))
                
                
                #self.serialport.flushInput()
                #self.serialport.flushOutput()
                #time.sleep(60)
                attempts=attempts+1
                self.readcmd(); #Read the first command.
                #print("Got %02x,%02x:'%s'" % (self.app,self.verb,self.data))
                if self.verb!=0x7f:
                    #Retry again. This usually times out, but helps connect.
                    self.readcmd()
                    #print("Retry got %02x,%02x:'%s'" % (self.app,self.verb,self.data))
            #Here we have a connection, but maybe not a good one.
            #print("We have a connection.")
            connected=1
        if attempts >= 100:
            print("")	# Add a newline
            olds=self.infostring()
            clocking=self.monitorclocking()
            for foo in range(1,30):
                if not self.monitorecho():
                    if self.verbose:
                        print("Comm error on %i try, resyncing out of %s." % (foo,
                                                                              clocking))
                    connected=0
                    break
        if self.verbose: print("Connected after %02i attempts." % attempts)
        self.mon_connected()
        self.serialport.setTimeout(12)
    def serInit(self, port=None, timeout=2):
        """Open the serial port"""
        # Make timeout None to wait forever, 0 for non-blocking mode.

        if port is None and os.environ.get("GOODFET") != None:
            glob_list = glob.glob(os.environ.get("GOODFET"))
            if len(glob_list) > 0:
                port = glob_list[0]
            else:
                port = os.environ.get("GOODFET")
        if port is None:
            glob_list = glob.glob("/dev/tty.usbserial*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyUSB*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if os.name == "nt":
            from scanwin32 import winScan

            scan = winScan()
            for order, comport, desc, hwid in sorted(scan.comports()):
                if hwid.index("FTDI") == 0:
                    port = comport
                    # print "Using FTDI port %s" % port

        self.serialport = serial.Serial(
            port,
            # 9600,
            115200,
            parity=serial.PARITY_NONE,
            timeout=timeout,
        )

        self.verb = 0
        attempts = 0
        connected = 0
        while connected == 0:
            while self.verb != 0x7F or self.data != "http://goodfet.sf.net/":
                # print "Resyncing.";
                self.serialport.flushInput()
                self.serialport.flushOutput()
                # Explicitly set RTS and DTR to halt board.
                self.serialport.setRTS(1)
                self.serialport.setDTR(1)
                # Drop DTR, which is !RST, low to begin the app.
                self.serialport.setDTR(0)
                self.serialport.flushInput()
                self.serialport.flushOutput()
                # time.sleep(60);
                attempts = attempts + 1
                self.readcmd()
                # Read the first command.
            # Here we have a connection, but maybe not a good one.
            connected = 1
            olds = self.infostring()
            clocking = self.monitorclocking()
            for foo in range(1, 30):
                if not self.monitorecho():
                    if self.verbose:
                        print "Comm error on %i try, resyncing out of %s." % (foo, clocking)
                    connected = 0
                    break
        if self.verbose:
            print "Connected after %02i attempts." % attempts
        self.mon_connected()
    def pyserInit(self, port, timeout, attemptlimit):
        """Open the serial port"""
        if self.connected == 0:
            if (not (attemptlimit == None)) and (attemptlimit <= 1):
                # it always takes at least 2 tries
                attemptlimit == 2

            # Make timeout None to wait forever, 0 for non-blocking mode.
            import serial;

            if os.name=='nt' and sys.version.find('64 bit')!=-1:
                print "WARNING: PySerial requires a 32-bit Python build in Windows.";

            if port is None and os.environ.get("GOODFET")!=None:
                glob_list = glob.glob(os.environ.get("GOODFET"));
                if len(glob_list) > 0:
                    port = glob_list[0];
                else:
                    port = os.environ.get("GOODFET");
            if port is None:
                glob_list = glob.glob("/dev/tty.usbserial*");
                if len(glob_list) > 0:
                    port = glob_list[0];
            if port is None:
                glob_list = glob.glob("/dev/ttyUSB*");
                if len(glob_list) > 0:
                    port = glob_list[0];
            if port is None:
                glob_list = glob.glob("/dev/ttyU0");
                if len(glob_list) > 0:
                    port = glob_list[0];
            if port is None and os.name=='nt':
                from scanwin32 import winScan;
                scan=winScan();
                for order,comport,desc,hwid in sorted(scan.comports()):
                    try:
                        if hwid.index('FTDI')==0:
                            port=comport;
                            #print "Using FTDI port %s" % port
                    except:
                        #Do nothing.
                        a=1;

            baud=115200;

            self.serialport = serial.Serial(
                port,
                baud,
                parity = serial.PARITY_NONE,
                timeout=timeout
                )

            self.verb=0;
            self.data=""
            attempts=0;
            self.connected=0;

            while self.connected==0:
                self.serialport.setDTR(False)
                while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
                    if attemptlimit is not None and attempts >= attemptlimit:
                        return

                    attempts=attempts+1;
                    self.readcmd(); #Read the first command.
                    if self.verbose:
                        print "Got %02x,%02x:'%s'" % (self.app,self.verb,self.data);

                #Here we have a connection, but maybe not a good one.
                #print "We have a connection."
                for foo in range(1,30):
                    time.sleep(1)
                    if not self.monitorecho():
                        self.connected = 0
                        if self.verbose:
                            print "Comm error on try %i." % (foo)
                    else:
                        self.connected = 1
                        break
            if self.verbose:
                print "Connected after %02i attempts." % attempts;
            self.serialport.setTimeout(12);
Example #6
0
    def serInit(self, port=None, timeout=2):
        """Open the serial port"""
        # Make timeout None to wait forever, 0 for non-blocking mode.

        if port is None and os.environ.get("GOODFET") != None:
            glob_list = glob.glob(os.environ.get("GOODFET"))
            if len(glob_list) > 0:
                port = glob_list[0]
            else:
                port = os.environ.get("GOODFET")
        if port is None:
            glob_list = glob.glob("/dev/tty.usbserial*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if port is None:
            glob_list = glob.glob("/dev/ttyUSB*")
            if len(glob_list) > 0:
                port = glob_list[0]
        if os.name == 'nt':
            from scanwin32 import winScan
            scan = winScan()
            for order, comport, desc, hwid in sorted(scan.comports()):
                if hwid.index('FTDI') == 0:
                    port = comport
                    #print "Using FTDI port %s" % port

        self.serialport = serial.Serial(
            port,
            #9600,
            115200,
            parity=serial.PARITY_NONE,
            timeout=timeout)

        self.verb = 0
        attempts = 0
        connected = 0
        while connected == 0:
            while self.verb != 0x7F or self.data != "http://goodfet.sf.net/":
                #print "Resyncing.";
                self.serialport.flushInput()
                self.serialport.flushOutput()
                #Explicitly set RTS and DTR to halt board.
                self.serialport.setRTS(1)
                self.serialport.setDTR(1)
                #Drop DTR, which is !RST, low to begin the app.
                self.serialport.setDTR(0)
                self.serialport.flushInput()
                self.serialport.flushOutput()
                #time.sleep(60);
                attempts = attempts + 1
                self.readcmd()
                #Read the first command.
            #Here we have a connection, but maybe not a good one.
            connected = 1
            olds = self.infostring()
            clocking = self.monitorclocking()
            for foo in range(1, 30):
                if not self.monitorecho():
                    if self.verbose:
                        print "Comm error on %i try, resyncing out of %s." % (
                            foo, clocking)
                    connected = 0
                    break
        if self.verbose: print "Connected after %02i attempts." % attempts
        self.mon_connected()
Example #7
0
 def serInit(self, port=None, timeout=2, attemptlimit=None):
     """Open the serial port"""
     # Make timeout None to wait forever, 0 for non-blocking mode.
     
     if os.name=='nt' and sys.version.find('64 bit')!=-1:
         print "WARNING: PySerial requires a 32-bit Python build in Windows.";
     
     if port is None and os.environ.get("GOODFET")!=None:
         glob_list = glob.glob(os.environ.get("GOODFET"));
         if len(glob_list) > 0:
             port = glob_list[0];
         else:
             port = os.environ.get("GOODFET");
     if port is None:
         glob_list = glob.glob("/dev/tty.usbserial*");
         if len(glob_list) > 0:
             port = glob_list[0];
     if port is None:
         glob_list = glob.glob("/dev/ttyUSB*");
         if len(glob_list) > 0:
             port = glob_list[0];
     if port is None:
         glob_list = glob.glob("/dev/ttyU0");
         if len(glob_list) > 0:
             port = glob_list[0];
     if port is None and os.name=='nt':
         from scanwin32 import winScan;
         scan=winScan();
         for order,comport,desc,hwid in sorted(scan.comports()):
             try:
                 if hwid.index('FTDI')==0:
                     port=comport;
                     #print "Using FTDI port %s" % port
             except:
                 #Do nothing.
                 a=1;
     
     baud=115200;
     if(os.environ.get("platform")=='arduino'):
         baud=19200; #Slower, for now.
     self.serialport = serial.Serial(
         port,
         #9600,
         baud,
         parity = serial.PARITY_NONE,
         timeout=timeout
         )
     
     self.verb=0;
     attempts=0;
     connected=0;
     while connected==0:
         #print "Got %s" % self.data;
         while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
             if attemptlimit is not None and attempts >= attemptlimit:
                 return
             elif attempts>2:
                 print "Resyncing.";
             self.serialport.flushInput()
             self.serialport.flushOutput()
             #Explicitly set RTS and DTR to halt board.
             self.serialport.setRTS(1);
             self.serialport.setDTR(1);
             #Drop DTR, which is !RST, low to begin the app.
             self.serialport.setDTR(0);
             
             #TelosB reset, prefer software to I2C SPST Switch.
             if(os.environ.get("platform")=='telosb'):
                 #print "TelosB Reset";
                 self.telosBReset();
             
                 
             #self.serialport.write(chr(0x80));
             #self.serialport.write(chr(0x80));
             #self.serialport.write(chr(0x80));
             #self.serialport.write(chr(0x80));
             
             
             self.serialport.flushInput()
             self.serialport.flushOutput()
             #time.sleep(60);
             attempts=attempts+1;
             self.readcmd(); #Read the first command.
         #Here we have a connection, but maybe not a good one.
         #print "We have a connection."
         connected=1;
         olds=self.infostring();
         clocking=self.monitorclocking();
         #if(os.environ.get("platform")!='arduino'):
         for foo in range(1,30):
             if not self.monitorecho():
                 if self.verbose:
                     print "Comm error on %i try, resyncing out of %s." % (foo,
                                                                           clocking);
                     connected=0;
                     break;
     if self.verbose: print "Connected after %02i attempts." % attempts;
     self.mon_connected();
     self.serialport.setTimeout(12);