Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

i need read the paralel port or serial port

Posted on 1999-06-28
23
Medium Priority
?
421 Views
Last Modified: 2010-05-18
how can i read the paralel port or serial port?

i have a conmutador conected a printer, these printer print the calls, then i need make a program in delphi that read these calls (in delphi3), can anyone help me?
0
Comment
Question by:jamiguel
[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
  • 9
  • 8
  • 6
23 Comments
 
LVL 15

Accepted Solution

by:
simonet earned 140 total points
ID: 1384976
If you're using Windows 95/98, you could try these functions for port access:

Note: these function use Delphi 2/3 register calling convention and
thus will get the first parameter in eax, the second in edx!

   function PortIn(IOport:word):byte; assembler;
   asm
     mov dx,ax
     in al,dx
   end;

   function PortInW(IOport:word):word; assembler;
   asm
     mov dx,ax
     in ax,dx
   end;

   procedure PortOut(IOport:word; Value:byte); assembler;
   asm
     xchg ax,dx
     out dx,al
   end;

   procedure PortOutW(IOport:word; Value:word); assembler;
   asm
     xchg ax,dx
     out dx,ax
   end;
   
Note that you are talking to a "virtual" port here, not the bare metal.
There is a driver layer between your program and the hardware. So expect
slower performance than you would get on the same hardware under DOS. And
i hope you do not need any millisecond timings for defined responses,
these are hard to get on a multitasking system outside of a device driver.

For Windows NT you need a port driver. One of these may serve:

   TVicHW32             http://www.entechtaiwan.com/tools.htm 
   Tinyport (NT)        
http://www.winsite.com/info/pc/winnt/programr/tinypo20.zip
   DriverX              http://www.tetradyne.com

Yours,

Athena's Place: http://www.bhnet.com.br/~simonet

0
 

Author Comment

by:jamiguel
ID: 1384977
can you explain (or example) of these functions (example of parameters please)
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384978

Ok! Suppose you want to read the byte on the parallel port (port address 0x378), you issue:

var
  x : byte:
begin
  x := portIn($378);

...
end;

That's pretty much what it takes. If you want to read a WORD (2 bytes) rather than a byte, you use PortInW instead of PortIn.

Use the equivalent PortOut functions to write values to the port.

Yours,

Alex
0
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!

 

Author Comment

by:jamiguel
ID: 1384979
ok friend

then when i read the port with portinw in that format rad?

ascii,word,binary...?

NOTE:
I need to prove the code in order to accept your answer
these of agreement?

0
 
LVL 15

Expert Comment

by:simonet
ID: 1384980
That will depend on what the other party is sending.

If the other party is sending BYTES, you should use PortIn. Howeverm if you use PortInW, you'll have the byte value in AL, rather than in AX.

If it's ascii, bcd, decimal, etc, depends on what is being transmitted at the moment.

>ascii,word,binary...?

These are all the same thing, aren't they?

PortIn will return a byte value, which can be a control value or a character. PortInW will return a word, which can be a control word, 2 characters or one double-byte/unicode character.

All the values are binary, because we are dealing with digital computers. Now, if you meant BCD, then it will depend on the other party.

You must know something about the data being transmitted in order to interpret the results accordingly. This depends only on you, not on the functions.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet

0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384981
I've written an program that uses an ECP to transfer files from one computer to another. Program, source, explanation + my email address for further details can you find at: http://www.torry.ru/apps/asystem/fasttransfer.zip

regards,
Lord Xeroth
0
 

Author Comment

by:jamiguel
ID: 1384982
i write these code:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  x:word;
  i:byte;
  y:string;
function portinw(Ioport:word):word;assembler;
asm
  mov dx,ax
  in ax,dx
end;
begin
  for i:=1 to 20 do
  begin
    x:=Portinw($378);
    y:=inttostr(x);
    y:=y;
  end;
end;

in twenty iterations the vairable x always are 33976 why?
i declare the variable y for view the valor of x


0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384983
The parrallel port is not word but byte, you should use al in stead of ax and return a byte in stead of a word.

0
 

Author Comment

by:jamiguel
ID: 1384984
i write these code:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  x:word;
  i:byte;
  y:string;
function portinw(Ioport:word):word;assembler;
asm
  mov dx,ax
  in ax,dx
end;
begin
  for i:=1 to 20 do
  begin
    x:=Portinw($378);
    y:=inttostr(x);
    y:=y;
  end;
end;

in twenty iterations the vairable x always are 33976 why?
i declare the variable y for view the valor of x


0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384985
of course (dumb me), you do 20 iterations at an very high speed. At the moment you're polling the parrallel port in SPP. The data on that port doesn't change in one cycle of your program. On a 486 processor you need to build a loop size 700 (at least) doing nothing between each polling. And are you putting something on that port? Please, do remark my previous comment. DON'T try to read a word, only bytes (some ECP's can handle words, but the ECP uses a 16byte buffer).

0
 

Author Comment

by:jamiguel
ID: 1384986
hi friend lordxeroth:

i discconect the cable of Printer, then i connect these cable to parallel port.

i prove the project fasttran, i select the port 378 then i click in the button Receive, then mark these error:

Project fasttran.exe raised exception class einouterror with message 'i/o error 103'

in edit i type e.txt

in labels:

Filename:
Filesize: 0
Size of Block: 64512
Number of blocks: 0
Block Transfered at Rate:
File Transfered at Rate:
Implementation: 8-bit implementation
Status: 02 ECP timedout, data transfer aborted.

I disconnect these cable of paralell port then i connect these cable to printer (then yes print) why?
 
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384987
Does e.txt excist? This might be a little bug (never tested that one): if you type a non excisting filename, this type of error can occur.
Second the only way the program works is to switch some wires of the cable (like described in the readme file).
Remember that BOTH computers must be in ECP.

0
 

Author Comment

by:jamiguel
ID: 1384988
lordxeroth

remember that i need receive data from a conmutador (i have a conmutador, then it is conecteed to a printer for printer calls), not other computer, i prove this, the error is the same!!! help me please
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384989
jamiguel,

Maybe your parallel port has an unusual configuration and is not configured to use port 0x378. Use the System applet in the control panel to see if your printer is indeed in port 378.

As of the pooling speed, try creating a delay in the loop, because you're reading it too fast. Reading it 20 times in a single loop is not enough to notice a change in the byte being sent.

Another thing: what other process is using the printer port when your program reads the port. Maybe there's no data being sent to the port, and thus, you're program is reading garbage from the port.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384990
The port should be an ECP at 378h or else jamiguel wouldn't get the info he gave about my program.

jamiguel:
it's like I and simonet told: you're poling far too fast.Second, read the port in bytes not in words. What port protocol are you using: SPP, EPP or ECP. You're port is configured to be able to use ECP, but what does it realy use?
I just gave you my program so you could see how it is done, it's just an example not a sollution.
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384991
by the way simonet: I would check you're (very nice) webpage, it contains errors: the slash in the "Delphi for Linux" link is wrong (\ in stead of /)
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384992
by the way: there is a Delphi like project running for Linux, they hope to be ready in 2 to 4 years (forgot the URL, I'll try to look it up again).
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384993
Thanks, lordxeroth. ;)

Alex
0
 

Author Comment

by:jamiguel
ID: 1384994
simonet and lordxeroth:

don't despair, please, together we will achieve it!!!!

i check this:

- protocol using: SPP, EPP or ECP

I have a Server Hpnetserver 5/75.
i go to Properties of My pc and then go to ports, then i chosse Paralel port the properties are:

e/s 378-37B
Int 7

when i probe receibe data from paralel port, the port not have activity (only the data that i receive)
 
i am not sure using Protocol ECP but i check ok?

thanks Friends

0
 
LVL 15

Expert Comment

by:simonet
ID: 1384995
You check out by going to the BIOS configuration onf your PC and checking what mode the parallel mode is configured to use.

Alex
0
 

Author Comment

by:jamiguel
ID: 1384996
hi  lordxeroth: hi probe the project fasttran in a pentium II (with win95), in the bios i indicate the mode of paralel port to a ECP, the adress are: 378-037F

I run the project if in Edit.text i type a name (for example: e.txt) then i click the button Receive, then mark these error (in window with messagedlg--> I/O Error 103) in label of status mark: '02 ECP timed out, data transfer aborted'

if Edit.text = *.* mark these error: (in window with messagedlg--> I/O Error 18) in label of status mark: '02 ECP timed out, data transfer aborted'

what are the problem?
necesary the port has that closed?

(The conmutador never close the port always send data  to port)

I am confused why when i connect the cable again the printer, begin print the data (when the cable was conected to the computer, dont get lost data).

NOTE: the output of conmutador are: Paralel
            the input of PRinter are Serial
           then betwen Conmutador exist a converter Parallel to Serial.
(Conmutador->Cable DB25->Converter Paralel to serial->Printer)

what need check?

Please help me...
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384997
I'm going beserk.
0
 
LVL 1

Expert Comment

by:lordxeroth
ID: 1384998
Fasttransfer is NOT a data-logger, you can't use it for anything else but for transfereing files from one computer to an other.
I'm a bit confused:
what is a conmutador?
what kind of printer are you using?
since you use a parallel to serial converter for your printer (?), it should be in SPP, in that case the answer is given by Simonet
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

721 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