Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Error Messages
Gambas Playground
How To's
How To Change the Tab Order of GUI Controls
How To Contribute
How to Create and Open a ".gmail.txt" Archive
How to deal with Git and Gitlab concerning your Project
How to deal with Git and Gitlab for Gambas
How To Deal With Subversion for Gambas
How To Display a Chinese Character
How To Draw with gb.Cairo
How To Enter Data With gb.db.form
How To Get Gambas Web Started (1)
How To Get Started
How To Interface Gambas With External Libraries
How To make a chart with the gb.chart component
How to make a report with Gambas
How To Make KDE Run Gambas Executables Automatically
How To Open, Debug & Compile The IDE
How To Open a MySQL connection and use it
How To Open a SQLite connection and use it
How To Open a Unix ODBC connection and use it
How To Package Gambas
How To Package your Project
How To Print
How to Run Gambas and Gambas Apps on Windows using WSL
How To Run Gambas On Windows using Cygwin
How To Translate A Gambas Project
How To Translate Gambas
How To Translate The Gambas IDE (deprecated)
How To Use Parallel Port
Language Index
Language Overviews
Last Changes
Search the wiki
To Do
Wiki License
Wiki Manual

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:

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

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


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

See also