- # 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;
- connected=0;
-
- while connected==0:
- while self.verb!=0x7F or 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);
- #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);
-
- 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():
- connected = 0
- if self.verbose:
- print "Comm error on try %i." % (foo)
+ 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];