PDA

View Full Version : Accessing the parallel port in Win Xp (Visual C)



lasse.j5
11-27-2007, 09:43 AM
Hello everyone.

I'm currently building temperature datalogger which is using a temparature sensor and an Analog to Digital converter. I'm using the parallel port to send the data from the converter to the PC.

My question is which C functions can i use to read from the parallel port and which header files are needed?

I have downloaded a program called Porttalk and it allows direct access to the I/O ports in Windows xp.

Heretic
11-29-2007, 06:25 PM
Not sure about ALL the methods you can use, but PortTalk's site suggests the inportb/outportb and inp/outp methods:


The Porttalk driver contains two IOCTL calls to read from and write to I/O Ports. A c source file, pt_iotcl.c can be
used to provide easy support based on the popular inportb/outportb and inp/outp calls supported in earlier
programming environments. By simply including pt_ioctl.c and calling OpenPortTalk when you program starts and
ClosePortTalk when your program finishes you can have the functionality of the inportb/outportb and inp/outp calls.

#include <stdio.h>
#include <windows.h>
#include <pt_ioctl.c>

void __cdecl main(void)
{
unsigned char value;
printf("IoExample for PortTalk V2.0\nCopyright 2001 Craig Pea:banana::banana::banana::banana:\nhttp://www.beyondlogic.org\n");
OpenPortTalk();
outportb(0x378, 0xFF);
value = inportb(0x378);
printf("Value returned = 0x&#37;02X \n",value);
outp(0x378, 0xAA);
value = inp(0x378);
printf("Value returned = 0x%02X \n",value);
ClosePortTalk();
}

The sample program above is included in the IoExample directory along with the pt_ioctl.c. The pt_ioctl can be
used as an example of how to load and open the driver and then make IOCTL_WRITE_PORT_UCHAR and
IOCTL_READ_PORT_UCHAR calls.

edit: Some more generic info from MSDN: http://msdn2.microsoft.com/en-us/library/ms798344.aspx

lasse.j5
11-30-2007, 12:34 AM
Thanks but i figured it out myself.

I used a dll file called InpOut32.dll which lets you access the LPT port.