Link to home
Start Free TrialLog in
Avatar of jamiguel
jamiguel

asked on

i need read the paralel port or serial port

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?
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jamiguel
jamiguel

ASKER

can you explain (or example) of these functions (example of parameters please)

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

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

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


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.

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


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

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

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
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
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.
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 /)
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).
Thanks, lordxeroth. ;)

Alex
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

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

Alex
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...
I'm going beserk.
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