# 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
bsl_standard.bslInit(self)
+if sys.platform == 'win32':
+ sys.path.append('.')
+ import cp210xrt
+else:
+ import fcntl
+
GPIOBIC = 0x89f2
GPIOBIS = 0x89f3
GPIO_2 = 0x04
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:
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:
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__"):