⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 giaotiep lpt.htm

📁 FM MUDULATION SYSTEM COMUNICATION
💻 HTM
📖 第 1 页 / 共 5 页
字号:
Currently, Parapin only supports a single parallel port at a time. Many new Linux distributions include parport kernel device driver already integrated to the system ready to use. <P>Parapin docmentation is available at <A HREF="http://www.epanorama.net/counter.php?url=http://parapin.sourceforge.net/doc/parapin.html">http://www.epanorama.net/counter.php?url=http://parapin.sourceforge.net/doc/parapin.html</A>. Most of the parapin description give above ade edited form documentation found at that address.<P><H3>Other Linux parallel port controlling software</H3><P><A HREF="http://www.epanorama.net/counter.php?url=http://parashell.sourceforge.net/">Parashell</A> is a program that allows you to control the parallel port (input and output) using simple command line arguments. Due to it's easy interface all you need to know is the parallel port's address (ie., 0x378, 0x3bc, etc.) and a little bit about binary. This software can be found at <A HREF="http://www.epanorama.net/counter.php?url=http://parashell.sourceforge.net/">http://www.epanorama.net/counter.php?url=http://parashell.sourceforge.net/</A>Usage example: <PRE>/usr/local/bin/parashell 0x378 VALUE</PRE>Where value is the numeric value you want to send to parallel port data pins. Parasheel is easy program to use in shell scripts. The software package comes with example shell scripts. Parasheel can also be use to read written pin states:<PRE>/usr/local/bin/pin 0x378</PRE>NOTE: You need to have root right to succesfully run parashell programs. <P>MatPLC is a program that could be worth to check is also. MatPLC is a PLC-like program for Linux (PLC = Programmable Logic Controller), licensed under the GNU GPL. The software can control also PC parallel port. MatPLC home page can be found at <A HREF="http://www.epanorama.net/counter.php?url=http://mat.sourceforge.net/">http://www.epanorama.net/counter.php?url=http://mat.sourceforge.net/</A>. <P><H2><A NAME="webcontrol">Controlling parallel port through web</A></H2><P>It is possible to build a system that allows you to control your parallel port pins through a web. To do this you need the following parts in your Linux system:<P><UL>   <LI>A web server software: <LI><A HREF="http://www.epanorama.net/counter.php?url=http://www.apache.org/">Apache</A> is the most popular, <A HREF="http://www.epanorama.net/counter.php?url=http://www.boa.org/">Boa</A> is also possible   <LI>The conrolling use interface web pages (you have to make those yourself, possible few web forms with control buttons)   <LI>Parallel port controlling CGI-BIN script (you have to write this)   <LI>The control program that control parallel port (the Linux controlling program described above is suitable)</UL><P>Usually web based I/O-device controlling works in the followingway:<UL>  <LI>1. Users downloads a web pages from some page where the web pages is (web browser does this from given addess)  <LI>2. The user web browser shows user the downloaded web page that has the control needed (forms, buttons, etc.)  <LI>3. User presses some control button or send button on form  <LI>4. The user operation at step 3 causes the web browser to send the information (that key has been pressed or form data contents) to the web address given in the web page where this button/form is (can be same or different web server where the form was leaded)  <LI>5. A web server in that given address receives the data from user web browser, checks that it correct and sends in some way command to the actual hardware to do whatever needed (this could be call to hardware driver or signaling to some other application running somewhere accessable from web server)</UL>Typically the web based uder interface building can be divided to two quite differnet parts: The web interface part (getting the controlling information form used to the computer) and the actual hardware controlling<P>The first part would include that web server, controlling webpages and needed scripts to take user controls.There is a wide selection of suitable scripting languages,most attractive for this could be Perl, PHP and UNIX shell script(bash). Al those can be used to do to read the user controls. The second part needs to be generally written using C language,because most scripting languages usually lack the features to do actualdirect hardware controlling. For this C languageis generally the best approach. The idea is tht the actuallow level hardware controlling is done with simple C program,and then the script (on part 1) sends controls to thisC program in some way (in simplest case runs this C programwith right command line arguments every time hardware needs tobe controlled).<P><H3>Simple CGI-BIN controlling example</H3><P>In this example the idea is that you make a web page that has the control buttons what controls you want to do. The control buttons are set so that pressing them causes user web browser to send the form contents to a CGI-BIN script. This call causes the web server to run the specified CGI-BIN script. The CGI-BIN scrips is written to perform the needed controlling, typically calling the parallel port controlling program with right parameters.<P>This is the basic idea how to do this. <P>Here is a simple example web controlling application.Do the following to make it work:<P>1. Make sure that your system is running <a href="http://www.epanorama.net/counter.php?url=http://www.apache.org/">Apache</A> web server. Most modern Linux distributions come already with this web server software. Make sure you have Apache installed. The flllowing steps expect that you run Linux system with correctly configured Apache (Red Hat 7.2 Linux default setting are OK). I epect that the web pages related material is located in /var/www/ directory (this is typical place on Red Hat Linux systems, on other distributions the place can vary, change the examples in this case as needed). Make sure that your web server is running. You can start is it for example with following command (in most systems you need to be root to do this):<PRE>/sbin/service httpd start</PRE>Make sure you can access your Linux computer with your web browser (running on the same or other computer) when Apache is running on the Linux computer.<P>2. Compile the <a href="weblpt/lptout.c">lptout.c</a> source code to lptout binary program, copy the pgoram to /usr/sbin/ directory and set rights so that it is always executed as root. You can do this by logging on as root and executing the following commands:<PRE>gcc -O lptout.c -o lptout.ccp lptout /usr/sbin/lptoutchmod +s /usr/sbin/lptout</PRE>This shoud do this. Now everybody should be able run the command. Test this by logging in as somebody else than root and excute the command:<PRE>/usr/sbin/lptout 0xff</PRE>This should turn on all parallel port LPT1 data pins high (3..5V).Executing command<PRE>/usr/sbin/lptout 0xff</PRE>should turn all output pins low (0..1V). Make sure that this works without problems. Test that the port gets really controlled with this program with a multimeter or the LED circuit decribed in the beginning of this document.<P>3. Install the CGI scripts for parallel port controlling. The need scripts are <A HREF="weblpt/lpton.txt">lpton.cgi</A> and <A HREF="weblpt/lptoff.txt">lptoff.cgi</A>. Click the file names to see the source code, use "view source" if needed, save those files to your system with names lpton.cgi and lptoff.cgi. Then copy those files to the web server CGI-BIN directory and give necessary executing rights.Log in as root and do the following commands on the diectory where you stored the lpton.cgi and lptoff.cgi:<PRE>cp lpton.cgi /var/www/cgi-bin/lpton.cgicp lptoff.cgi /var/www/cgi-bin/lptoff.cgichmod go+rx /var/www/cgi-bin/lpton.cgichmod go+rx /var/www/cgi-bin/lptoff.cgi</PRE><P>4. Install the necessary controlling web page. In this example your controllign webpage resides in the web address http://www.epanorama.net/counter.php?url=http://yourservernamehere/lpt/index.html where the "yourservernamehere" means the name or IP address of your Linux computer you run this application at. You need the web page <A HREF="weblpt/index.txt">index.html</A> source code (click filename to see the source code, use "view source" if needed ,save to your computer as index.html file). To create the web directory for the parallel port controlling do the following when logged as root:<PRE>cd /var/www/html/mkdir lptchmod go+rx lpt</PRE>Now go to the directory where you have the index.html file and copy it to the created directory with following commands (still logged in as root)<PRE>cp index.html /var/www/html/lpt/index.htmlchmod go+r /var/www/html/lpt/index.html</PRE><P>5. Test that you can access the controlling page on the Linux server. Point your web browser to addewss http://www.epanorama.net/counter.php?url=http://yourservernamehere/lpt/index.html where the "yourservernamehere" means the name or IP address of your Linux computer. You should see a controlling page that looks something like this:<IMG SRC="lptweb.gif" ALT="Web browser view of controlling page"><P>6. Test pressing the control buttons and see that the paralle port output pins change their state as controlled. <P>You can find all the necessary files for this simple web project at one tar file called <A HREF="weblpt/weblpt.tar">weblpt.tar</A>. Just download it to your Linux system and expand it to suitable directory with command<PRE>tar xvf weblpt.tar</PRE>Now you have all the files you need. Just do the steps needed with them and you should get your simple web controlling application working well. <P>NOTE: This a simple example of parallel port controlling through web. This example is proably not the most convient or efficent way to do the controlling, but has worked for me. When making electronics that is controlled through web, you need to always think of the information security related to this, meaning that only people whos shoudl be able to do the controlling can do this and nobody can easily hack to your system. This method has potanetial security risks because the lptout program is always run at root rights (if somebody can make it to crash somehow this can potentially cause security problems). To do all the steps mentioned in this document you need to be logged as root to the system to do what is needed, when you are as root, you can do lots of harm to your system if you do stupid mistakes.<P><H3>Parallel port controlling using PHP</H3><P>Here is another source code example for parallel port controlling. This one was sent to me by Andrew Nickson to be included in this web page. This is a php script which will allow the writing of any data to the parallel port. You need to have <A HREF="http://www.epanorama.net/counter.php?url=http://www.apache.org/">Apache</A> web server and a decent version of <A HREF="http://www.epanorama.net/counter.php?url=http://www.php.net/">PHP</A> installed with Apache. Many Linux distributions include those tools if you have selected those to be installed in your system (If you don't have them you need to install them). <P><IMG SRC="lptoutphp.gif" ALT="Picture of controlling web page"><P>There are two files, one the actual php script and the other being the form data used to get the users input.  For this script to work you need to have the same lptout program as used in previous example at your computer at /usr/sbin/ directory with enough right that the web server can run it.<P>Here is the source code of lptout.php / parallel.php:<PRE>&lt;?php/* Program: lptout.php * Desc:    Takes data from the form and sends it to the  *          parallel port program (lptout). *			Values should be given in hex (0 - ff) *          requires lptout placed in /usr/sbin/ *           *	By Andrew Nickson (www.re-mastered.co.uk) */?&gt;&lt;?php  switch (@$_GET['do'])                                 {    case "update":	{		echo ("&lt;center&gt;&lt;br&gt;Data sent to parallel port (0x$fvalue)&lt;/br&gt;&lt;/center&gt;");		exec ("/usr/sbin/lptout 0x$fvalue");		include("parallel.inc");	}	break;                 default:                                                     include("parallel.inc");  }?&gt;</PRE><P><P>Here is the source code of parallel.inc file that is used by the previous source code. This source code prints out the form that is shown to user for parallel port controlling.<PRE>&lt;?php/* Progra

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -