LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices

Reply
 
LinkBack Search this Thread
Old 01-24-2003, 06:40 AM   #1
Robert0380
Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 46
Parallel port pin access


Any one know how to access individual pins on the parallel port in Linux and what the voltage levels are? If I find something before someone replies I'll post again.
 
Old 01-24-2003, 07:00 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,835

Rep: Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118
the pins run at 5v, most of them with a very low current though, so are only useful for data, not power (you can gang together a big bunch pins (say the output port) and power a small IC if you really want.

it's pretty easy to set individual pins, but the last time i did it was 1 year ago for my degree project (a fully functional oscilloscope capture engine).

i found the "parapin" wrappers useful for a lot of interaction and that's also a good enough bit of source code to read through (it's easy enough to translate to C++ if need be)

one of my key resources was the BEyond Logic site, has shedloads of info (although mainly for win32 programming.. but it's very similar at register level. just need a different c library)

http://www.beyondlogic.org/index.html
 
Old 01-24-2003, 10:22 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 9,916

Rep: Reputation: 338Reputation: 338Reputation: 338Reputation: 338
Here is some code where the data lines lit some led lamps.


/* meter.c by Joseph W. Vigneau (joev@wpi.edu) (c)1994.
This program is covered under the GNU copyleft agreement.
*/

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include "port.h"

float loadavg(void)
{
FILE *f;
char line[80];
float cpu = 0.0, totalcpu = 0.0;

if((f = popen("/bin/ps -aux","r"))==NULL) {
fprintf(stderr,"Couldn't fork /bin/ps.\n");
exit(1);
}

fgets(line, 80, f);
while(!feof(f)) {
sscanf(line,"%*s %*d %f",&cpu);
totalcpu += cpu;
fgets(line, 80, f);
}
/* printf("TOTAL: %f\n",totalcpu); */
pclose(f);
return totalcpu/100.0;
}


main()
{
unsigned char lights;
float ave;
char dir = 0;
char foo[10];
register unsigned char numlights, i;

if(ioperm(0x378,1,1)) {
fprintf(stderr,"ioperm error.\n");
exit(1);
}

while(1) {
ave = loadavg();
numlights = (int)(ave*8.0);
/* printf("ave = %f, numlights = %d\n",ave, numlights); */

lights = 0;
for(i=0;i<numlights;i++)
lights |= (1<<i);

port_out(0x378, lights);
usleep(750000L);
}
}

This program has to be suid root, due to the ioperm call.
 
Old 01-24-2003, 10:41 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,835

Rep: Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118
not a great example really, there's a lot of excess junk there, and appears to actually use an additional bit of code to set the lines (from the ports.h include statement) to set the lines you'll want to get familiar with the outb command
 
Old 07-29-2003, 03:25 PM   #5
CroftonTom
LQ Newbie
 
Registered: Aug 2001
Location: New Jersey
Distribution: Red Hat
Posts: 6

Rep: Reputation: 0
I am running something much simpler that I'm sure you've seen before (lptout) but my problem I have is that it works on my laptop, but on my desktop, I get a segmentation fault. Anyone have any idea how to fix this?
 
Old 07-29-2003, 04:11 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,835

Rep: Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118Reputation: 1118
please don't drag up unlrelated threads. i'd suggest you create a new thread in Programming, and add a lot more information, e.g. gdb backtraces etc...
 
  


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
alternate methods of parallel port access bobbens Programming 9 10-25-2005 08:47 AM
Why the STROBE pin in parallel port?? arunshivanandan Linux - General 3 09-01-2004 08:28 AM
Allow program to access parallel port LongName Linux - Newbie 5 08-27-2004 06:08 PM
urgent help please (parallel port access) yahya Programming 1 08-12-2002 12:36 PM
urgent help please ( parallel port access) yahya Linux - Software 1 08-12-2002 12:32 PM


All times are GMT -5. The time now is 12:26 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
Open Source Consulting | Domain Registration