LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 11-19-2006, 12:13 AM   #1
mzubair
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Rep: Reputation: 0
accesssing parallel port error


hi to all
I want to access parallel port using fedora core 4 and gcc 4.0.0 .
In window operating system we use dos.h for accessing parallel port
but gcc compiler show error for this file.please tell me what header file i should use for this purpose also tell me how can i get complete information about using gcc compiler and how can i check header files for its functions,is there any gui interface available for gcc compiler.
thanks
 
Old 11-19-2006, 06:37 AM   #2
GNUlancer
Member
 
Registered: Oct 2006
Location: Russia
Distribution: Slax KillBill
Posts: 59

Rep: Reputation: 15
As i know you can access nearly any hardware only by using appropriate device files (located under /dev). Find out what is your port's file and try to simply write to it.
 
Old 11-19-2006, 07:35 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Method 1: Look in /dev for anything with lpn, where n is a digit, e.g.
Code:
/dev/lp0
If you're using udev on your system I believe only devices which exist should have nodes in /dev.

Method 2: Check in dmesg:
Code:
dmesg |grep parport |grep ' lp'
(be aware that dmesg outputs a ring buffer, and boot-time messages like the parport one might get flushed from this buffer if there is a lot of post-boot dmesg activity (e.g. plugging USB devices))

Method3: Have a poke about in the /proc and /sys filesystems. I'm not quite sure how to get the device filename from this, but it's possible to get the IO base address and such.
 
Old 11-19-2006, 08:19 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
I assume that you are wanting to program the parallel port and not just attach a printer.

http://parapin.sourceforge.net/
http://tldp.org/HOWTO/IO-Port-Programming.html
 
Old 02-09-2007, 12:01 AM   #5
tinieprotonjam
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Rep: Reputation: 15
Question

Quote:
Originally Posted by michaelk
in the link above, it was mentioned that parallel port programming can also be done in c++. I saving the sample code as a c++ file and compiled it, but I get some errors, I did not change anything of the sample code (see below)
Code:
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>

#define BASEPORT 0x378 /* lp1 */

int main()
{
  /* Get access to the ports */
  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
  
  /* Set the data signals (D0-7) of the port to all low (0) */
  outb(0, BASEPORT);
  
  /* Sleep for a while (100 ms) */
  usleep(100000);
  
  /* Read from the status port (BASE+1) and display the result */
  printf("status: %d\n", inb(BASEPORT + 1));

  /* We don't need the ports anymore */
  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}

  exit(0);
}
the error messages that I get from the compiler are:

port.cpp: In function `int main()':
port.cpp:18: error: `ioperm' undeclared (first use this function)
port.cpp:18: error: (Each undeclared identifier is reported only once for each
function it appears in.)
port.cpp:18: error: `exit' undeclared (first use this function)


Is there something that I missed? I hope someone can help me out, since I really need to do a the parallel port interfacing program in c++. Thank you in advance.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel port isra SUSE / openSUSE 1 10-03-2006 08:22 AM
parallel port mehro Linux - Hardware 5 01-31-2006 06:43 AM
What's using my parallel port?! DiBosco Linux - Hardware 10 06-20-2004 10:18 AM
Cannot use parallel port under 2.6.4 jimbob1234 Slackware 2 03-14-2004 08:34 PM
Parallel Port CD-RW dbrook42 Linux - Hardware 3 09-30-2003 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration