Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Read the (printed ) data from another PC's LPT1 (or) capture the printed data from another PC thru Lpt1

I need to read the data from another PC while it is printing.
Suppose PC 'B' is printing some information thru it's parallel port. By attaching a cable ( db25 ) between PC 'A' <=> pc 'B' (thru LPT1) , will I be able receive the data in pc 'A'. Receiving Computer has got bi-directional Port.

I have found one bi-directional configuration (zstewart@hisys.com) and made a cable. The configuration is ,

       Side 1   Pin     dir     Pin    Side 2   connection
       ------   ---     ---     ---    ------   ----------
        D0       2      <=>*     2      D0      direct
        D1       3      <=>*     3      D1      direct
        D2       4      <=>*     4      D2      direct
        D3       5      <=>*     5      D3      direct
        D4       6      <=>*     6      D4      direct
        D5       7      <=>*     7      D5      direct
        D6       8      <=>*     8      D6      direct
        D7       9      <=>*     9      D7      direct

        C0-      1       =>     13      S4+     inverted
        C1-     14       =>     12      S5+     inverted
        C2+     16       =>     10      S6+     direct
        C3-     17       =>     11      S7-     direct

        S4+     13      <=       1      C0-     inverted
        S5+     12      <=      14      C1-     inverted
        S6+     10      <=      16      C2+     direct
        S7-     11      <=      17      C3-     direct

        Gnd     25      ===     25      Gnd     (ground)

I set C5 to 1 to enable bi-direction.
I wrote a small routine in 'C' to read the data from Data register using 'inportb'. Results are not O.K.

Suppose PC 'B' is printing "THIS IS FOR TEST", it appears in PC 'A' like follows


Sometimes I am loosing some caharacters but moset of the time i am getting repeated cahrs.

Can anyone show me the right direction ?


( Though this question deserves more points I have only 75 points to give, i am new guy.)

1 Solution
Although I cannot help you with you code, I can tell you that the parrallel port is interrupt driver and therefore the data needs to be read from it via interrupts. You need to right a software interrupt handler to be notified when there is data sitting there. If you continously read the data then you are going to get dups. After you read the data you have to tell it that you have the data. I have done this before with a generic token ring project using com ports. My guess is that is similar. Are you writing this for DOS, Windows or Linux?
Why do you need to do this?

It would make more sense to  link the machines on a lan or peer to peer and share the file.

izzathAuthor Commented:
Dear Joeisanerd

I am writing it in DOS. You are right. I have to write an interrupt toutine but i don't know where exactly and how ?

I am reading continuosly from 0x0378 after I set the 5 th bit of 0x37A to 1 ( for bi-directional). What interrup do i have to use ( int 7 )?.

( *** I am assigned to read the data thru LPT1 from Airline Reservation Terminals . I don't have any control over their terminal. All I have got is just to use their LPT1.  So Lan/ peer to peer is not possible ).
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

You will first need to initialize the hardware in code, then install the handler.

To install the handler it is something like this:

void install_handler(void)
   disable();          // no int when change vector
   OldCommHandler = getvect(irq + 8);     // first 8 vectors are system
   setvect(irq + 8,  RxIntHandler);     // save old - install mine
   outportb(IER, RX_INT);               // int on data available
   inportb(LSR);                    // clear line status reg
   inportb(MSR);                    // clear modem status reg
   oldimr = inportb(IMR);               // save old PIC mask
   outportb(IMR, oldimr & IRQ3_MASK);     // allow com2 to int
//   outportb(IMR, oldimr & IRQ4_MASK);     // allow com1 to int
void RestoreSettings()
   setvect(irq + 8, OldCommHandler);     // put back DOS's vector
   outportb(IER, 0x00);
   outportb(IMR, oldimr);               // put back old mask

The actually interrupt handler function is as follows

void interrupt RxIntHandler(...)
   //Your code here to read it.
The ... is necessary

Here is some defines that I had to use so check them out

/* Constant definitions  */
/* COM1 @ 3f8 - COM2 @ 2f8 - COM3 @ 3e8 - COM4 @ 2e8               */
/* COM1 & COM3 irq=4 irqmask=0xef - COM2 & COM4 irq=3 irqmask=0xf7 */
#define BASE          0x02f8          /* COM2 Port Address         */
#define RBR             BASE            /* Rec Buf Register        */
#define THR           BASE          /* Tx  Data Buffer         */
#define     DLL          BASE          /* LSB of Baud-Rate Divisor */
#define     DLM          BASE+1          /* MSB of Baud-Rate Divisor */
#define IER             BASE+1          /* Interrupt Enable Register */
#define IIR             BASE+2          /* Interrupt Ident Register */
#define FCR          BASE+2          /* FIFO Control Register   */
#define LCR          BASE+3          /* Line Control Register   */
#define MCR          BASE+4          /* Modem Control Register  */
#define LSR          BASE+5          /* Line Status Register    */
#define MSR          BASE+6          /* Modem Status Register   */
#define TX_EMPTY        0x20            /* Tx hold register empty  */
#define DTR             0x01            /* Data Terminal Ready     */
#define GO2_DTR_RTS     0x0b            /* Out 2 and DTR RTS on    */
#define DSR             0x20            /* Data Set Ready          */
#define FIFO_ENABLE     0x07            /* FIFO enable & reset     */
#define RX_INT          0x01            /* Rx Data Interrupt       */
#define RX_MODEM        0x09            /* Rx and Modem Status Int */
#define UNLOCK          0x80            /* unlock baud rate divisor */
#define LOCK_SET     0x03          /* 8 Bits with 1 stop-bit  */
#define PIC             0x20            /* Intel 8259 Interrupt ctrl */
#define IMR             0x21            /* Intel 8259 mask reg     */
#define IRQ3_MASK       0xf7            /* unmask comm 2 IRQ3      */
#define IRQ4_MASK       0xef            /* unmask comm 1 IRQ4      */
//#define irq             0x04            /*  comm1 IRQ is 4         */
#define irq             0x03            /*  comm2 IRQ is 3         */
#define BELL            0x07            /*  bell char              */
#define QUIT            0x1b            /*  escape key             */
/* -------------------------------------------------------------------*/

In the project I had to do we used the outportb and inportb to read and write to the port.
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
Dear Izzath,

I have a problem similar to you and I am trying to solve it  using a parallel to serial convertion. I am not sure if it works, but I think it is an easier way to solve this problem.

I really appreciate if you leave you send me an e-mail telling your experience untill now. Maybe we could share some information and solve our common problem.


Carlos Pezzotta

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now