]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/platforms/msp430/pybsl/tos-bsl.in
Update tos-bsl for win32 python
[tinyos-2.x.git] / tools / platforms / msp430 / pybsl / tos-bsl.in
old mode 100644 (file)
new mode 100755 (executable)
index 4cd94d8..6809e3b
 # from bsl_standard or one of its specializations.
 #
 
-import sys, fcntl, time, string, cStringIO, struct
+import sys, time, string, cStringIO, struct
 sys.path.append("@tinyoslibdir@")
 import serial
 
@@ -1423,6 +1423,12 @@ class bsl_cp2103(bsl_standard):
        bsl_standard.bslInit(self)
 
 
+if sys.platform == 'win32':
+    sys.path.append('.')
+    import cp210xrt
+else:
+    import fcntl
+
 GPIOBIC  = 0x89f2
 GPIOBIS  = 0x89f3
 GPIO_2 = 0x04
@@ -1439,7 +1445,7 @@ class cp2103_posix:
 
     def setGpio2(self, assertme):
        """ set not assertme to the gpio pin """
-        if not self.fd: raise "connection not open"
+        if not self.fd: raise BSLException("connection not open")
         if assertme:
             fcntl.ioctl(self.fd, GPIOBIC, GPIO_2)
         else:
@@ -1448,7 +1454,7 @@ class cp2103_posix:
 
     def setGpio3(self, assertme):
        """ set not assertme to the gpio pin """
-        if not self.fd: raise "connection not open"
+        if not self.fd: raise BSLException("connection not open")
         if assertme:
             fcntl.ioctl(self.fd, GPIOBIC, GPIO_3)
         else:
@@ -1456,42 +1462,36 @@ class cp2103_posix:
        time.sleep(0.010) # no sleep = too fast
 
 
-class cp2103_cygwin:
+class cp2103_win32:
     """
-       Implements cp2103 gpio access for windows cygwin systems via the
+       Implements cp2103 gpio access for windows win32 systems via the
         cp210x VCP and the CP210xRuntime.dll.
     """
     def __init__(self, serialport):
-       import cp210xrt
-       sys.stderr.write("cp2103_cygwin\n")
-       self.fd = serialport.fd
+       self.hComPort = serialport.hComPort
 
     def setGpio2(self, assertme):
        """ set not assertme to the gpio pin """
-       import cp210xrt
         if assertme:
-           cp210xrt.writeLatch(self.fd, GPIO_2, 0)
+           cp210xrt.writeLatch(self.hComPort, GPIO_2, 0)
        else:
-           cp210xrt.writeLatch(self.fd, GPIO_2, GPIO_2)
+           cp210xrt.writeLatch(self.hComPort, GPIO_2, GPIO_2)
 
     def setGpio3(self, assertme):
        """ set not assertme to the gpio pin """
-       import cp210xrt
         if assertme:
-           cp210xrt.writeLatch(self.fd, GPIO_3, 0)
+           cp210xrt.writeLatch(self.hComPort, GPIO_3, 0)
        else:
-           cp210xrt.writeLatch(self.fd, GPIO_3, GPIO_3)
+           cp210xrt.writeLatch(self.hComPort, GPIO_3, GPIO_3)
 
 
 def cp2103_factory(serialport):
-    import os;
-    if os.name == 'posix':
-       if sys.platform == 'cygwin':
-           return cp2103_cygwin(serialport)
-       else:
-           return cp2103_posix(serialport)
+    if sys.platform == 'win32':
+       return cp2103_win32(serialport)
+    elif sys.platform != 'cygwin':
+       return cp2103_posix(serialport)
     else:
-       raise "No cp2103 support is available for your platform."
+       raise BSLException("No cp2103 support is available for your platform.")
 
 
 def getClass(classname, modulename="__main__"):