Solved

printer port control..

Posted on 1999-01-27
10
216 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
[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
  • 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
Technology Partners: 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!

 
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

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

Suggested Solutions

Title # Comments Views Activity
Passing a array as parameter - C 2 103
Line meaning 9 90
nested if statement in excel help 4 40
If a cell in a range equals "YES" return specific Test. 4 42
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…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

763 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