
 Port control software for Linux

  Version 0.3

  Copyright Tomi Engdahl 1996-2005

  

 Introduction

This software package provides access to PC computer hardware 
I/O ports under Linux operating system. 

This softare package is designed to run on Linux system that 
runs on normal PC hardware. The software has been tested to 
run nicely on Fedora Core 4 Linux distribution. 
You need GCC to compile the programs. 

This package provides the following tools:

lptout       simple program to control LPT1 printer port data pins
portcontrol  general use I/O port reading and writing application
control.php  AJAX/PHP based web interface for parallel port controlling

The software are provided with no guarantee of their correctness.
Use them at your own risk.


 Compiling

Run:
make install

 Installing

Log in as root.
Run:
make install 

The software is now installed to /usr/local/sbin/ directory
 
 Using lptout

The user has to have the root previledges to have access to the ports 
for the program to run. For this reason the the program is installed 
with SUID ROOT settings, meaning that every time the program is run 
it is automatically run at root previledges no matter who runs it. 
This program is designed to access LPT1 parallel port at I/O address 
0x378 (normal address for parallel port integrated to motherboard)

For example command
/usr/local/sbin/lptout 0xFF 
will turn all data pins in LPT1 port to high state (1).
Command
/usr/local/sbin/lptout 0x00 
will turn all data pins to to low state (0).


 Using portcontrol

portconrol is a simple general purpose I/O port control program for 
Linux. It allows you to write and read the supported I/O ports. 
The software allows writing specified value to port, reading 
value at given I/O address and printing it out to screen in 
different formats and bit-level manipulation of the port data.


Examples

/usr/local/sbin/portcontrol LPT1DATA read setbit 1 write 
Reads parallel port data, set bit D1 to 1 and writes value back
Effectively sets the LPT1 pin D1 in parallel port to logic 1

/usr/local/sbin/portcontrol LPT1DATA read resetbit
Reads parallel port data, set bit D1 to 0 and writes value back
Effectively sets the LPT1 pin D1 in parallel port to logic 0

/usr/local/sbin/portcontrol LPT1DATA setvalue 0xff write
Writes value 0xff (255 dec) to the parallel port
Effectively sets all LPT1 data pins to logic 1

/usr/local/sbin/portcontrol LPT1DATA read print bin
Reads the parallel port data pin states and prints 
the results as binary numbers to the screen (standard output).

/usr/local/sbin/portcontrol LPT1DATA read print bin
Reads the parallel port data pin states and prints
the results as binary numbers to the screen (standard output).

/usr/local/sbin/portcontrol LPT1DATA read printbits 021
Reads the parallel port data pin states and prints
the states of bits D0, D2 and D1 in that order to the 
screen (standard output).



Supported port identifiers
   LPT1DATA         LPT1 port data lines controlling (0x378)
   LPT1STATUS       LPT1 printer status inputs register
   LPT1HANDSHAKE    LPT1 handstake output controlling 
   JOYSTICK         Joystick port reading (only reading makes sense)

Supported commands
  PRINT DEC       Read data, gives output as decimal number
  PRINT HEX       Read data, gives output as hexadecimal number
  PRINT BIN       Read data, gives output as binary number
  PRINTBITS bits  Reads the specified bits in the specified order (0..7)

  WRITE           Writes register value to port
  READ            Reads value from specified port to register

  SETVALUE value  Sets the given value to register
  AND value       Performs AND with given value and register
  OR value        Performs OR with given value and register
  XOR value       Performs XOR with given value and register
  SETBITS bits    Sets given bits to 1 in register 
  RESETBITS bits  Sets given bits to 0 in register
  SETBIT bits     same as SETBITS
  RESETBIT bits   same as RESETBITS 
  TOGGLEBITS bits Toggles specified bit values

value can be gives as decimal number or heaxadecimal starting with 0x
bits is a list of bit position identifiers from 0 to 7

Port names are ment to be written at high case. 
Commands at low case. 


  Using web interface

The web interface for controlling paralle port is simple 
modern web based interface for controlling parallel port. 
To make it you need to have the following parts in your system:
- Apache web server with PHP5 support working with it
- portcontrol software installed to the default install directory
- SAJAX Simple Ajax Toolkit by ModernMethod
- Modern web browser that supports JavaScript (IE6, Mozilla Firefox) 

Installing the web interface is simple. All you need is
to copy the control.php file to a suitable place
on your web directory you want it to be copy the Sajax.php 
file from the SAJAX package to the same directory where you 
have the control.php. 

Then just go to the URL where you have that control.php 
accessable. You should see status line plus a set 
of control buttons. The status bar shoudl automatically update 
every 5 seconds with the parallel port status and current 
time on the server computer. 
Pressing the buttons will change the parallel port bit states. 

Note that on some systems the PHP script might hot have 
enough rights to run the portconrol software. 
Check your access rights to make sure that rights are correct
(the system did not work on my Fedora Core 4 system when 
I had SELinux security enabled). 

SAJAX Simple Ajax Toolkit by ModernMethod can be downloaded from 
http://www.modernmethod.com/sajax/

NOTE: There is an another version of the control.php file available. 
This file controlfile.php work pretty much in the same way, but 
instead of controlling parallel port writes and reads the status 
from a file (status.txt in the same directory as the script is). 
It can be used to test the AJAX/PHP based control system.
