ADAM'S WEB PRESENCE

10 August 2009

Parallel port control in Python

Filed under: Nerd Notes — adam @ 11:11 am

Controlling the parallel port has always been a pain in Windows 2000, XP and later. In DOS or older versions of Windows you could just write a byte directly to port 0×378 and that was it.

Now you can get the same level of simplicity using inpout32.dll and Python. Go here to download the DLL and you can access it from Python just as easily as it used to be under DOS. The following example writes the number 5 to the parallel port:

import ctypes

ctypes.windll.inpout32.Out32(0x378, 5)


UPDATE: I have made a simple demo app using this technique. You can download it from my commercial website at http://siliconsparrow.com/parallel-port-tester-in-python/.

4 Comments »

  1. Comment by Gil — 25 October 2009 @ 11:42 pm

    Will this hold the port to 5 or will it revert instantly to 0?

  2. Comment by adam — 27 October 2009 @ 9:16 pm

    It will hold it until you write a different value to the port.

  3. Comment by Gil — 28 October 2009 @ 6:20 pm

    Thanks for the info

  4. Comment by David — 7 December 2009 @ 3:25 pm

    Hey – thanks Adam.

    Much appreciated – I’ve been pulling my hair out trying to solve this for hours.

RSS feed for comments on this post. TrackBack URI

Leave a comment


Powered by WordPress