Parallel port control in Linux
The program also has support for the serial rs232 port. Although the IO is different from that of the parallel port, the serial connector rs232 can prove useful in many situations since it offers a serious amount of power (a voltage of +-12V or in some cases +-5V and short circuit current flow of 7-10mA) depending on the circuit types used in the PC circuitry. This is all at the cost of signal lines. The parallel port has eight data pins as we have seen above whereas the serial port has only three: TD(Transmit Data), DTS(Data Terminal Ready), RTS(Request to Send). However, only the last two are usable since TD is logic true(-12V) when no data is sent:
Based on the equivalence of both parallel port versions, pport accepts both standards transparently, either 9 pin or 25 pin serial rs232 connector.
- -p, –port <serial>
- With this option one can select an alternative port.
- -s, –set <pin1,pin2…|all|none|even|odd|random|dtr,rts>
- Causes pport to set one, some, or all pins to high. Or to set all low with “none”. dtr and rts are available only in combination with the serial port. One can also use all and none with the serial port option in order to set both RTS and DTR lines to high respectively low.
- -t, –toggle <pin1,pin2…|all|even|odd|random>
- Causes pport to toggle the state of the specified pins.
- -w, –wait <Nd|Nh|Nm|Ns>
- Where n is a number, causes pport to wait a specific time before altering the state of the specified pins, where n is a number, and d stands for days, h for hours, m for minutes and s for seconds.
- -r, –restore
- Causes pport to restore the previous state of the pins stored in the data file.
- Makes pport give a status report on the parallel port.
- Will turn on debugging for the following command.
- Will send raw data through the parallel port.
Here are a few examples for using this program:
- pport -s all -w 10m
- Will set all the pins to high after a 10 minutes delay.
- pport -s random -w 5s
- Will set some random pins to high after a 5 seconds delay.
- pport -r
- Will restore the previous pin states. This can be useful if you want to include pport in your startup scripts so it can restore your device status on system startup.
- pport -t 2,4,7 -w 10s
- Will toggle pins 2, 4 and 7 into their complementary state after 10 seconds.
- pport -p serial -s rts
- Will set the rts line of the rs232 port to the high state.
- pport -p serial -s rts,dtr
- Will set both lines of the rs232 port to the high state.
- pport -p serial -s none
- Will set both lines of the rs232 port to the low state.
- pport –raw “Hello world”
- Will send data through the parallel port.
1. The pport utility, must be able to access the ports in the first place. Failure to do so will result in an error. Thus pport must have superuser priviledges at runtime.
Parallel Port Accessing using C Code
Below are listed two options for controlling the parallel port under Linux. The first option writes directly to the parallel port memory address. It’s simple and works well, but because of the low level access, you’ll need to have root privileges. The second option, uses the
ppdev module for user-space access, that means you don’t need root privileges.
Compile either source file using the following command line.
> gcc cableTest.c -o cableTest