Picaxe type control of a printer port?

GeorgeC47

Senior Member
Is there any software that allows the user to control the outputs and inputs of the PC printer port in the same way the programming language operates the input and output ports on a Picaxe?
On the old BBC computers it was very easy to send outputs to an external device, but modern PCs seem to require programming in C++ or Pascal.
 

hippy

Ex-Staff (retired)
There are a number of Active-X (.OCX) and .DLL components which will allow access to the parallel port from within PC-side programming languages, possibly even through HTML Pages if using Internet Explorer. There may be example programs which simply show the status of the line printer port bits and and allow the output bits to be controlled. Google would be a good place to start.

Note that some LPT ports are 3V3, and I/O lines can be bi-directional, so not a good idea to feed 5V or any signal directly into then.
 

benryves

Senior Member
Inpout32.dll works very nicely with virtually any programming language, and is just a couple of functions. For VB.NET, just copy the DLL to your application's directory and add the following two lines to your project:
Code:
Declare Function Inp32 Lib "inpout32.dll" (ByVal PortAddress As Integer) As Integer
Declare Sub Out32 Lib "inpout32.dll" (ByVal PortAddress As Integer, ByVal Value As Integer)
The Beyond Logic website has useful information about the various parallel port registers. Please allow the user to enter their own parallel port address, though - most modern PCs don't have parallel ports built into their motherboards, and a PCI parallel port will be assigned a non-legacy base address by Windows. Mine is at &HCCD8, and I've had to apply a variety of different hacks to get software that is hard coded to the legacy &H378 address to work!

Remember that direct access to I/O ports requires administrator privileges under Windows.

Edit: Of course, a more obvious answer would be to use, well, BBC BASIC. :) I haven't tested this code in anger, but it appears to work (I'm not sure if BBC BASIC for Windows lets you access I/O ports directly - I'm more used to the Z80 version, which had variations on GET and PUT for I/O port access).

Code:
SYS "LoadLibrary", "inpout32.dll" TO inpout32%
SYS "GetProcAddress", inpout32%, "Inp32" TO inp32%
SYS "GetProcAddress", inpout32%, "Out32" TO out32%
DEF PROC_Out32(port%,value%) SYS out32%, port%, value% : ENDPROC
DEF FN_Inp32(port%) SYS inp32%, port% TO value% : =value%
 
Last edited:

GeorgeC47

Senior Member
Thanks. I have used BBC Basic on the PC but so far have only tried the demo version. I will investigate the input/output of BBC Basic and perhaps will pay for the full version.
From what I remember, the BBC micro used addresses like &FE62 for the output port. Will the code you gave emulate those addresses?
 
Last edited:

benryves

Senior Member
Thanks. I have used BBC Basic on the PC but so far have only tried the demo version. I will investigate the input/output of BBC Basic and perhaps will pay for the full version.
From what I remember, the BBC micro used addresses like &FE62 for the output port. Will the code you gave emulate those addresses?
Sadly not, the code I posted just wraps the two functions in Inpout32.dll as a BASIC procedure and function. You would still need to control the port using the PC registers described on the Beyond Logic site, eg PROC_Out32(&378, &0F) to switch D0~D3 high and D4~D7 low (assuming a legacy LPT1 parallel port at &378 - you can find the address of your port in Device Manager, on the Resources tab of the port's property pages).

I did just find this article on Serial and Parallel I/O on the BBC BASIC website. If you can get away with reading and writing bytes using the Centronics protocol, you can open the port as a file (if you need to control pins individually then I think you'll be stuck with reading and writing registers directly). There is also sample code for WINRING0, which looks quite a bit more involved than the simple Inpout32.dll library.
 

hippy

Ex-Staff (retired)
I gave up on direct LPT port interfacing when I stated using XP, moved to using the Game Port for switch inputs, and with everything going USB have now settled on serial / USB-to-serial. It's quite easy to have a PICAXE ( or more ) controlled by serial and put X lines out and read Y lines in - In fact it's what initially appealed to me about the PICAXE, a few lines of code and everything works. What's best is any hardware designed this way will almost certainly work with anything which has a serial port - desktop, laptop, router, PDA, phone - as long as you can write the necessary control code for the device being used.
 

GeorgeC47

Senior Member
@George.
Just a question out of curiosity;
Is this the sort of thing you're making?

http://www.bbastrodesigns.com/BBAstroDesigns.html

e
That electronics is for controlling a Dobsonian telescope to allow it to track the stars. My mount already has the ability to do that, although it is a German Equatorial and achieves it a different way.
I would quite like to motorise the observatory dome because that also has to be moved around as the telescope moves to keep the open slot in line with the scope.
That will require a fairly powerful motor I imagine.
 

eclectic

Moderator
That electronics is for controlling a Dobsonian telescope to allow it to track the stars. My mount already has the ability to do that, although it is a German Equatorial and achieves it a different way.
I would quite like to motorise the observatory dome because that also has to be moved around as the telescope moves to keep the open slot in line with the scope.
That will require a fairly powerful motor I imagine.
Thanks for the info.

Two further questions please.

1. What is the (potential) Parallel interface for?

2. Would a wheelchair motor ( and relevant gearing) work?

Have a forum search for
scooter

Loads more there.

e
 

Andrew Cowan

Senior Member
A serial interface is much easier than a parallel one (as hippy points out) - is this possible? If no serial port is available, a virtual serial port can be created using USB.

Andrew
 

GeorgeC47

Senior Member
Two further questions please.

1. What is the (potential) Parallel interface for?

2. Would a wheelchair motor ( and relevant gearing) work?

e
Question 1. Not really sure. It was more of a hypothetical question. I have a computer in the observatory so it seemed logical to explore the possibility of using it to control the dome. A picaxe will probably be easier.

Question 2. I have a motor that is geared down so it is strong enough to do the job. At the moment it has a switch for forward and reverse, so I would have to work out how to control a mains voltage from the picaxe. Relays?
 

hippy

Ex-Staff (retired)
USB ports are replacing most others these days and that will only increase with time. Using a parallel port is a lock-in to older technology which can become a problem later if you upgrade the PC.

For mains control I'd go for a low-voltage coil relay switching mains ( both live and neutral ) and switched via an opto. I'd have the switching system separately powered and signal from the PC opto isolated as well.

Safe mains use is a lot about design and thinking of the worst that could happen. No end of protection will help if the live incoming mains wire comes loose and can short to a signal line to the PC. If you're not scared pantless by what you're doing you probably haven't thought of everything bad which could happen :)
 
Top