Solved

Switch LPT1 Pin1 on & off

Posted on 2004-08-16
16
759 Views
Last Modified: 2008-02-01
Hi !
I've searched EE and the Web for switching on/off a PIN of LPT1 under W2K. I always found WinIO
and the WinIO unit. Can somebody explain me how to use this thing ? I only want to turn off/on
one pin. This can't be so hard ?? A short function would be nice.

Thanks
Philip
0
Comment
Question by:fuluppi
  • 9
  • 7
16 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
Hi,
you can try with zlportio :
http://www.delphi32.org/vcl/4848/

also :
http://sourceforge.net/projects/tpapro
This is the definite component suite for COM port programming.
Manual and sample programs included.

Regards
Amir
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
LPT port address = 378H  OR 278H
0
 

Author Comment

by:fuluppi
Comment Utility
hi amir !
i already tried zlportio. i have no idea how to use it with the parallell
port. can you post some demo code for winio or zlportio ?

Thanks
Philip
0
 

Author Comment

by:fuluppi
Comment Utility
i guess it works like this:

  SetPortVal(378,0,0);

what must i set to disable and to enable all pins ?
  SetPortVal(378,256,0); for all on and   SetPortVal(378,0,0); for all off ??
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
the zlportio is include a demo to read/wrtite from/to ports,
anyway, this is some codes :

/////////////////////////////////////////////////////////
// for write to port 378H
procedure TMain.Button1Click(Sender: TObject);
var Port,data:dword;
begin
      try
       Port := str2int('378',true); // str2int func. convert a hex value to decimal.
      except
       Port := 0;
      end;
// it'll write 'FF' (HEX) to the 378H ( enable all the data pins ( pins 2-9) )
 zlioportwrite(port,coDataType.itemindex,str2int('FF', true));

// it'll write '01' (HEX) to the 378H ( enable pin 2 and disable pins 3 - 9 )
//  zlioportwrite(port,coDataType.itemindex,str2int('01', true));

end;
/////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////
// for read from port 378H
procedure TMain.Button2Click(Sender: TObject);
var Port,data:dword;
begin
     try
       Port := str2int('378',true); // str2int func. convert a hex value to decimal.
      except
       Port := 0;
      end;

 setthreadpriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL);
 data := zlioportread(Port,coDataType.itemindex);
 setrdata(data);
end;
/////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////
function TMain.str2int(const value:string;const HEX:boolean):integer;
begin // convert a hex value to decimal value
  if HEX then
     result := strtoint('$' + value)
    else
     result := strtoint(value);
end;
/////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////
procedure TMain.setrdata(const Data:dword);
begin // convert an integer value to hex value and show that in an edit box
 erData.Text := inttohex(Data,coDataType.Tag);
end;
/////////////////////////////////////////////////////////
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
Also, not bad to take a look at this link for more details about interfacing the standard parallel port :
http://azhdari.europe.webmatrixhosting.net/parallel.pdf

0
 

Author Comment

by:fuluppi
Comment Utility
hi amir !
nothing changes on the port when i call the functions with zlio ???
0
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 500 total points
Comment Utility
Hi  Fuluppi,
download this project , it work on my pc :
http://azhdari.europe.webmatrixhosting.net/Q_21095463.zip

Let me know if you have problem yet...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:fuluppi
Comment Utility
it works ! thanks a lot ! i found a component which works well, too. but it's not free.
0
 

Author Comment

by:fuluppi
Comment Utility
In my application it doesn't work any longer.  if ZLIOStarted returns false. Any ideas what I do wrong ? Do I need to do something special to start the driver ???

thanks
philip
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
philip, thanks for the points,

Copy file zlportio.sys to your project directory
It should be in the one directory with you application.
0
 

Author Comment

by:fuluppi
Comment Utility
i did that already. still doesn't work.
0
 

Author Comment

by:fuluppi
Comment Utility
i found out the problem. my projects ly on a network drive. it only works on a physical disk. no idea why. this is really strange.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
Hi philip,
I tested that on my client,
you are right, it only works on a physical disk ,not on a network drive,
it's because of the driverinstall func. can't read the driver file from network drive,
so I made some changes to the zlportio.pas file to copy the zlportio.sys to 'C:\' first and then load it from 'C:' instead of
network drive and it work now ,

download the zlportio.pas from here and recompile your project :
http://azhdari.europe.webmatrixhosting.net/zlportio.pas

by the way , don't forget to Copy file zlportio.sys to your project directory
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
Hi philip,
did you test your project on the server ?
Let me know if you have any problem
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now