sitemap link mailform link home

devC++ Konsolenprogramm

Ansteuerung des Parallelports mit einem einfachen C++-Konsolen-Programm

Verwendet wurde als Entwicklungsumgebung DevC++ bzw. wxDevC++.

Als DLL findet die sehr beliebte Dowmload inpout32.dll Verwendung. Diese muss sich auch im Projekt-Verzeichnis bzw. im gleichen Ordner wie die compilierte exe-Datei befinden.

ACHTUNG: Geht nur mit Windows XP / NICHT mit Windows 7

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
//-------------------------------------------------------------------------
typedef short _stdcall (*inpfuncPtr)(short portaddr);
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);

void lib_laden();
void set_pin(int Pin);
void lib_schliessen();

HINSTANCE hLib;
inpfuncPtr inp32;
oupfuncPtr oup32;
short x;
int i = 0x378;
//-------------------------------------------------------------------------
void lib_laden ()
{
hLib = LoadLibrary("inpout32.dll");

inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (hLib == NULL || inp32 == NULL || oup32 == NULL) {/*** ERROR ***/}
}
void set_pin(int Pin)
{
switch (Pin)
{
case 0: (oup32)(i,0x0); break;
case 1: (oup32)(i,0x1); break;
case 2: (oup32)(i,0x2); break;
case 3: (oup32)(i,0x4); break;
case 4: (oup32)(i,0x8); break;
case 5: (oup32)(i,0x10); break;
case 6: (oup32)(i,0x20); break;
case 7: (oup32)(i,0x40); break;
case 8: (oup32)(i,0x80); break;
}
}
void lib_schliessen()
{
FreeLibrary(hLib);
}

int main(int argc, char *argv[])
{
 
   int pin = 0;
 
    lib_laden();
    int i=0;
    int j=0;
   
    for(i=0; i<20000; i++){
                 for(j=0; j<8; j++){
                          set_pin(j+1);
                          Sleep(100);
                          }
                 }
   
    lib_schliessen();
 
    return 0;
 
}

 

Die LEDs am Parallelport sollten lauflichtartig blinken.

.

Letzte Änderung:
March 23. 2023 21:04:40
«    top    »