954,234 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with parallel port access

I am having trouble when trying to send information through the PC parallel port. I am using the following code to try to send data:

#include
#include
#include

int main(void){
ioperm( 0x378, 1, 1 );
outb( 0x378, 0xAA );
sleep( 2000 );
outb( 0x378, 0x55 );
sleep( 2000 );
outb( 0x378, 0x00 );
return 0;
}

Because it failed (for a reason that I am unaware of) I tried the following program which, I think, is equivalent to the previous one:

#include
#include
#include
#include
#include

int main(void){
const int PORT = 0x378;
int fd = open("/dev/port", O_WRONLY, 0);
unsigned char val;

if( fd < 0 ){
exit(1);
}
lseek(fd, PORT, SEEK_SET);
val = 0x50;
write(fd, &val, sizeof(val));
sleep(2000);
val = 0xA0;
write(fd, &val, sizeof(val));
sleep(2000);
val = 0x00;
write(fd, &val, sizeof(val));
close(fd);
return 0;
}
I'm running the program as the root user, so I have all priveleges. I am verifying the output with a bunch of LEDs that are supposed to turn on when I send a 1. I've already tried a similar code in Windows and it works as expected. Help or suggestions are warmly welcome.

mfierro
Newbie Poster
1 post since Mar 2003
Reputation Points: 10
Solved Threads: 0
 

Hi
I studied your code. It is better that you use

outportb(PORTADDRESS,databyte);
for example outportb(0x378,0x01);
Another mistake i found is sleep() is a function used to suspend the program execution by that much seconds you specify as the arguments.
You wrote sleep(2000); i.e. you are asking the program to hold for 2000 seconds. Instead you use
delay(milliseconds); to control the port.
All the best. If any queries regarding parallel port control in C. please be free to mail me to this ID : [email]muralikvn81@yahoo.com[/email]

I am having trouble when trying to send information through the PC parallel port. I am using the following code to try to send data:

#include #include #include

int main(void){ ioperm( 0x378, 1, 1 ); outb( 0x378, 0xAA ); sleep( 2000 ); outb( 0x378, 0x55 ); sleep( 2000 ); outb( 0x378, 0x00 ); return 0; }

Because it failed (for a reason that I am unaware of) I tried the following program which, I think, is equivalent to the previous one:

#include #include #include #include #include

int main(void){ const int PORT = 0x378; int fd = open("/dev/port", O_WRONLY, 0); unsigned char val;

if( fd < 0 ){ exit(1); } lseek(fd, PORT, SEEK_SET); val = 0x50; write(fd, &val, sizeof(val)); sleep(2000); val = 0xA0; write(fd, &val, sizeof(val)); sleep(2000); val = 0x00; write(fd, &val, sizeof(val)); close(fd); return 0; } I'm running the program as the root user, so I have all priveleges. I am verifying the output with a bunch of LEDs that are supposed to turn on when I send a 1. I've already tried a similar code in Windows and it works as expected. Help or suggestions are warmly welcome.

muralikvn
Newbie Poster
1 post since May 2005
Reputation Points: 10
Solved Threads: 0
 

Hi!

I'm having a similar program. Here is the code I am using -

#define DATA 0x378
void strober()
{
    int c;
    if (ioperm(DATA,3,1))
        fprintf(stderr,"You need to be root!\n");
    for (c=0; c<50; c++){
        fprintf(stdout,"LED should turn on.\n");    fflush(stdout);
        outb(0x07,DATA);
        sleep(t);
        fprintf(stdout,"LED should turn off.\n");   fflush(stdout);
        outb(0x00,DATA);
        sleep(t);
    }
}
int main(){
    strober();
}


The intention is to see a '1' (or 5V) on pins no. 2, 3 and 4 (D0, D1 and D2). However, when I check with the multimeter, the output is always 0V.
I am using pin 25 as the reference for ground.

I checked if the parallel port is working by checking the potential at pin 1. It was +5V.

Thanks
Kedar

PS: I am working on a laptop running Ubuntu. I am using a docking station since there is no parallel port on the laptop itself.

kedarm
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: