From: R. Steve McKown Date: Fri, 15 Mar 2013 15:04:38 +0000 (-0600) Subject: Update tos-bsl for win32 python X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=add98f2f5788d2ee9f8104881fd0a2bc97f2c209 Update tos-bsl for win32 python tos-bsl uses the cp210xrt module, whose source is provided herein. This is a simple extension for Python that allows access to the CP210x_WriteLatch function in the CP210xRuntime.dll. The compiled Python extension module is included, as well as the runtime dll and its associated .lib and .h files. The module was compiled using Visual Studio C++ Express 2008, which is apparently the same version of the MSVC used to compile ActivePython 2.7.1 from ActiveState, on which the module was tested. This uses the latest CP210xRuntime.dll and requires a 6.x version of the SiLabs VCP to be installed. Tested with VCP_Windows v6.6.1. The code changes should not change behavior on non-win32 platforms. --- diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntime.lib b/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntime.lib deleted file mode 100644 index e5d4b93a..00000000 Binary files a/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntime.lib and /dev/null differ diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntimeDLL.h b/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntimeDLL.h deleted file mode 100644 index f6fa9a7c..00000000 --- a/tools/platforms/msp430/pybsl/cp210x_rt/CP210xRuntimeDLL.h +++ /dev/null @@ -1,56 +0,0 @@ - -// The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the CP210xRUNTIMEDLL_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// CP210xRUNTIMEDLL_API functions as being imported from a DLL, wheras this DLL sees symbols -// defined with this macro as being exported. -#ifdef CP210xRUNTIMEDLL_EXPORTS -#define CP210xRUNTIMEDLL_API __declspec(dllexport) -#else -#define CP210xRUNTIMEDLL_API __declspec(dllimport) -#endif - -#define CP210x_MAX_SETUP_LENGTH 65536 - -#ifndef _CP210x_STANDARD_DEF_ -#define _CP210x_STANDARD_DEF_ -// GetDeviceVersion() return codes -#define CP210x_CP2101_VERSION 0x01 -#define CP210x_CP2102_VERSION 0x02 -#define CP210x_CP2103_VERSION 0x03 - -// Return codes -#define CP210x_SUCCESS 0x00 -#define CP210x_DEVICE_NOT_FOUND 0xFF -#define CP210x_INVALID_HANDLE 0x01 -#define CP210x_INVALID_PARAMETER 0x02 -#define CP210x_DEVICE_IO_FAILED 0x03 -#define CP210x_FUNCTION_NOT_SUPPORTED 0x04 -#define CP210x_GLOBAL_DATA_ERROR 0x05 -#define CP210x_COMMAND_FAILED 0x08 -#define CP210x_INVALID_ACCESS_TYPE 0x09 - -// Type definitions -typedef int CP210x_STATUS; -#endif /*_CP210x_STANDARD_DEF_*/ - -// Mask and Latch value bit definitions -#define CP210x_GPIO_0 0x01 -#define CP210x_GPIO_1 0x02 -#define CP210x_GPIO_2 0x04 -#define CP210x_GPIO_3 0x08 - -CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI -CP210xRT_ReadLatch( HANDLE cyHandle, - LPBYTE lpbLatch); - -CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI -CP210xRT_WriteLatch( HANDLE cyHandle, - BYTE bMask, - BYTE bLatch); - - -CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI -CP210xRT_GetPartNumber( HANDLE cyHandle, - LPBYTE lpbPartNum); diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/cp210xrtmodule.c b/tools/platforms/msp430/pybsl/cp210x_rt/cp210xrtmodule.c deleted file mode 100644 index 860c03d3..00000000 --- a/tools/platforms/msp430/pybsl/cp210x_rt/cp210xrtmodule.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2010, Titanium Mirror, Inc. - * All rights reserved. - * Based upon work Copyright (c) 2006-2007 by Sporian Microsystems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - Neither the name of the Technische Universität Berlin nor the names - * of its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @author R. Steve McKown - */ - -#include -#include -#include -#include -#include "CP210xRuntimeDLL.h" - -typedef CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI (*fn_t)(HANDLE, BYTE, BYTE); - -void* dll; -fn_t writeLatch; -PyObject* exception; - - -static PyObject* cp210xrt_writeLatch(PyObject* self, PyObject* args) -{ - int fd; - BYTE bMask; - BYTE bData; - HANDLE hDevice; - CP210x_STATUS ret; - - if (!PyArg_ParseTuple(args, "iBB", &fd, &bMask, &bData)) - return NULL; - if (!writeLatch) { - PyErr_SetString(exception, "No access to CP210xRuntime.dll"); - return NULL; - } - - hDevice = (HANDLE)get_osfhandle(fd); - if (hDevice == INVALID_HANDLE_VALUE) - { - PyErr_SetString(exception, "No access to device"); - return NULL; - } - - /* If we don't call writeLatch, then we don't core dump when we return to - * the python caller. If we do call writeLatch, the latches are set, but - * when we return return into python, perhaps the stack has been corrupted - * somehow. We get a stackdump from cygwin. - * - * Note: when we opened the handle here, via CreateFile(), then closed it - * before returning, we had no problems. - */ - ret = writeLatch(hDevice, bMask, bData); - if (ret != CP210x_SUCCESS) { - PyErr_SetString(exception, "IO Error with device"); - return NULL; - } - -#if 1 - Py_INCREF(Py_None); - return Py_None; -#else - return Py_BuildValue("i", ret); -#endif -} - - -static PyMethodDef cp210xrtMethods[] = { - { "writeLatch", cp210xrt_writeLatch, METH_VARARGS, "Set GPIO bits" }, - { NULL, NULL, 0, NULL } -}; - - -PyMODINIT_FUNC initcp210xrt(void) -{ - PyObject* m = Py_InitModule("cp210xrt", cp210xrtMethods); - exception = PyErr_NewException("cp210xrt.error", NULL, NULL); - Py_INCREF(exception); - PyModule_AddObject(m, "error", exception); - - if (!dll) { - dll = dlopen("CP210xRuntime.dll", RTLD_NOW); - if (dll) { - dlerror(); - writeLatch = (fn_t)dlsym(dll, "CP210xRT_WriteLatch"); - if (dlerror()) - writeLatch = NULL; - } - } -} - diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.cygwin-1.5.12-i686.tar.gz b/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.cygwin-1.5.12-i686.tar.gz deleted file mode 100644 index 7c2aa956..00000000 Binary files a/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.cygwin-1.5.12-i686.tar.gz and /dev/null differ diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.tar.gz b/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.tar.gz deleted file mode 100644 index 1f21b920..00000000 Binary files a/tools/platforms/msp430/pybsl/cp210x_rt/dist/cp210xrt-0.1.tar.gz and /dev/null differ diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/setup.py b/tools/platforms/msp430/pybsl/cp210x_rt/setup.py deleted file mode 100644 index 859bc2c5..00000000 --- a/tools/platforms/msp430/pybsl/cp210x_rt/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/python - -from distutils.core import setup, Extension - -module1 = Extension('cp210xrt', sources = ['cp210xrtmodule.c']) - -setup(name = 'cp210xrt', version = '0.1', - description = 'Interface to cp210x runtime dll', - ext_modules = [module1]) - diff --git a/tools/platforms/msp430/pybsl/cp210x_rt/test/reset.py b/tools/platforms/msp430/pybsl/cp210x_rt/test/reset.py deleted file mode 100644 index 3a58b1f9..00000000 --- a/tools/platforms/msp430/pybsl/cp210x_rt/test/reset.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python - -import sys, os, time, serial, cp210xrt; - -sys.stderr.write("os.name is %s\n" % os.name); -sys.stderr.write("sys.platform is %s\n" % sys.platform); - -serialport = serial.Serial(9, 9600, parity = serial.PARITY_EVEN, - timeout = 1000) -sys.stderr.write("using serial port %r\n" % serialport.portstr) -sys.stderr.write("serial port fd is %d\n" % serialport.fd) -#sys.stderr.write("serial port HANDLE is %d\n" % _get_osfhandle(serialport.fd)) - - -sys.stderr.write("clear bit...\n") -cp210xrt.writeLatch(serialport.fd, 0x04, 0x0) -sys.stderr.write("clear bit done\n") -time.sleep(0.250) -sys.stderr.write("set bit...\n") -cp210xrt.writeLatch(serialport.fd, 0x04, 0x04) - diff --git a/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.dll b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.dll new file mode 100755 index 00000000..f4e97a93 Binary files /dev/null and b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.dll differ diff --git a/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.lib b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.lib new file mode 100644 index 00000000..06d891ce Binary files /dev/null and b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntime.lib differ diff --git a/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntimeDLL.h b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntimeDLL.h new file mode 100644 index 00000000..ac6b1581 --- /dev/null +++ b/tools/platforms/msp430/pybsl/cp210xrt/CP210xRuntimeDLL.h @@ -0,0 +1,100 @@ + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the CP210xRUNTIMEDLL_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// CP210xRUNTIMEDLL_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +#ifdef CP210xRUNTIMEDLL_EXPORTS +#define CP210xRUNTIMEDLL_API __declspec(dllexport) +#else +#define CP210xRUNTIMEDLL_API __declspec(dllimport) +#endif + +#ifndef _CP210x_STANDARD_DEF_ +#define _CP210x_STANDARD_DEF_ + +// GetDeviceVersion() return codes +#define CP210x_CP2101_VERSION 0x01 +#define CP210x_CP2102_VERSION 0x02 +#define CP210x_CP2103_VERSION 0x03 +#define CP210x_CP2104_VERSION 0x04 +#define CP210x_CP2105_VERSION 0x05 +#define CP210x_CP2108_VERSION 0x08 + +// Return codes +#define CP210x_SUCCESS 0x00 +#define CP210x_DEVICE_NOT_FOUND 0xFF +#define CP210x_INVALID_HANDLE 0x01 +#define CP210x_INVALID_PARAMETER 0x02 +#define CP210x_DEVICE_IO_FAILED 0x03 +#define CP210x_FUNCTION_NOT_SUPPORTED 0x04 +#define CP210x_GLOBAL_DATA_ERROR 0x05 +#define CP210x_FILE_ERROR 0x06 +#define CP210x_COMMAND_FAILED 0x08 +#define CP210x_INVALID_ACCESS_TYPE 0x09 + +// Type definitions +typedef int CP210x_STATUS; + +// Buffer size limits +#define CP210x_MAX_PRODUCT_STRLEN 126 +#define CP210x_MAX_SERIAL_STRLEN 63 + +// Type definitions +typedef char CP210x_PRODUCT_STRING[CP210x_MAX_PRODUCT_STRLEN]; +typedef char CP210x_SERIAL_STRING[CP210x_MAX_SERIAL_STRLEN]; + +#endif //_CP210x_STANDARD_DEF + +// Mask and Latch value bit definitions +#define CP210x_GPIO_0 0x0001 +#define CP210x_GPIO_1 0x0002 +#define CP210x_GPIO_2 0x0004 +#define CP210x_GPIO_3 0x0008 +#define CP210x_GPIO_4 0x0010 +#define CP210x_GPIO_5 0x0020 +#define CP210x_GPIO_6 0x0040 +#define CP210x_GPIO_7 0x0080 +#define CP210x_GPIO_8 0x0100 +#define CP210x_GPIO_9 0x0200 +#define CP210x_GPIO_10 0x0400 +#define CP210x_GPIO_11 0x0800 +#define CP210x_GPIO_12 0x1000 +#define CP210x_GPIO_13 0x2000 +#define CP210x_GPIO_14 0x4000 +#define CP210x_GPIO_15 0x8000 + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_ReadLatch( HANDLE cyHandle, + LPWORD lpLatch); + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_WriteLatch(HANDLE cyHandle, + WORD mask, + WORD latch); + + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_GetPartNumber(HANDLE cyHandle, + LPBYTE lpbPartNum); + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_GetDeviceProductString(HANDLE cyHandle, + LPVOID lpProduct, + LPBYTE lpbLength, + BOOL bConvertToASCII = TRUE + ); + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_GetDeviceSerialNumber(HANDLE cyHandle, + LPVOID lpSerialNumber, + LPBYTE lpbLength, + BOOL bConvertToASCII = TRUE + ); + +CP210xRUNTIMEDLL_API CP210x_STATUS WINAPI +CP210xRT_GetDeviceInterfaceString(HANDLE cyHandle, + LPVOID lpInterfaceString, + LPBYTE lpbLength, + BOOL bConvertToASCII); diff --git a/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.cpp b/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.cpp new file mode 100644 index 00000000..fae7247a --- /dev/null +++ b/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010-2013, Titanium Mirror, Inc. + * All rights reserved. + * Based upon work Copyright (c) 2006-2007 by Sporian Microsystems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universität Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author R. Steve McKown + */ + +#include "Python.h" +#include "windows.h" +#include +#include "CP210xRuntimeDLL.h" + + +static PyObject* exception; + + +static PyObject* ex_writeLatch(PyObject* self, PyObject* args) +{ + BYTE bMask; + BYTE bData; + HANDLE hDevice; + CP210x_STATUS ret; + + if (!PyArg_ParseTuple(args, "iBB", &hDevice, &bMask, &bData)) + return NULL; + + if (hDevice == INVALID_HANDLE_VALUE) { + PyErr_SetString(exception, "No access to device"); + return NULL; + } + + ret = CP210xRT_WriteLatch(hDevice, bMask, bData); + if (ret != CP210x_SUCCESS) { + PyErr_SetString(exception, "IO Error with device"); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; + //return Py_BuildValue("i", ret); +} + + +static PyMethodDef cp210xrt_methods[] = { + { "writeLatch", ex_writeLatch, METH_VARARGS, "Set GPIO bits" }, + { NULL, NULL } +}; + + +PyMODINIT_FUNC initcp210xrt(void) +{ + PyObject* m = Py_InitModule("cp210xrt", cp210xrt_methods); + exception = PyErr_NewException("cp210xrt.error", NULL, NULL); + Py_INCREF(exception); + PyModule_AddObject(m, "error", exception); +} diff --git a/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.pyd b/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.pyd new file mode 100755 index 00000000..b3f67f71 Binary files /dev/null and b/tools/platforms/msp430/pybsl/cp210xrt/cp210xrt.pyd differ diff --git a/tools/platforms/msp430/pybsl/cp210xrt/setup.py b/tools/platforms/msp430/pybsl/cp210xrt/setup.py new file mode 100644 index 00000000..e92b8712 --- /dev/null +++ b/tools/platforms/msp430/pybsl/cp210xrt/setup.py @@ -0,0 +1,22 @@ +# This is an example of a distutils 'setup' script for the example_nt +# sample. This provides a simpler way of building your extension +# and means you can avoid keeping MSVC solution files etc in source-control. +# It also means it should magically build with all compilers supported by +# python. + +# USAGE: you probably want 'setup.py install' - but execute 'setup.py --help' +# for all the details. + +# NOTE: This is *not* a sample for distutils - it is just the smallest +# script that can build this. See distutils docs for more info. + +from distutils.core import setup, Extension + +cp210xrt_mod = Extension('cp210xrt', sources = ['cp210xrt.cpp'], \ + include_dirs = ['.'], library_dirs = ['.'], libraries = ['CP210xRuntime']) + +setup(name = "cp210xrt", + version = "0.1", + description = "CP210x runtime access", + ext_modules = [cp210xrt_mod], +) diff --git a/tools/platforms/msp430/pybsl/cp210xrt/test/reset.py b/tools/platforms/msp430/pybsl/cp210xrt/test/reset.py new file mode 100644 index 00000000..06bac3ed --- /dev/null +++ b/tools/platforms/msp430/pybsl/cp210xrt/test/reset.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import sys, time, serial, cp210xrt; + +if sys.platform != 'win32': + print 'Sorry, the cp210xrt module only works for Win32 platforms' + sys.exit(1) +elif sys.argc != 2: + print 'usage: %s ' % sys.argv[0] + sys.exit(1) +else: + comport = sys.argvp[1] + print 'Opening %r\n' % comport + serialport = serial.Serial(comport, 9600) + print 'Clear bit...\n' + cp210xrt.writeLatch(serialport.fd, 0x04, 0x0) + time.sleep(0.250) + print 'Set bit...\n' + cp210xrt.writeLatch(serialport.fd, 0x04, 0x04) + print 'Device should now be reset' + diff --git a/tools/platforms/msp430/pybsl/tos-bsl.in b/tools/platforms/msp430/pybsl/tos-bsl.in old mode 100644 new mode 100755 index 4cd94d86..6809e3b6 --- a/tools/platforms/msp430/pybsl/tos-bsl.in +++ b/tools/platforms/msp430/pybsl/tos-bsl.in @@ -116,7 +116,7 @@ # 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__"):