Thread: Another Parallel-Port thread

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    Another Parallel-Port thread

    I know that there are plenty of them already, but none did really help me.
    Thing is, that I just want to set some of the data-lines high/low. I also spent the whole day searching with google, but I didnīt find the info I needed (or as easy as I would have needed).
    So, I found out, that it would be best to use /dev/parport0 because itīs more low-level than lp0.
    So far so good, but I only managed to open and close parport. I just didnīt find out which commands are used just to write binary in it. For example 1010 1010 - to set four data-lines high and four ones low.

    Thats what I think I found out until now:

    Code:
    #include <stdio.h>
    
    int main()
    {
    	int fd;
    	fd = open("/dev/parport0");
    	close(fd);
    	return(0);
    }
    Is that code right? What code line do I have to put in to set some data-lines?

    Hope you can help me and donīt tell me to google or use search - I really tried...And yes I am a beginner...
    Last edited by KeTZer; 10-18-2005 at 07:02 AM.

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    5
    Okay, I figured it out my self, it works like this:

    Code:
    #include <stdio.h>
    #include <linux/parport.h>
    #include <linux/ppdev.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    
    
    int main()
    {
    	int fd;
    	int val;
    	val = 0x81;
    	fd = open("/dev/parport0", O_RDWR);
    		if (fd < 0)
    		{
    		printf("Couldnīt open parport0");
    		}
    	ioctl(fd, PPEXCL);
    	ioctl(fd, PPCLAIM);
    	ioctl(fd, PPWDATA, &val);
    	close(fd);
    	return(0);
    }
    Last edited by KeTZer; 10-20-2005 at 02:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  2. Question on Accessing parallel port
    By Luciferek in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2008, 05:36 PM
  3. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  4. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 12:16 PM
  5. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM