[LIP] problem using parallel port in c

arundeep Singh <arundeep78-/[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
hello all

 i am new member of this group and also new to 
programming in linux. i tried to run this code on 
fedora machine. but it gives me the error. when it 
calls write function with 

portname=/dev/parport0 

Write failed with: Invalid argument

and the following error when portname=/dev/lp0

Write failed with: Resource temporarily unavailable

what is the reason for that. i have ECP configuration 
for the port in my BIOS. 

is there any problem with some configuration or
driver??

Or to send data to port it needs some other functions 
than write.

please help

thanks in advance



#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/signal.h>
#include <linux/lp.h>

extern int errno;

int main( int argc, char **argv )
{
	char *filename, input[5];
	int fd;

	errno = 0;

	if( argc < 2 ) {
		printf("Usage:  a.out /dev/portname\n");
		exit(1);
	}

	printf("Trying to open %s\n", argv[1] );

	fd = open( argv[1] , O_RDWR | O_NONBLOCK );
        if( fd < 0 ) {
		fprintf( stderr, "Open failed with: " );
		goto fail;
	}
	
	if ( write( fd, "hello\n", sizeof( "hello\n" ) ) < 0 
) {
		fprintf( stderr, "Write failed with: " );
		goto fail;
	}

	if ( read( fd, input, 5 ) < 0 ) {
		fprintf( stderr, "Write failed with: " );
		goto fail;
	}

	close( fd );
	exit(0);
fail:
	fprintf( stderr,  strerror( errno ) );
	fprintf( stderr,  "\n" );
	close( fd );
	exit(1);
}

=====
Arundeep Singh,
M.Tech (IS), IIIT Allahabad, 
U.P, India. 
ph: 09415262466, 09417066713
http://www.i-cognition.com

Don't take life seriously, as you can't come out of it alive.

__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.