Hello

I need to work out some parallel port output signals.

I found a short program to test bits on that port.
It tells I need to set the permission with ioperm() as this:

#include <asm/io.h>
#include <iostream>
#include <cstdlib>
#include <unistd.h>

#define base 0x378           /* printer port base address */
#define value 255            /* numeric value to send to printer port */

using namespace std;

main(int argc, char **argv)
{
   if (ioperm(base,1,1))
    fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

   outb(value, base);
}

but when i try to compile it reports error:
`ioperm' undeclared (first use this function)

help pls.

Dani AI

Generated

Good catch from — switching the include to <sys/io.h> is the reason the compile error disappeared. A few follow‑up points and troubleshooting steps that often save time when moving from “it compiles” to “the pins actually toggle” on Linux systems.

  • ioperm needs elevated rights (CAP_SYS_RAWIO / root). It returns 0 on success and -1 on error (check errno / use perror); release access when finished with ioperm(base, 1, 0). See the manual for details: ioperm(2) man page.

  • Common reasons the port still won’t behave as expected:

    • The kernel parallel‑port driver owns the I/O region. Check and free it:

      lsmod | grep parport
      cat /proc/ioports | grep 378
      sudo rmmod parport_pc lp parport
    • BIOS/board settings change base addresses or put the port into ECP/EPP mode; verify the port base (0x378 is common) with dmesg | grep -i parport or lspci -v.

    • On SMP/modern kernels, direct user I/O can conflict with the kernel — prefer a kernel‑mediated interface when possible.

  • Safer alternative: use the ppdev interface (/dev/parport0) or a library such as libieee1284 so the kernel mediates access (no raw port fiddling, fewer root/security issues). See: .

Final cautions: running code that touches hardware bypasses kernel protection — only do this on controlled hardware and ensure the kernel driver is not simultaneously manipulating the port. Also note ’s point: these are Linux/x86 techniques, not a Windows solution.

Recommended Answers

All 4 Replies

What operating system are you using? That is a and not supported in MS-Windows. But if you are using linux then I don't know the answer because I don't have a linux computer available to me where I am at.

I am using slackware linux 10.2.

Try replacing #include <asm/io.h> to #include <sys/io.h> and tell me what you get.

Great, no error

Now I check the real output on pins.

Thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.