Solved

printer port control..

Posted on 1999-01-27
10
212 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

762 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