Link to home
Start Free TrialLog in
Avatar of Dennis9
Dennis9

asked on

LPT Port ?

Hi.

I need to read bits from my printer port.
I use DLPORTIO.dll to write the bits.

Now i need to read the bits that are active.

Eg if i write: 1001110

Then i want to be able to close my prog, and read the current status of the port, and actually get back the: 1001110

If u use the read button in the demo, it gets back the value in hex, and i need to get it back the other way.

Can anyone help?

Thanks
Avatar of alanwhincup
alanwhincup

If you can get the value back in hex then you can convert the hex value back to its binary form with a function like below:

function HexToBin(Hex : string) : string;
const
  BCD : array [0..15] of string = ('0000', '0001', '0010', '0011', '0100',
    '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101',
    '1110', '1111');
var
  I : integer;
begin
  for I := Length(Hex) downto 1 do
    Result := BCD[StrToInt('$' + Hex[I])] + Result;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(HexToBin('4E'));
end;

Cheers,

Alan
Avatar of Dennis9

ASKER

its 8 bit result i want eg: 10101101
I've downloaded and had a quick look at the DLPORTIO.dll and assume you are using the following function to interface between your prog and the driver to read an 8 bit result (or a byte):

function DlPortReadPortUchar(Port : LongInt) : Byte; stdcall;

As this returns a byte then you can convert straight from a byte to its binary form with the function IntToBin() which is implemented in the IdGlobal unit.
ASKER CERTIFIED SOLUTION
Avatar of Dennis9
Dennis9

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
Dennis9:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Dennis9,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Accept alanwhincup's answer http:#7139232 and Refund

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer