Results 1 to 2 of 2
This is a C code written for windows to help identify the address of a parallel port:
Code:
/*detect.c*/
/*This piece of code determines if the PC has any parallel ...
- 04-01-2007 #1Just Joined!
- Join Date
- Dec 2003
- Posts
- 41
Can someone please help me port this C code?
This is a C code written for windows to help identify the address of a parallel port:
I am well aware than this wont work on linux becuase we use things such as ioperm() to get port access and inb() and outb() to read and write data.Code:/*detect.c*/ /*This piece of code determines if the PC has any parallel adapter*/ /*If yes, it finds out and prints the addresses of the DATA, CONTROL */ /*and the STATUS ports*/ #include <stdio.h> #include <dos.h> main() { int dport, cport, sport, select, offset; clrscr(); /*clear screen*/ printf("\tProgram to detect the parallel printer adapter.\n"); printf("Enter 1, 2 or 3 to detect LPT1, LPT2 or LPT3 respectively.\n\n"); /*wait for a keystroke*/ select=getch(); /*loop indefinitely if the key pressed is not '1', '2' or '3'*/ while ( (select != '1') && (select != '2') && (select != '3') ) { printf("Invalid number. Enter 1, 2 or 3\n"); select=getch(); } if(select =='1') offset = 0x08; if (select =='2') offset = 0x0a; if (select =='3') offset = 0x0c; /*now look into BIOS area to determine the address of the particular*/ /*parallel adapter*/ dport=peek(0x40, offset); /*If the address is zero, means that particular parallel adapter*/ /*is not present. No point in continuing. Abort the code here*/ if (dport == 0) { printf("Sorry, On this machine LPT%d does not exist\n", select-'0'); exit(0); } /*else print the port addresses of the DATA, STATUS and CONTROL ports*/ printf("\nLPT%d detected!\n", select -'0'); printf("DATA port is %x\n", dport); printf("STATUS port is %x\n", dport+1); printf("CONTROL port is %x\n", dport+2); }
Can someone translate this code to linux C? I am also unaware as to why those offset values where chosen.
--thanks.
- 04-01-2007 #2Just Joined!
- Join Date
- May 2005
- Posts
- 22
Please read the HOWTO about IOPerm (chapter 2):
http://tldp.org/HOWTO/IO-Port-Programming.html


Reply With Quote