Thread: LPT: Need help to READ and WRITE to port

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    2

    LPT: Need help to READ and WRITE to port

    Hi all,

    I want to hook some instrumentation to the LPT1: port, control and read its status through this port. However, my compiler (VC++ 6.0) on a Windows XP machine does not recognize 'inportb' or 'outportb' (used in some very old instructions). Here is the basic elements of that code and what I'm attempting to do;

    Code:
    #include <stdio.h>
    #include <dos.h>
    
    void main(void)
    {
      int val; 
      val=inportb(0x378);       //readport
       outportb(0x378,0x0F);    //write to port
      val=inportb(0x378);       //read again. should be 0F 
      printf("%x \n",val);
    }
    Is there some other funciton that I should be using ?

    Does someone have a snip of code I could use ?

    Thanks

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I'm not sure if it's possible to do that with Windows XP at all. You might wanna search the board for inportb and outportb.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    yes, use fopen("prn","w") to create a file pointer to the printer. You can then use all the regular file output functions like fwrite().

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    2
    Thanks Draco !

    That has got me started. I was able to produce output !
    Now I need to figure out the input bytes and status bytes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  2. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. read from and write to serial port
    By wazilian in forum Networking/Device Communication
    Replies: 3
    Last Post: 04-25-2004, 08:22 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM