Board index » delphi » sending data on LPT port

sending data on LPT port

is there anybody know how to send specified data on LPT port.
 

Re:sending data on LPT port


Quote
B.T. wrote in message <87bi69$io...@as102.tel.hr>...
>is there anybody know how to send specified data on LPT port.

In Windows '95 (and probably Win '98) there is a "cheat" way of writing to
LPT ports. You can use the following assembler code to read and write
directly to the memory address.

function PortIn( IOAddr : WORD ) : BYTE;
begin
  asm
    mov dx,IOAddr
    in  al,dx
    mov result,al
  end;
end;

procedure PortOut( IOAddr : WORD; Data : BYTE );
begin
  asm
    mov  dx,IOAddr
    mov  al,Data
    out  dx,al
  end;
end;

Tha above code will not work for NT, and probably won't work for Win 2000.
The "correct" way to write to parallel ports in Windows is the same as for
serial ports. One should use the API comms functions, something like

CreateFile( "LPT1:", GENERIC_READ or GENERIC_WRITE,
                             0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
0 );

....

WriteFile( FHandle, Block, BlockSize, NumWritten, nil )

...

However I have never seen this implemented successfully! I'd be quite
interested to hear if anyone has managed to do this.

Rob

Other Threads