parallel port output
Just a quick question, how would i get around to outputting data through the parallel port? This is for porting an app i have made in windows. I just need to know the base function, ex: outportb(addr as short, datum as short) equivalent. Thanks.
|
At first you must get parallel port access permissions, so you must use ioperm(), take a look at man 2 ioperm for further information. After that, use outb() and inb() in order to write/read from/to the parallel port.
Usage of outb: outb(port, value); /* for parallel port */ out(0x378, value); Value (1 byte) is written to the data port (pins between 2 and 9). You may also want to use sleep() and usleep() to delay. I hope it helps |
Thanks man, just need to know one more thing, what headers have those functions?
You've helped alot, thanks alot man. BTW, do you know how to read the lpt addresses from the bios? I remember i got that working once but it was a long time ago, sorta better to have them like that then hardcoded. Thanks alot. |
you'll want to use "#include <sys/io.h>" as you'll also probably need access to ioperm() to gain access to the hardware. no idea if it is of interest to you, but certain forms of lpt action might benefit from an external library i used to use called parapin. auomates a lot of stuff for pin switching etc..
|
Nah, i've done all the coding myself, all the functions and shit, all i need is to be able to output to an address a certain data, and be able to port the gui to X11, but i'll figure that out on my own, it's probably just getting used to the equivalent of W32 API. Gonna be my first time coding in linux :P.
|
What you need is to get parallel port access permissions. Look at the following code:
Code:
#include <asm/io.h> |
You must run the code above as root in order to get parallel port access permissions, otherwise ioperm() will fail. You can do away with root permissions once you've called ioperm() by calling seteuid().
|
Thanks alot, ill get to work right away :P.
EDIT: I'm having problems with your code, it compiles perfectly, but nothing happens, i have a little circuit i made myself where it uses LED's to show the status of the parallel port, but they don't change when i run it. When i tried to change the W32 system to Linux in my code, it gets an error along the way, i'll have to look more into that. Do you have any idea of what could be wrong with your code? Or maybe it's my machine... ><. Thanks. |
What do you get exactly while running my code? Do you get an error or so?
|
I get no error, no visible error, it runs smoothly, but i get no parallel port output, i have 8 LED's connected to the data lines and GND of my LPT1 (0x378), but when i run your code and type in any number, it doesn't change, the same 3 are lit, and the rest are dark. I don't know what could be the problem. I think it has something to do with permissions and shit, but i'm not sure.
|
I think it is due to the behaviour of getchar(), since it's providing an ASCII value.
Try this code instead: Code:
#include <asm/io.h> |
Still not working, i think it's a permission problem or something like that. To get this working in windows i had to use a 3rd party driver, must be some way to get around system security or something like that...
|
keep on trying, I am interested in seeing a working solution since I have (not immediate ) plans to port a similar app to Linux myself.
|
Hi
I noticed a small error here. My guess is that your program is segfaulting outb(value, address); so outb(0xFF, 0x378); |
Yeah, the call is defined as outb(value, port), that's why it didn't work!!
|
All times are GMT -5. The time now is 06:41 AM. |