Click to See Complete Forum and Search --> : IOPort programm


edpuchta
01-19-2003, 05:08 PM
hello!
I am with a doubt, when sending a byte for the parallel port the byte is in the bolts only some microseconds, but when I go to read way software I read only buffer(and the byte is there).
The documentation I caught of www.linuxdoc.org


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

#define base 0x378 /* printer port base address */

void setbite(int valor)
{
while(ab != 1)
{
outb(valor,base);

}
}
void main(void)
{
if(ioperm(base,1,1))
{
fprintf(stderr, "Error: Couldn't get the port at %x\n", base), exit(1);
}
printf("digite um valor: ");
scanf("%d", &valor);
setbite(valor);
usleep(500000); //500ms

}
What I want to make is that when sending the byte it is in the port.
what I can make to function?

bwkaz
01-19-2003, 07:06 PM
"the byte is in the bolts"

Ummm, what? Sorry, but I can't parse that sentence...

If you're asking how to send data out the parallel port, simply write it to the /dev/lp0 device. That way, you can do it as any user rather than having to check ioperm().

ChryZKoiD
01-19-2003, 07:40 PM
If you want a more low level control over the parallell port, use this function:

outb(data, address);
ie: outb(0x01, 0x378); // write 0x01 to Lpt1

I used this to program software for an lcd-display I hooked up to it.

You also need this, to gain access to the memory area:
ioperm(portAddress, 3, 1);

And to release it after use:
ioperm(portAddress, 3, 0);

:D

edpuchta
01-19-2003, 10:53 PM
hello, i was mistake when i say "bolt". I liked say pin,
you are certain, I you want to send a byte lp0 but as I make to send (/dev/lp0)? it will be that it can teach to me?

bwkaz
01-20-2003, 10:50 AM
You can send a byte to /dev/lp0 like this:

int fd = open("/dev/lp0", 0);
char buf[48]; // this size can be anything, as long as it's big enough to hold your strcpy string + 1

strcpy(buf, "string to output; can be a single character too");

write(fd, buf, strlen(buf));