LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-18-2004, 03:51 PM   #1
vasanthraghavan
Member
 
Registered: Mar 2004
Location: USA
Distribution: Redhat Linux 9
Posts: 98

Rep: Reputation: 15
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.
 
Old 04-19-2004, 08:58 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 56
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.
 
Old 04-19-2004, 09:24 AM   #3
kolargol
LQ Newbie
 
Registered: Jan 2003
Posts: 18

Rep: Reputation: 0
I think the first parallel port is /dev/lp0 not /dev/lpt0
 
Old 04-19-2004, 03:46 PM   #4
vasanthraghavan
Member
 
Registered: Mar 2004
Location: USA
Distribution: Redhat Linux 9
Posts: 98

Original Poster
Rep: Reputation: 15
Thank you very much. Following the hint by kolargol and itsme86, the LEDs now work correctly! Both the changes were needed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome Terminal Backspace Screen flashing problem! e_liming Linux - Software 4 11-23-2009 08:21 AM
CD RW LED keeps flashing arubin Linux - Hardware 1 11-17-2005 03:54 PM
Flashing SL-5500 = LED lights flash endlessly Zeiph Linux - Laptop and Netbook 1 05-02-2005 06:15 AM
putc and fputc - and other confusion Linh Programming 8 07-21-2003 06:54 AM
putchar and putc are not working .... purpleburple Programming 4 07-04-2002 03:28 PM


All times are GMT -5. The time now is 08:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration