Click to See Complete Forum and Search --> : Outputting to Parallel Port in Linux


L.I. Surfer
05-13-2003, 04:13 AM
I'm trying to control a small TS-75 Servo motor through the parallel port. I've google all around and I still cannot under stand how to output to the parallel port, I can do it in Assembly 1-2-3 but in C i'm having some hangups. I downloaded the parapin library but the parapin.c file wouldn't compile without errors. I've seen in dos.h using outp(address, data) but what is the deal with outportb(address, data)? Where the hell can I use this function, I have yet to understand where it is. Does a standard library function do the same thing? Basically I wanna do this in pseudo code.

turn on pin 2 and 3 of parallel port
sleep(1);
turn off parallel port
sleep(1);


any ideas??

Cerf
07-02-2004, 01:32 PM
I had the same questions, here is the code I use to control my parallel port to control some LEDs


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

#define BASEPORT 0x378

int main(int argc, char* argv[])
{
ioperm(BASEPORT, 1, 1);

if(argc == 1)
{
for (int i = 0; i < 256; i++)
{
outb(i, BASEPORT);
usleep(1);
}
}else{
for (int i = 1; i < argc - 1; i++)
{
outb(atoi(argv[i]), BASEPORT);
usleep(1);
}

outb(atoi(argv[argc - 1]), BASEPORT);
}


ioperm(BASEPORT, 1, 0);

}