Problem mit Daten vom Parallelport
-
Hallo!
Weil ich vorhabe ein kleines PC-Link Programm zu schreiben, das den Parallelport nutzt, habe ich ein wenig gegoogelt und die inpout32.dll (http://www.logix4u.net/inpout32.htm)gefunden. Wenn ich aber mein Testprogramm starte, wird mir immer ein bestimmter Wert ausgegeben, obwohl nichts an dem Port angeschlossen ist. Hier der wohl entscheidende Programmteil:
short port::Inp32(short i) { return (inp32fp)(i); //die unveränderte Funktion aus der DLL } int port::read_all() { data=0; for (address=pportBase; (address<(pportBase+8)); address++)//pportBase = 0x378 data+=Inp32(address); return data; }Mir fällt da kein großer Fehler auf. Im Hauptprogramm wird dann nur read_all() in einer Schleife ausgeführt und der Wert - auf meinem XP-Rechner 1851, auf dem Win 98-Notebook 1853 - ausgegeben.
Weil ich nicht weiß, ob das normal ist, oder ob ich sonstige Verständnisprobleme habe, habe ich jetzt nicht den ganzen Quelltext eingefügt. Wenn es aber nötig sein sollte, werde ich es natürlich nachholen.
Kann und will mir jemand helfen?
-
Hallo,
hier ist der ganze Quelltext:Header:
#ifndef PORT_HEADER #define PORT_HEADER #include <conio.h> #include <windows.h> #include <iostream> using namespace std; typedef short (_stdcall *inpfuncPtr)(short portaddr); typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); class port{ private: short data; int address; int pportBase; inpfuncPtr inp32fp; oupfuncPtr oup32fp; HINSTANCE hLib; short Inp32(short i); void Out32(short i, short x); public: port(short portadress); ~port(); int read(short portnr); int read_all(); bool write(short data); }; #endifImplementation der Klasse:
#include "port.hpp" port::port(short portaddress) { pportBase=portaddress; inp32fp = NULL; oup32fp = NULL; hLib = LoadLibrary("inpout32.dll"); if(hLib == NULL) { cerr<<"Hard Error: Couldn't load library."<<endl; exit(1); } inp32fp = reinterpret_cast<inpfuncPtr>(GetProcAddress(hLib, "Inp32")); if(inp32fp == NULL) { cerr<<"Hard Error: Couldn't get ProcAddress for Inp32."<<endl; exit(0); } oup32fp = reinterpret_cast<oupfuncPtr>(GetProcAddress(hLib, "Out32")); if(oup32fp == NULL) { cerr<<"Hard Error: Couldn't get ProcAddress for Out32."<<endl; exit(0); } } short port::Inp32(short i) { return (inp32fp)(i); } void port::Out32(short i, short x) { (oup32fp)(i, x); } port::~port() { FreeLibrary(hLib); } int port::read(short portnr) { if(portnr<0 || portnr>7) return -1; data=Inp32(pportBase+portnr); return data; } int port::read_all() { data=0; for (address=pportBase; (address<(pportBase+8)); address++) data+=Inp32(address); return data; } bool port::write(short data) { Out32(pportBase, data); if(data!=Inp32(pportBase)) return false; return true; }main:
#include <iostream> #include <ctime> #include "port.hpp" int main() { port parallel(0x378); short message; time_t start, end; cout<<"Starte Suche nach angeschlossenem PC"<<endl; start = time(NULL); end = start + 10; while(time(NULL)<end){ message=parallel.read_all(); cout<<"Daten empfangen: "<<message<<endl; } }Der Port sendet nach wie vor 1800 oder 1851.
Habe ich etwa die Hardware geschrottet?Grüße,
kynarion