<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - How To Use Parallel Port
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../howto+en">Up</a>&nbsp;
<a href="package+en">Previous</a>&nbsp;
<a href="translate+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
How To Use Parallel Port
</h1>
How to use the parallel port is not a <a href="../def/gambas+en">Gambas</a> problem, but a <a href="../def/linux+en">Linux</a> kernel problem.
<p>
The kernel prevents any program from doing bad things like directly accessing hardware.
Instead, you must use <i>devices</i>, i.e. special files located in the <tt>/dev</tt>
directory, that allow you to access the hardware under kernel control.
<p>
You can access parallel port by using device files like <tt>/dev/lp0</tt>...<tt>/dev/lpN</tt>.
But if you need more controls, i.e. if you want to be able to write to x86
input/output ports, you use a device file named <tt>/dev/port</tt>.
<p>
You will find more explanation there:
<p>
<a href="http+//www.faqs.org/docs/Linux-mini/IO-Port-Programming.html">http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html</a>
<p>
The chapter 2.2 says that:
<p>
<pre class="code">2.2 An alternate method: /dev/port

Another way to access I/O ports is to open() /dev/port (a character device,
major number 1, minor 4) for reading and/or writing (the stdio f*() functions
have internal buffering, so avoid them). Then lseek() to the appropriate byte
in the file (file position 0 = port 0x00, file position 1 = port 0x01, and so
on), and read() or write() a byte or word from or to it.

Naturally, for this to work your program needs read/write access to /dev/port.
This method is probably slower than the normal method above, but does not
need compiler optimisation nor ioperm(). It doesn't need root access either,
if you give a non-root user or group access to /dev/port --- but this is a
very bad thing to do in terms of system security, since it is possible to
hurt the system, perhaps even gain root access, by using /dev/port to access
hard disks, network cards, etc. directly.

You cannot use select(2) or poll(2) to read /dev/port, because the hardware
does not have a facility for notifying the CPU when a value in an input port
changes.
</pre><p><p>
So, as root, you can do what is explained above: opening <tt>/dev/port</tt>
(<tt><a href="../lang/open+en">OPEN</a> &quot;/dev/port&quot; <a href="../lang/for+en">FOR</a> <a href="../lang/read+en">READ</a> <a href="../lang/write+en">WRITE</a>) and read/write at a specific
location.
<p>
There is another solution based on a C library named 'parapin'. You will find
more information at <a href="http+//parapin.sourceforge.net/">http://parapin.sourceforge.net/</a>
<p>
<hr><b>See also</b><br>
<a href="../lang/open+en">OPEN</a>&nbsp;

</div>
</body>
</html>

