www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/09/00:48:05

From: "Richard Hasty" <rhasty AT io DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Help: read/write from printer port
Date: 9 Jan 1998 05:44:19 GMT
Organization: Illuminati Online
Lines: 50
Message-ID: <01bd1cc1$d4914d00$ab51e0ce@rhasty>
NNTP-Posting-Host: as4-dialup-33.wc-aus.io.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm brand new to DJGPP and I'm trying to write stuff to the printer port.
I'm running Win95 if that has anything to do with it.  I was thinking I'd
be able to just use "open" and pretend I was writing to a file called LPT1
or PRN. It does not work as I would have expected though.  The code (only a
few lines) is at the end of the message. It bombs on the write operation. 

Is there a better way of doing it?  I was thinking of trying to just write
to the correct memory address.
I have an old copy of Turbo C v 1.01 and I tried
poke(0x000,0x0378,1);
but that didn't work either.  If I tried that under plain old dos would it
work?  Do I even have the right address for the parallel port?
Can I do something equivalent using DJGPP?

I would love to stop asking these questions.  Are there any documents,
books or any other resources for learning about how to do this kind of
thing?  Also, any reccomendations for the beginner in assembly and writing
TSR programs and using interrupts?  

Many thanks for any assistance,

Richard Hasty
rhasty AT io DOT com

#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <conio.h>

int main(void)
{
   int handle;
	int value=1;

        if ((handle = open("PRN", O_WRONLY, 0)) < 0 )
	{
		perror("Error: Cannot open lpt1");
		return 1;
	}
        if(write(handle, &value, 1) != 1)
        {
                printf("write_error");
                return 1;
        }

   close(handle);
   return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019