#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    3
    Rep Power
    0

    parallel port programming under Unix


    Hello there,

    I'm having trouble finding decent resources to learn about interfacing electronics through my printer port. Almost all of the docs I find are for DOS/Windows or Linux. The system I need to run on is OpenBSD 3.0. Is anyone here familiar with this environment? Does anyone know of some good links for unix LPT communication? Thanks for the help!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,594
    Rep Power
    4207
    Found some code on the web, which works on NetBSD and supposedly on OpenBSD as well. Hope this helps.

    Code:
    First you need to allow access to the port for your process.  First, you need to enable the port, then just use outb(port, char) to talk to it.
    
    For example:
    
    /* pioexample.c         Example of using PIO to talk to an I/O port
     *
     * Little ditty to count bits on the parallel port output register.
     */
    
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/syscall.h>
    #include <machine/sysarch.h>
    #include <machine/pio.h>
    
    /* ioport(port)         permit access to an I/O port.
     * port                 I/O address to enable
     */
    void
    ioport(int port) {
            u_long iomap[32];
            struct i386_set_ioperm_args ioperm;
     
            ioperm.iomap = iomap;
            syscall(SYS_sysarch, I386_GET_IOPERM, (char *) &ioperm);
            iomap[port >> 5] &= ~(1 << (port & 0x1f));
            syscall(SYS_sysarch, I386_SET_IOPERM, (char *) &ioperm);
    }
    
    int
    main() {
            int i;
            ioport(0x378);                  /* Enable access to the port */
            for(i = 0; i < 256; i++) {
                    outb(0x378, i);         /* Set the output register   */
                    sleep(1);               /* Sleep a tick              */
            }
            return 0;
    }

IMN logo majestic logo threadwatch logo seochat tools logo