LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   accesssing parallel port error (https://www.linuxquestions.org/questions/programming-9/accesssing-parallel-port-error-502908/)

mzubair 11-19-2006 12:13 AM

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

GNUlancer 11-19-2006 06:37 AM

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.

matthewg42 11-19-2006 07:35 AM

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.

michaelk 11-19-2006 08:19 AM

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

tinieprotonjam 02-09-2007 12:01 AM

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.


All times are GMT -5. The time now is 12:32 PM.