Cerf
05-31-2004, 05:19 PM
Yo yo yo
I made a program in C++ to controll the parallel port (I finally got it right).
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#define BASEPORT 0x378 /* lp1 */
int main()
{
/* Get access to the ports */
if (ioperm(BASEPORT, 3, 1))
{
perror("ioperm");
}
for (int i = 0; i < 256; i++)
{
outb(i, BASEPORT);
usleep(10000);
}
/* 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");
}
}
When I run the program as root the program works fine, when not as root, I have a problem.
[Cerf@localhost parallelport]$ ./parallelport
ioperm: Operation not permitted
Segmentation fault
[Cerf@localhost parallelport]$ su
Password:
[root@localhost parallelport]# ./parallelport
[root@localhost parallelport]#
I made a program in C++ to controll the parallel port (I finally got it right).
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#define BASEPORT 0x378 /* lp1 */
int main()
{
/* Get access to the ports */
if (ioperm(BASEPORT, 3, 1))
{
perror("ioperm");
}
for (int i = 0; i < 256; i++)
{
outb(i, BASEPORT);
usleep(10000);
}
/* 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");
}
}
When I run the program as root the program works fine, when not as root, I have a problem.
[Cerf@localhost parallelport]$ ./parallelport
ioperm: Operation not permitted
Segmentation fault
[Cerf@localhost parallelport]$ su
Password:
[root@localhost parallelport]# ./parallelport
[root@localhost parallelport]#