Parallel port controlling using PHP

Parallel port controlling using PHP

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 Apache web server and a decent version of PHP 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).

Picture of controlling web page

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.

Here is the source code of lptout.php / parallel.php:

<?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)
 */

?>

<?php

  switch (@$_GET['do'])                               
  {

    case "update":
	{
		echo ("<center><br>Data sent to parallel port (0x$fvalue)</br></center>");

		exec ("/usr/sbin/lptout 0x$fvalue");
		include("parallel.inc");
	}
	break;             

    default:                                             
        include("parallel.inc");
  }
?>

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.

<?php
/* Program: Parallel.inc
 * Desc:    Contains the form data for the parallel control
 *          This will call parallel.php.
 *         
 *	By Andrew Nickson 2005 (www.re-mastered.co.uk)
 */

?>

<html>
<head><title>Parallel Port Controller</title></head>
<body topmargin="0" leftmargin="0" marginheight="0"
      marginwidth="0">
         <center><form action="parallel.php?do=update" method="POST"> 
         <table border="0">
          <tr><td align=right><b>Value (HEX)</b></td>
             <td><input type="text" name="fvalue" 
                      size="5" maxsize="3">
             </td></tr>
                <br><input type="submit" name="Update" 
                           value="Update">
               </td></tr>
         </table>
</body></html>

You can donwload the download those source codes as one zipped packet with file name lptoutphp.zip. I used PHP4 when I wrote this source code years ago.

Programming I/O

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: