Hi!
Get the parallel port address seems to be a hard work! :)
No valid informations can be found in internet...
I am playing now with WMI and its capabilities: http://msdn.microsoft.com/
I am newie managing Com, automation and this kind of things, but I made a code that's be able to enumerate the Parallel ports availlables and its starting addresses.
With the same mechanism, we can also know the port capabilities (normal, ecp, epp, etc)
The class of our interest is called:
Win32_ParallelPort URL: http://msdn.microsoft.com/
With this class, we can enumerate the ports and its data.
There is a problem... the property called 'Capabilities' of this class is an array:
Capabilities
Data type: uint16 array
and... I dont know yet how read this type of data from a Delphi app...
I have an open question for this work:
http://www.experts-exchang
but... without answer yet.
Well... here is the code:
- Add ComObj, ActiveX to the uses line
- Put a TMemo (Memo1)
- Put a TButton and paste this code in its OnCLick event:
procedure TForm1.Button1Click(Sender
type
TParPort = record
Name : string;
PnpDeviceId : string;
StartingAddress : string;
end;
TParPorts = array of TParPort;
procedure EnumerateParallelPorts(var
//uses ComObj, ActiveX
var
oCosas,
oCosa : OleVariant;
services : OleVariant;
n : integer;
iTemp : longword;
sTemp : string;
oEnum : IEnumvariant;
function GetObject(Value: String): OleVariant;
var pUnk: IUnknown;
pDisp: IDispatch;
pmk: IMoniker;
pbc: IBindCtx;
cbEaten: LongInt;
clsid: TGUID;
begin
// Resource protection
try
// Attempt to convert the string using the registry
clsid:=ProgIDToClassID(Val
// Check running object table
if (GetActiveObject(clsid, nil, pUnk) = S_OK) then
begin
// Return result as IDispatch
result:=pUnk as IDispatch;
// Release the refcount that we are holding on to
pUnk:=nil;
end
else
// Failed
result:=Unassigned;
except
// Try to access the object using a moniker
if (CreateBindCtx(0, pbc) = S_OK) then
begin
if (MkParseDisplayName(pbc, StringToOleStr(Value), cbEaten, pmk) = S_OK) then
begin
// Attempt to bind the moniker
if (BindMoniker(pmk, 0, IDispatch, pDisp) = S_OK) then
// Return the IDispatch
result:=pDisp
else
// Return unassigned
result:=Unassigned;
// Release refcounts
pDisp:=nil;
pmk:=nil;
end
else
// Return unassigned
result:=Unassigned;
// Release refcounts
pbc:=nil;
end
else
// Return unassigned
result:=Unassigned;
end;
end;
begin
services:=GetObject('winmg
oCosas:=Services.ExecQuery
oEnum := IUnknown(oCosas._NewEnum) as IEnumVariant;
//Get name & PNPDeviceId of the ports
while oEnum.Next(1,oCosa,iTemp) = 0 do begin
if High(PortList)<iTemp then SetLength(PortList,iTemp);
with PortList[High(PortList)] do begin
Name :=oCosa.Caption;
PnpDeviceId :=oCosa.PNPDeviceId;
end;
oCosa:=Unassigned;
end;
oCosas := Unassigned;
//Enum PnPAllocatedResources looking for the parallel ports address
oCosas:=Services.ExecQuery
oEnum := IUnknown(oCosas._NewEnum) as IEnumVariant;
while oEnum.Next(1,oCosa,iTemp) = 0 do begin
//Asociate the resource to the found ports and get the address
for n:=0 to High(PortList) do begin
sTemp:=StringReplace(PortL
if Pos(sTemp,oCosa.Dependent)
sTemp:=oCosa.Antecedent;
sTemp:=Copy(sTemp,Succ(Pos
sTemp:=Copy(sTemp,1,Pred(L
PortList[n].StartingAddres
end;
end;
oCosa:=Unassigned;
end;
oCosas := Unassigned;
Services:=Unassigned;
end;
var
Ports : TParPorts;
n : integer;
begin
EnumerateParallelPorts(Por
//Show the captured data in a Memo:
Memo1.Lines.Clear;
for n:=0 to High(Ports) do begin
With Ports[n] do begin
Memo1.Lines.Add( Format('Port Name: %s, Address: %s',[Name,StartingAddress]
end;
end;
end;
Main Topics
Browse All Topics





by: JohnjcesPosted on 2005-08-30 at 08:43:51ID: 14785889
I have had similar difficulty in some of my past parallel port projects. There was one thing I did that helped a great deal. I am somehow assuming that your software manipulates a hardware device connected to the printer port. If you read the port with your device attached, do you get some return value that is unique? With it disconnected you should just get a big 0. Can you set set one of the upper addresses on your device so that your software can see a 'signature'.
/edit/coun t.cfm?ID=1 720
What I mean is, in one of my projects, I tied bit 7 and 8 of the printer port high via a 1K resistor as I only used the first five bits. I could then read a decimal 192 and knew my device was there. I would simply read all possible standard printer port addresses and set the one that had my simple "signature"
As far as knowing if the port is ECP, etc, the only thing I found was MiTec System Information which will advise of a parallel port being ECP etc. I just downloaded the recent version and ran a couple of demos and it just showed that my one and only port was ECP. It did not tell me what its address was but then I just did a quick check. You can download this from
http://www.delphipages.com
Hope this helped you a bit. Good luck.