1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include <QCoreApplication>
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <sys/io.h>
#define BASEPORT 0x378 /* lp1 */
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ioperm(0x300,3,1);
/* Obtention de l'accès aux ports */
if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
/* Initialisation de tous les signaux de données (D0-D7) à l'état bas (0) */
outb(0, BASEPORT);
/* Dormons pendant un moment (100 ms) */
usleep(100000);
/* Lecture sur le port d'état (BASE+1) et affichage du résultat */
cout << inb(BASEPORT + 1);
cout << endl;
/* Nous n'avons plus besoin de l'accès aux ports */
if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
return a.exec();
} |
Partager