Home > howto > parport 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs ar fa id vi ko ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Search  Administration  
Documentation  
Warning! This page is not translated.  See english version 
How To Use Parallel Port
How to use the parallel port is not a Gambas problem, but a Linux kernel problem.

The kernel prevents any program from doing bad things like directly accessing hardware. Instead, you must use devices, i.e. special files located in the /dev directory, that allow you to access the hardware under kernel control.

You can access parallel port by using device files like /dev/lp0.../dev/lpN. 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 /dev/port.

You will find more explanation there:

http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html

The chapter 2.2 says that:

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.

So, as root, you can do what is explained above: opening /dev/port with OPEN and read/write at a specific location.

Example

Dim hPort As File
Dim iPortNumber As Integer
Dim iValue as Byte

' Send 42 on the port 1
iPortNumber = 1
iValue = 42

hPort = Open "/dev/port" For Read Write
Seek #hPort, iPortNumber
Write #hPort, iValue
...

There is another solution based on a C library named 'parapin'. You will find more information at http://parapin.sourceforge.net/

See also

OPEN