Solved

printer port control..

Posted on 1999-01-27
10
214 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
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.

813 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

16 Experts available now in Live!

Get 1:1 Help Now