|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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;
}
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > parallel port programming under Unix |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|