?
Solved

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

Posted on 2003-03-08
7
Medium Priority
?
321 Views
Last Modified: 2006-11-17
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

"TTTTTTHHHHHHISS FFFFFFFFOOOOOOORRRR  TTTTTTEEEEESSSST".

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

Can anyone show me the right direction ?

Thanks

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








0
Comment
Question by:izzath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 8095843
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?
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8096002
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.

mlmcc
0
 

Author Comment

by:izzath
ID: 8096996
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 ).
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 9

Accepted Solution

by:
Joeisanerd earned 300 total points
ID: 8097760
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
   enable();
}
//************************************
void RestoreSettings()
{
   disable();
   setvect(irq + 8, OldCommHandler);     // put back DOS's vector
   outportb(IER, 0x00);
   outportb(IMR, oldimr);               // put back old mask
   enable();
}

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.
0
 

Expert Comment

by:CleanupPing
ID: 9447262
izzath:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Expert Comment

by:Pezzotta
ID: 9487535
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.

Buy.

Carlos Pezzotta
carlos@pezzotta.com
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question