summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2005-01-27 00:47:15 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2005-01-27 00:47:15 +0000
commitc51fc663998d5a408f4c7cf78c36ea9e9ecb517c (patch)
treec064f9a5491a7e296a467d7f461921c54e1dbe90
parentfebcaae53bc9b16486d73daa1de9f5f14306c571 (diff)
downloadpyserial-c51fc663998d5a408f4c7cf78c36ea9e9ecb517c.tar.gz
- windows implementation changed to ctypes + simple dll
- added simpleio.dll, sources git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk@132 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--pyparallel/MANIFEST3
-rw-r--r--pyparallel/README.txt5
-rw-r--r--pyparallel/parallel/parallelwin32.py11
-rw-r--r--pyparallel/setup.py14
-rw-r--r--pyparallel/src/win32/README.txt9
-rw-r--r--pyparallel/src/win32/makefile9
-rw-r--r--pyparallel/src/win32/simpleio.c47
-rw-r--r--pyparallel/src/win32/simpleio.dllbin0 -> 5632 bytes
8 files changed, 85 insertions, 13 deletions
diff --git a/pyparallel/MANIFEST b/pyparallel/MANIFEST
index b392dc3..653a05e 100644
--- a/pyparallel/MANIFEST
+++ b/pyparallel/MANIFEST
@@ -7,6 +7,9 @@ parallel/parallelwin32.py
parallel/parallelppdev.py
examples/test.py
src/win32/_pyparallel.c
+src/win32/simpleio.c
+src/win32/simpleio.dll
+src/win32/makefile
src/win32/README.txt
src/win32/install_giveio.bat
src/win32/remove_giveio.bat
diff --git a/pyparallel/README.txt b/pyparallel/README.txt
index 55c9760..0e180ee 100644
--- a/pyparallel/README.txt
+++ b/pyparallel/README.txt
@@ -10,13 +10,12 @@ possible too but not yet integrated.
This module is still under developement. But it may be useful for
developers.
The windows version needs a compiled extension and the giveio.sys driver
-for Windows NT/2k/XP. The extension module can be compiled with distutils
-with either MSVC or GCC/mingw32.
+for Windows NT/2k/XP. It uses ctypes to access functions in a prebuilt DLL.
It is released under a free software license, see LICENSE.txt for more
details.
-(C) 2001-2003 Chris Liechti cliechti@gmx.net
+(C) 2001-2005 Chris Liechti cliechti@gmx.net
Homepage: http://pyserial.sf.net
diff --git a/pyparallel/parallel/parallelwin32.py b/pyparallel/parallel/parallelwin32.py
index d5d1fc1..5c287cb 100644
--- a/pyparallel/parallel/parallelwin32.py
+++ b/pyparallel/parallel/parallelwin32.py
@@ -50,7 +50,16 @@ LPT2 = 1
LPT1_base = 0x0378
LPT2_base = 0x0278
-import _pyparallel
+import ctypes
+import os
+#need to patch PATH so that the DLL can be found and loaded
+os.environ['PATH'] = os.environ['PATH'] + ';' + os.path.abspath(os.path.dirname(__file__))
+#fake module, names of the functions are the same as in the old _pyparallel
+#python extension in earlier versions of this modules
+_pyparallel = ctypes.windll.simpleio
+#need to initialize giveio on WinNT based systems
+_pyparallel.init()
+
class Parallel:
def __init__(self, port = LPT1):
diff --git a/pyparallel/setup.py b/pyparallel/setup.py
index 929277a..749470c 100644
--- a/pyparallel/setup.py
+++ b/pyparallel/setup.py
@@ -1,24 +1,20 @@
#!/usr/bin/env python
-from distutils.core import setup, Extension
+from distutils.core import setup
import os
if os.name == 'nt':
- ext_modules =[
- Extension('_pyparallel',
- sources=['src/win32/_pyparallel.c'],
- )
- ]
+ data_files = {'parallel': ['simpleio.dll']}
else:
- ext_modules = None
+ data_files = None
setup (name = "pyparallel",
description="Python Parallel Port Extension",
- version="0.1",
+ version="0.2",
author="Chris Liechti",
author_email="cliechti@gmx.net",
url="http://pyserial.sourceforge.net/",
packages=['parallel'],
license="Python",
long_description="Python Parallel Port Extension for Win32, Linux, BSD",
- ext_modules = ext_modules
+ package_data = data_files
)
diff --git a/pyparallel/src/win32/README.txt b/pyparallel/src/win32/README.txt
index b2cb0af..4b6984b 100644
--- a/pyparallel/src/win32/README.txt
+++ b/pyparallel/src/win32/README.txt
@@ -1,3 +1,12 @@
+New:
+simpleio.c provides inp(), outp(), init() these functions are accessed trough
+ctypes.
+
+Build (cygwin/mingw): run "make" the makfile should care of everything.
+
+- - - - - - - - - - - - -
+Old python extension:
+
This extension is needed on Windows as there is no API to
manipulate the parallel port. This Python extension exposes
"inp()" and "outp()" that can be used to manipulate the printer
diff --git a/pyparallel/src/win32/makefile b/pyparallel/src/win32/makefile
new file mode 100644
index 0000000..fad59ee
--- /dev/null
+++ b/pyparallel/src/win32/makefile
@@ -0,0 +1,9 @@
+CFLAGS = -mno-cygwin -mdll -O -Wall
+
+.PHONY: clean FORCE
+
+simpleio.dll: simpleio.o
+ gcc -mno-cygwin -mdll -static -s $^ -Wl,--export-all-symbols,--kill-at -o $@
+
+clean:
+ rm -f simpleio.dll simpleio.o
diff --git a/pyparallel/src/win32/simpleio.c b/pyparallel/src/win32/simpleio.c
new file mode 100644
index 0000000..793cfac
--- /dev/null
+++ b/pyparallel/src/win32/simpleio.c
@@ -0,0 +1,47 @@
+// Parallel port extension for Win32
+// "inp" and "outp" are used to access the parallelport hardware
+// needs giveio.sys driver on NT/2k/XP
+//
+// (C) 2005 Chris Liechti <cliechti@gmx.net>
+// this is distributed under a free software license, see license.txt
+
+#include <windows.h>
+#include <conio.h>
+
+#define DRIVERNAME "\\\\.\\giveio"
+
+/* module-functions */
+
+WINAPI void outp(int port, int value) {
+ _outp(port, value);
+}
+
+WINAPI int inp(int port) {
+ int value;
+ value = _inp(port);
+ return value;
+}
+
+WINAPI int init(void) {
+ OSVERSIONINFO vi;
+
+ //detect OS, on NT,2k,XP the driver needs to be loaded
+ vi.dwOSVersionInfoSize = sizeof(vi);
+ GetVersionEx(&vi);
+ if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+ HANDLE h;
+ //try to open driver
+ h = CreateFile(DRIVERNAME, GENERIC_READ, 0, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ //if it fails again, then we have a problem... -> exception
+ //"Couldn't access giveio device";
+ return 1;
+ }
+ //close again immediately.
+ //the process is now tagged to have the rights it needs,
+ //the giveio driver remembers that
+ if (h != NULL) CloseHandle(h); //close the driver's file
+ }
+ return 0;
+}
diff --git a/pyparallel/src/win32/simpleio.dll b/pyparallel/src/win32/simpleio.dll
new file mode 100644
index 0000000..df480ac
--- /dev/null
+++ b/pyparallel/src/win32/simpleio.dll
Binary files differ