]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - support/sdk/python/tos.py
Add support for COMX and X to tos.py
[tinyos-2.x.git] / support / sdk / python / tos.py
index a8f008d2818ac14bbb9b855dcf85c0449d566ab6..330df0c2a4c66b29f6790805e70b8a947eda2188 100644 (file)
@@ -67,15 +67,16 @@ class Timeout(Exception):
 def getSource(comm):
     source = comm.split('@')
     params = source[1].split(':')
+    debug = '--debug' in sys.argv
     if source[0] == 'serial':
         try:
-            return Serial(params[0], int(params[1]), flush=True, debug=('--debug' in sys.argv))
+            return Serial(params[0], int(params[1]), flush=True, debug=debug)
         except:
             print "ERROR: Unable to initialize a serial connection to", comm
             raise Exception
     elif source[0] == 'network':
         try:
-            return SerialMIB600(params[0], int(params[1]), debug=False)
+            return SerialMIB600(params[0], int(params[1]), debug=debug)
         except:
             print "ERROR: Unable to initialize a network connection to", comm
             print "ERROR:", traceback.format_exc()
@@ -89,6 +90,11 @@ class Serial:
         self.ackTimeout = ackTimeout
         self._ts = None
 
+        if port.startswith('COM') or port.startswith('com'):
+            port = int(port[3:]) - 1
+        elif port.isdigit():
+            port = int(port) - 1
+
         self._s = serial.Serial(port, int(baudrate), rtscts=0, timeout=0.5)
         self._s.flushInput()
         if flush:
@@ -122,7 +128,7 @@ class Serial:
         self._s.timeout = timeout
 
 class SerialMIB600:
-    def __init__(self, host, port=10002, debug=False, readTimeout=None, ackTimeout=0.05):
+    def __init__(self, host, port=10002, debug=False, readTimeout=None, ackTimeout=0.5):
         self.debug = debug
         self.readTimeout = readTimeout
         self.ackTimeout = ackTimeout