LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   putc problem - LED flashing (https://www.linuxquestions.org/questions/programming-9/putc-problem-led-flashing-171755/)

vasanthraghavan 04-18-2004 04:51 PM

putc problem - LED flashing
 
Hi,
My attempt at interfacing LEDs to parallel port:
Hooked up the parallel port to a bunch of LEDs.
Wrote a driver to flash the LEDs.
Compilation went fine.

The following piece of code works:

if (ioperm(base,1,1))
{
printf("Error: Couldn't get the port at %x\n", base);
exit(1);
}

for (i = 0; i <= 7; i++)
{
value = pow(2, i);
outb((unsigned char)value, base);
sleep(1);
}
Result: LEDs work as expected.

However if you replace the code with the following piece of code, it does not work:

FILE *stdprn;
stdprn = fopen("/dev/lpt0", "w"); /*My parallel port is port number 0 */

for (i = 0; i <= 7; i++)
{
value = pow(2, i);
putc(value, stdprn);
sleep(1);
}
LEDs don't flash at all for this piece of code.
Is there something wrong in calling putc or does it have anything to do with changing
the terminal to buffered/unbuffered i/o?
Any suggestion or direction would be great.

Thank you.

itsme86 04-19-2004 09:58 AM

I really have no idea, but there haven't been any replies so I thought I'd give you something! :)

Have you tried to fflush(stdprn); after putc(value, stdprn);?

I don't know. Would be interesting to hear how/if you get it to work.

kolargol 04-19-2004 10:24 AM

I think the first parallel port is /dev/lp0 not /dev/lpt0

vasanthraghavan 04-19-2004 04:46 PM

Thank you very much. Following the hint by kolargol and itsme86, the LEDs now work correctly! Both the changes were needed.


All times are GMT -5. The time now is 06:01 PM.