Solved

printer port control..

Posted on 1999-01-27
10
213 Views
Last Modified: 2010-05-18
How can I read data from printer port ?

If the setting is ..
LPT1(0x378)..

And How can I write data ?

It's hurry,,...

Thank U !
0
Comment
Question by:can9999
  • 7
  • 3
10 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1258463
Let's say you want to write a byte to the port..here is how to do it...

typedef unsigned char byte;

void WriteToPort(byte MyByte)
{
  asm {
    mov dl, 378h
    mov al, [MyByte]
    out dl, al
  }
}

to get data you can do something like this...

byte GetPort()
{
  byte tmp;
  asm {
    mov dl, 378h
    in al, dl
    mov [tmp], al
  }
  return tmp;
}

Hope this helps...

-Viktor
--Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1258464
also you can use

outp() and outport()

e.g.

outp(0x378, MyData);

outport(0x378, MyData);

There are other functions that I can look up for you if you need them and are similar to these two i just gave you...

The code I sent above was in assembler so you can use it if oyu want, but I think these two functions are easier to use...

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:can9999
ID: 1258465
In your code...

you only read from printer port 0x378.

Is there a anything to initial for reading port ?

What is SPP and .. ?

outp(0x37a, 0x20);
^ some people says above line for reading..

Had you trid it ?

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1258466
oh for reading use

MyData = inp(0x378);

and for writing use

outp(0x378, MyData);

Hope this helps...

-Viktor
--Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1258467
Why did you give me a C? What's wrong with what I said?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 10

Expert Comment

by:viktornet
ID: 1258468
I gave you all the needed info... What more do you want?

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:can9999
ID: 1258469
nothing..

that's enough !

thank U everybody..


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1258470
What do you mean? I was asking you why you gave me so low grade when I gave you all the needed info?!?!
0
 
LVL 1

Author Comment

by:can9999
ID: 1258471
OK !
I'll explain everything..... ^-^

There are several modes for parallel port operating (EPP, BI-DIR, SPP.... etc)
- I don't know what those mean, besides SPP and BI-DIR.

It' is impossible to read data from DATA BUS(d0~d7) of printer port...with using the method what you said alone....

Some steps remain.

1. Set Printer Mode BI-DIR or SPP....
2. Outp(0x37a, 0x20)    <- this command means " I'll read DATA from now "
3. and then READ !
   tmpData = Inp(0x378)

4. If you want to write data,
   Outp(0x37a, 0x00)   <- " I'll write DATA from now "

That's all....


Bye !




 


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1258472
i just think it wasn't appropriate...
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now