[ubuntu-it] [OT] =>Re: asm/io.h -- Piccola aggiunta che può servire a qualcuno

Franco Minucci ingframin a yahoo.it
Gio 6 Mar 2008 10:13:18 GMT


Per comunicare con una porta seriale/parallela è abbastanza facile,
riporto uno spezzone di codice C che ho trovato su internet e che spero possa fare comodo a qualcuno.
Non ricordo il sito esatto, (NON SONO IO L'AUTORE) io l'ho solo modificato leggermente per testarne il funzionamento e vi assicuro che funziona perfettamente :-)
Divertitevi!

/*
 * example.c: very simple example of port I/O
 *
 * This code does nothing useful, just a port write, a pause,
 * and a port read. Compile with `gcc -O2 -o example example.c',
 * and run as root with `./example'.
 */

#include <stdio.h>
#include <unistd.h>
#include </usr/include/sys/io.h>

#define BASEPORT 0x378 /* lp1 */

int main()
{
    setuid(0);
  /* Get access to the ports */
  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
  
  /* Set the data signals (D0-7) of the port to all low (0) */
  outb(2, BASEPORT);
  
  /* Sleep for a while (100 ms) */
  usleep(100000);
  
  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n", inb(BASEPORT/* + 1*/));

  /* We don't need the ports anymore */
  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}

  exit(0);
}
/* end of example.c */
 






      Inviato da Yahoo! Mail.
La web mail più usata al mondo. http://it.docs.yahoo.com/mail/overview/index.html




Maggiori informazioni sulla lista ubuntu-it