Paralel port interupts programs
This can become a hassle regularly. As the hardware does all the work, this handshake only requires to be used for your hardware and not for software as the case with SPP. Details on this, latter. The EPP Port also has a new set of registers. However 3 of them have been inherited from the Standard Parallel Port. Below is a table showing the new and existing registers.
As you can see, the first 3 addresses are exactly the same than the Standard Parallel Port Register and behave in exactly the same way. Your device can signal a read request via the use of the interrupt and have your ISR perform the Read Operation. The Status Port has one little modification. This bit will be set when an EPP time-out occurs. The port never gets an acknowledgment nWait , thus keeps sending requests for wait states, and your computer locks up. Therefore the EPP implements a type of watchdog, which times out after approximately 10uS.
The Parallel Port can only transport 8 bits at a time, thus any 32 or 16 bit word written to the Parallel Port will be split into byte size blocks and sent via the Parallel Port's 8 data lines. Some ports require you to set this up before starting any EPP Cycle.
Therefore our first task is to manually initialise these lines using the SPP Registers. Writing XXXX to the control port will do this. So you can use the C example above in Windows 3. Direct port controlling from application is not possible under Windows NT and to be ale to control the parallel port directly you will need to write some kind of device driver to do this. You can find also this kind of drivers from Parallel Port Central and Inpout Kemo relay module M is designed for switching up to 8 different appliances, lamps or motors according to a computer program up to 40V and loads up to 0,4A DC or 0,2A AC.
The module is operated at the printer port LPT1 in the same way as my parallel port controlling circuit examples in this module there is one solid state relay connected for each of those 8 data output pin on parallel port. Kemo M kit information page has control software available for download. Those software allows controlling of outputs manually and timed operation.
There is also programming C source code example available. The software is written using Visual Basic and Euphoria programming languages and comes with source code. VBPortTest parallel port utility is designed to help test and debug parallel port interfaces.
Allows access to the three registers data, status, and control associated with the PC standard parallel port SPP. The user can read and write the data and control registers. The program continually reads the status register the status register is read-only. Individual register bits are displayed on LEDs along with the hex value for the entire data register.
In write mode, the user can toggle individual bits by clicking on the corresponding LED. Hex values can be entered on the keyboard. Bit, byte and strobed byte write modes are possible.
Online Help with useful parallel port reference material includes signal descriptions and Centronics handshake timing waveform. VBPortTest is available for download as freeware. Windows 98, ME, and XP compatible. The second link was a very nice, step by step guide as to how to do things. It is not designed for contrlling single pins on or off. Using the parallel port for digital output can be made to work with the normal Windows API with a simple hardware hack.
The main trick is to tie pins 11 Busy and 12 Paper Error to ground. Otherwise, the hardware driver will think the printer it is talking to is busy or experiencing an error and will not output any data. Just send one character to parallel port, and the Windows wii send the value of that character to printer port data pins, plus generate one pulse to strobe line.
The port will maintain the last value written to it until another value is written or until the computer is powered down or new data is sent to port. If you output more than one byte at a time the driver will send them to the port in sequence and toggle the Strobe line line 1 off and on for each byte. The timing involved varies somewhat from one computer to the next. This means that in a Windows environment we can output data to the parallel port.
You can send data even through Windows command line with copy command like this: copy somefile. The value of the last byte in the file will be left as the state of the parallel port after the command execution. Besides need for the hardware hack, there are other limitations on the Windows API method. Windows API does not have built in support for input operations nor reading back the last sent value.
Even though the parallel port hardware supports it, the software driver does not. Parallel port controlling in Linux Linux will allow acess to any port using the ioperm syscall. If you want to make a program which can be run by anybody then you have to first set the owner of the program to be root for example do compilation when yhou are root , give the users rights to execute the program and then set the program to be always executed with owner root rights instead of the right of the user who runs it.
If you want a more useful program, then download my lptout. That program works so that you can give the data to send to parallel port as the command line argument both decimal and hexadecimal numbers supported to that program and it will then output that value to parallel port. You can compile the source code to lptout command using the following line to do the compilation: gcc -O lptout.
For example running. In this case you need to modify the address in define base line. There are different ways to know the port address. First you could try your graphical configuration tools to look for this information. Those tools and how to use them vary quite much between different Linux distributions. This list should include your parallel port or parallel ports in it.
The first parallel port port in motherboard typically has name parport0. There are some cases where you might not see your device in your list or sometimes you see the sama name twice usually the first one is the right one.
In many new Linux systems you can run "lspci -v more" to get information of each device on your PCI bus this should tell make and model, interrupt and port and memory block assignments.
I have also written a more feature rich program to control. The portcontrol software is available as portcontrol. My simple parallel port control GUI is written in such way that it allows you to control parallel port pins. To see what it looks check the screenshot.
The program is intended to be a simple example that you can modify for your own uses. Just download menu. The routines there are inline macros, so it is enough to include ; you do not need any additional libraries.
Because of a limitation in gcc, you have to compile any source code that uses these routines with optimisation turned on gcc -O1 or higher , or alternatively use define extern static before you include remember to undef externafterwards. For debugging, you can use gcc -g -O at least with modern versions of gcc , though optimisation can sometimes make the debugger behave a bit strangely.
Before you access any ports, you must give your program permission to do so. This is done by calling the ioperm function declared in unistd. The ioperm call requires your program to have root privileges; thus you need to either run it as the root user, or make it setuid root. You are not required to explicitly drop your port access privileges with ioperm You can drop the root privileges after you have called ioperm to enable the ports you want to use. A setuid to a non-root user does not disable the port access granted by ioperm , but a fork does the child process does not get access, but the parent retains it.
To input a byte 8 bits from a port, call inb port , it returns the byte it got To output a byte, call outb value, port Note that all port access instructions take at least about a microsecond to execute.
This method is probably slower than the normal method above, but does not need compiler optimisation nor ioperm. The use of ioperm requires root privileges.
For more ports, the iopl function must be used. Permissions are not inherited on fork, but on exec they are. This is useful for giving port access permissions to non-privileged tasks. This call is mostly for the i architecture. On many other architectures it does not exist or will always return an error.
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. Glibc1 does not have a prototype. The description above concentrates on the C programming language.
Parallel Port Pin Programming Library for Linux If you want a higher level approach to parallel port controlling than low level directly writign to control registers apprach, there are also tools for this available.
Parapin makes it easy to write C code under Linux that controls individual pins on a PC parallel port. Parapin provides a simple interface that lets programs use pins of the PC parallel port as digital inputs or outputs.
You can assert high or low TTL logic values on output pins or poll the state of input pins. Parapin has two personalities: it can either be used as a user-space C library, or linked as part of a Linux kernel module. There is also a device driver that provides access to the kernel module from user-space, allowing the administrator to use filesystem permissions to control access to the port.
Parapin was written with efficiency in mind, so that Parapin can be used in time-sensitive applications. The user-space version of Parapin is compiled and linked very much like any other C library.
The header file with the library's function prototypes and other definitions, parapin. To use the library, first make sure to include parapin. When linking, add -lparapin along with any other libraries you might be using. Please note that pin state may only be queried only if they are input pins by hardware or set as input. This device driver exposes the functionality of kparapin through a normal character-device interface except for interrupt handling.
When building a userspace program that will make use of the parapindriver interface to kparapin, you must include parapindriver. This header file defines the device-specific ioctl commands used to communicate with the device driver.
It also includes parapin. The parapindriver system calls take arguments using these constants and pass them unchanged down to the kparapin routines. To shutdown the parapin system you simply have to call close 2 : close device ; When using the parapindriver device interface, all functionality related to pins on the parallel port is invoked via the ioctl 2 system call.
The ioctl commands for parapindriver are defined in the parapindriver. Return values from these ioctl calls are the same as those defined for the corresponding functions in kparapin plus value -ENOTTY indicates that an invalid ioctl command value was passed down.
Programming tip: Usually, it is most convenient to use define statements to give pins logical names that have meaning in the context of your application. Example: include "parapin. 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. Most of the parapin description give above ade edited form documentation found at that address. Other Linux parallel port controlling software Parashell 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. Parasheel is easy program to use in shell scripts.
The software package comes with example shell scripts. MatPLC is a program that could be worth to check is also. The software can control also PC parallel port. Controlling parallel port through web It is possible to build a system that allows you to control your parallel port pins through a web.
Users downloads a web pages from some page where the web pages is web browser does this from given addess 2. The user web browser shows user the downloaded web page that has the control needed forms, buttons, etc.
User presses some control button or send button on form 4. 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 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 The first part would include that web server, controlling web pages and needed scripts to take user controls.
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 actual direct hardware controlling. For this C language is generally the best approach. The idea is tht the actual low level hardware controlling is done with simple C program, and then the script on part 1 sends controls to this C program in some way in simplest case runs this C program with right command line arguments every time hardware needs to be controlled.
Simple CGI-BIN controlling example 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.
The CGI-BIN scrips is written to perform the needed controlling, typically calling the parallel port controlling program with right parameters. This is the basic idea how to do this. Here is a simple example web controlling application. Do the following to make it work: 1. Make sure that your system is running Apache 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. Make sure that your web server is running. Compile the lptout. You can do this by logging on as root and executing the following commands: gcc -O lptout. Now everybody should be able run the command. 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.
Install the CGI scripts for parallel port controlling. The need scripts are lpton. Click the file names to see the source code, use "view source" if needed, save those files to your system with names lpton. Log in as root and do the following commands on the diectory where you stored the lpton. Install the necessary controlling web page. You need the web page index. Test that you can access the controlling page on the Linux server.
You should see a controlling page that looks something like this: 6. Test pressing the control buttons and see that the paralle port output pins change their state as controlled. You can find all the necessary files for this simple web project at one tar file called weblpt. Just download it to your Linux system and expand it to suitable directory with command tar xvf weblpt. Just do the steps needed with them and you should get your simple web controlling application working well.
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.
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. 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.
There are two files, one the actual php script and the other being the form data used to get the users input. Here is the source code of lptout. This source code prints out the form that is shown to user for parallel port controlling. I used PHP4 when I wrote this source code years ago. Web controlling using PHP and AJAX The portcontrol softwae web interface for controlling parallel port is simple modern web based interface for controlling parallel port. The software is based on PHP software running on Linux server and a JavaScript based client application running on the user web browser.
With this apprioach it is possible to get the almost real-time status of the parallel port data pins to the screen nicely and do flexible controlling easily. The server end is based on small piece of PHP code and portconrol software. The control. When it is loaded, the user gets a web page plus user end JavaScript code. That JavaScript code periodically once in 5 seconds asks the parallel port state from the server AJAX call and if it has changed updates status to the screen.
It also handles the control buttons. Every control button press makes the control software to call the server to make desired function AJAX call. After controlling is done, the server returns the current port status it is printed to screen. When the control software is written in this way, it works prerry well and feels almost like a graphical application programs controlling the parallel port directly instead of typical web application that loads web page again and again every time you do something.
Besides the actual controllign PHP script, I have written also an another version of the control. This file controlfile. The file based AJAX port control test application is availble here for you to test. The portcontrol software with web interface is is available as portcontrol.
I developed this software using PHP4 some years ago. I have not tested to software with PHP5. The modifications needed were mostly related to different executable portcontrol program portcontrol vs. The system-supplied function driver for parallel ports creates a functional device object FDO for each parallel port enumerated in the system. The following topics describe how a client operates a parallel port by using the interface provided by the port's FDO:.
Creating and Starting a Parallel Port. Opening and Closing a Parallel Port. Obtaining Information About a Parallel Port. Synchronizing the Use of a Parallel Port. Connecting to an IEEE
0コメント