summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2002-09-09 21:56:38 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2002-09-09 21:56:38 +0000
commit8dcdc4766bb1bad883b8cd1ee03ef0c2ad24a5bb (patch)
tree5dcb7123054b3e34fa02ccc1848ca91c201052bc
parent71e69de63f8abf1eb5d0e623f11f66e1ef0a7bc2 (diff)
downloadpyserial-git-8dcdc4766bb1bad883b8cd1ee03ef0c2ad24a5bb.tar.gz
remove loading of giveio (NT/2k/XP) driver within extension.
use loaddrv.exe to load the driver. it stays loaded accross system boots. the batchfiles *_giveio.bat are there to install or remove the driver
-rw-r--r--pyparallel/src/win32/README.txt9
-rw-r--r--pyparallel/src/win32/_pyparallel.c34
-rw-r--r--pyparallel/src/win32/install_giveio.bat15
-rw-r--r--pyparallel/src/win32/loaddrv.c103
-rw-r--r--pyparallel/src/win32/loaddrv.h17
-rw-r--r--pyparallel/src/win32/remove_giveio.bat13
6 files changed, 40 insertions, 151 deletions
diff --git a/pyparallel/src/win32/README.txt b/pyparallel/src/win32/README.txt
index d0b3cc5..b2cb0af 100644
--- a/pyparallel/src/win32/README.txt
+++ b/pyparallel/src/win32/README.txt
@@ -9,9 +9,12 @@ a kernel driver is needed. The sources to GIVEIO.SYS are in
the respective directory. The loaddrv sources come from the
archive that is mentioned in the giveio readme.
-The extension tries to detect if its running on an NT based
-system and activates the giveio driver to gain access to the
-IO ports.
+If the extension detects that it is running on an NT based system
+(NT, 2k, XP) it activates the giveio driver to gain access to the
+IO ports. To make this work, the giveio driver must be installed.
+this can be done with the loaddrv tool. The batchfiles
+"install_giveio.bat" and "remove_giveio.bat" do whats needed to
+install or uninstall.
Thanks go to
Dale Roberts for the giveio driver and to
diff --git a/pyparallel/src/win32/_pyparallel.c b/pyparallel/src/win32/_pyparallel.c
index 7f906c5..6316de0 100644
--- a/pyparallel/src/win32/_pyparallel.c
+++ b/pyparallel/src/win32/_pyparallel.c
@@ -8,10 +8,8 @@
#include <Python.h>
#include <windows.h>
#include <conio.h>
-#include "loaddrv.h"
-#define DRIVERNAME "giveio.sys"
-#define SERVICENAME "giveio"
+#define DRIVERNAME "\\\\.\\giveio"
/* module-functions */
@@ -46,12 +44,10 @@ static PyMethodDef pypar_methods[] = {
/* module entry-point (module-initialization) function */
void init_pyparallel(void) {
- int dwStatus;
- //~ char buf[256];
OSVERSIONINFO vi;
/* Create the module and add the functions */
- PyObject *m = Py_InitModule("_pyparallel", pypar_methods);
+ Py_InitModule("_pyparallel", pypar_methods);
//detect OS, on NT,2k,XP the driver needs to be loaded
vi.dwOSVersionInfoSize = sizeof(vi);
@@ -59,29 +55,11 @@ void init_pyparallel(void) {
if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
HANDLE h;
//try to open driver
- h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ h = CreateFile(DRIVERNAME, GENERIC_READ, 0, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
- //failed, try to load sys file fom disk
- dwStatus = LoadDriverInit(); //init loaddriver module
- //~ printf("init %d\n", dwStatus);
- //driver not running, try to start it
- //~ dwStatus = getcwd(buf, sizeof buf);
- //~ snprintf(buf, sizeof buf, "%s\\%s", buf, SERVICENAME);
- //~ printf("path %d %s %s\n", dwStatus, buf, SERVICENAME);
- //~ dwStatus = DriverInstall(buf, SERVICENAME);
- //install the driver. this returns an error if already installed
- //but who cares?
- dwStatus = DriverInstall(DRIVERNAME, SERVICENAME);
- dwStatus = DriverStart(SERVICENAME);//now start the driver
- LoadDriverCleanup(); //close loaddriver module
- //retry to open the file
- h = CreateFile("\\\\.\\giveio", 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
- PyErr_Format(PyExc_ImportError, "Couldn't access giveio device");
- }
+ //if it fails again, then we have a problem... -> exception
+ PyErr_Format(PyExc_ImportError, "Couldn't access giveio device");
}
//close again immediately.
//the process is now tagged to have the rights it needs,
diff --git a/pyparallel/src/win32/install_giveio.bat b/pyparallel/src/win32/install_giveio.bat
new file mode 100644
index 0000000..3e575d8
--- /dev/null
+++ b/pyparallel/src/win32/install_giveio.bat
@@ -0,0 +1,15 @@
+@set DIRVERNAME=giveio
+
+@echo Installing Windows NT/2k/XP driver: %DIRVERNAME%
+
+@loaddrv install %DIRVERNAME%
+@if errorlevel 3 goto error
+
+@loaddrv start %DIRVERNAME%
+@if errorlevel 1 goto error
+@goto exit
+
+:error
+@echo ERROR: Installation of %DIRVERNAME% failed
+:exit
+@pause
diff --git a/pyparallel/src/win32/loaddrv.c b/pyparallel/src/win32/loaddrv.c
deleted file mode 100644
index 5149877..0000000
--- a/pyparallel/src/win32/loaddrv.c
+++ /dev/null
@@ -1,103 +0,0 @@
-// loaddrv.c - Dynamic driver install/start/stop/remove
-// original by Paula Tomlinson
-
-#include <windows.h>
-#include "loaddrv.h"
-
-SC_HANDLE hSCMan = NULL;
-
-DWORD LoadDriverInit(void) {
- // connect to local service control manager
- if ((hSCMan = OpenSCManager(NULL, NULL,
- SC_MANAGER_ALL_ACCESS)) == NULL) {
- return -1;
- }
- return OKAY;
-}
-
-void LoadDriverCleanup(void) {
- if (hSCMan != NULL) CloseServiceHandle(hSCMan);
-}
-
-DWORD DriverInstall(LPSTR lpPath, LPSTR lpDriver) {
- BOOL dwStatus = OKAY;
- SC_HANDLE hService = NULL;
-
- // add to service control manager's database
- if ((hService = CreateService(hSCMan, lpDriver,
- lpDriver, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
- SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, lpPath,
- NULL, NULL, NULL, NULL, NULL)) == NULL)
- {
- dwStatus = GetLastError();
- } else {
- CloseServiceHandle(hService);
- }
-
- return dwStatus;
-}
-
-DWORD DriverStart(LPSTR lpDriver) {
- BOOL dwStatus = OKAY;
- SC_HANDLE hService = NULL;
-
- // get a handle to the service
- if ((hService = OpenService(hSCMan, lpDriver,
- SERVICE_ALL_ACCESS)) != NULL)
- {
- // start the driver
- if (!StartService(hService, 0, NULL))
- dwStatus = GetLastError();
- } else {
- dwStatus = GetLastError();
- }
-
- if (hService != NULL) {
- CloseServiceHandle(hService);
- }
- return dwStatus;
-}
-
-DWORD DriverStop(LPSTR lpDriver) {
- BOOL dwStatus = OKAY;
- SC_HANDLE hService = NULL;
- SERVICE_STATUS serviceStatus;
-
- // get a handle to the service
- if ((hService = OpenService(hSCMan, lpDriver,
- SERVICE_ALL_ACCESS)) != NULL)
- {
- // stop the driver
- if (!ControlService(hService, SERVICE_CONTROL_STOP,
- &serviceStatus))
- dwStatus = GetLastError();
- } else {
- dwStatus = GetLastError();
- }
-
- if (hService != NULL) {
- CloseServiceHandle(hService);
- }
- return dwStatus;
-}
-
-DWORD DriverRemove(LPSTR lpDriver) {
- BOOL dwStatus = OKAY;
- SC_HANDLE hService = NULL;
-
- // get a handle to the service
- if ((hService = OpenService(hSCMan, lpDriver,
- SERVICE_ALL_ACCESS)) != NULL)
- {
- // remove the driver
- if (!DeleteService(hService))
- dwStatus = GetLastError();
- } else {
- dwStatus = GetLastError();
- }
-
- if (hService != NULL) {
- CloseServiceHandle(hService);
- }
- return dwStatus;
-}
diff --git a/pyparallel/src/win32/loaddrv.h b/pyparallel/src/win32/loaddrv.h
deleted file mode 100644
index 4f874da..0000000
--- a/pyparallel/src/win32/loaddrv.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef LOADDRV_H
-#define LOADDRV_H
-
-#include <windows.h>
-
-#define OKAY 0
-#define UNEXPECTED_ERROR 9999
-
-//prototypes
-DWORD LoadDriverInit(void);
-void LoadDriverCleanup(void);
-DWORD DriverInstall(LPSTR, LPSTR);
-DWORD DriverStart(LPSTR);
-DWORD DriverStop(LPSTR);
-DWORD DriverRemove(LPSTR);
-
-#endif //LOADDRV_H \ No newline at end of file
diff --git a/pyparallel/src/win32/remove_giveio.bat b/pyparallel/src/win32/remove_giveio.bat
new file mode 100644
index 0000000..c75caea
--- /dev/null
+++ b/pyparallel/src/win32/remove_giveio.bat
@@ -0,0 +1,13 @@
+@set DIRVERNAME=giveio
+
+@loaddrv stop %DIRVERNAME%
+@if errorlevel 2 goto error
+
+@loaddrv remove %DIRVERNAME%
+@if errorlevel 1 goto error
+@goto exit
+
+:error
+@echo ERROR: Deinstallation of %DIRVERNAME% failed
+:exit
+@pause