Position: Index > Unclassified >

Program LPT and COM ports easily under windows NT-2000-XP

2017-12-23 20:17  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

If you are working with embedded projects usually you have concerned about how directly control computer ports like LPT or COM. Basically no one wants to mess up with driver writing or reading tons of documentations in order to send some bytes via IO port to your target board.

Earlier when DOS, win95 and win98 operating systems were popular accessing I/O ports was easy as there weren’t any protections a€“ simple code could do the job. Under NT/2000/XP situation is different. These operating systems has strict control of I/O ports. Read more about this here: www.beyondlogic.org.
If you will try to access ports directly under windows XP, then you will get error mesage:


How to solve this problem without writing your own driver and without rewriting old DOS or win98 programs. Well there is a solution that allow you to run programs under windows 2000/XP and talk to ports directly. Download PortTalk program from www.beyondlogic.org.

Now you have two ways of running programs a€“ but don’t forget to read porttalk.pdf which is included in package.

Solution No.1

Download portalk22.zip and unzip it in separate folder somewhere. Then copyallowio.exedirectly to the directory where is you program which you want to run. Then create shortcut of your compiled program for instance demo.exe. Then open files properties and in line target do following changes:

Instead of:


change to

D:/project/allowio.exe D:/project/demo.exe /a

This is it. Just remember that you must have administrator rights on this computer. Other wise you should run your program with administrator user rights. Dirty trick but it works.

Solution No.2

Download same program packet portalk22.zip. In the packet besides the driver there is header files for working with ports directly under Windows NT/2000/XP.

Set up your compiler like DEV-CPP. It is free IDE and C/C compiler. Or you can use any commercial compiler package like Microsoft Visual C or even C builder.

Before you start compiling your program copyportalk.sysfile toWINDOWS/System32/Driversand copy pt_ioctl.c and PortTalk_IOCTL.h files to your project directory. Now you can start developing.

Few words about Linux OS

For parallel port program usesppdevinterface of kernel. This is why with commandlsmodyou should make sure if this module is loaded:

root@xxx# /sbin/lsmodModule                  Size  Used by    Not taintedppdev                   5580   0  (unused)parport_pc             14724   0parport                23264   0  [ppdev parport_pc]

Otherwise you have to load this module with commandmodprobewhich is in the root:

root@xxx# /sbin/modprobe parport
root@xxx# /sbin/modprobe parport_pc
root@xxx# /sbin/modprobe ppdev

It is good practice if this command is performed during startup of operating system. These commands cam be added to script filerc.

For RedHat would be/etc/rc.d/rc.localor write to file/etc/modules.conf

For Slackware add them to file/etc/rc.d/rc.modules

#### PC parallel port support ###/sbin/modprobe parport_pc
/sbin/modprobe ppdev
/sbin/modprobe parport

Iy you want to work as other user without root rights you have to chmodppdevinterface by using comand (has to be performed under root rights):

# chmod 666 /dev/parport0

Before running your program make sure if there is no other programs running that serve for LPT printer. Otherwise you have to stop it before running your application.

Source: www.sapunoff.ru

Reprinted Url Of This Article: