Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 25th, 2011, 03:12 PM
Registered User
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can´t read from parallel port

Hello.

I am trying to write a program for ms-dos 6.22, with Turbo C++ 3.0, that detects some push buttons connected to the data pins of the parallel port.
All the program does, at this stage, is read the data register 5 times per second and output it to the screen as a 2-digit hexadecimal code. So, when you press a button, the code should change. But it doesn't. The program just keeps printing code AA, which is odd, because when all the buttons are off, the code should be FF. Here's the code:
Code:
#include <dos.h>
#include <stdio.h>
#include <conio.h>


#define PORT    0x378

#define DATA    (PORT+0)
#define STATUS  (PORT+1)
#define CONTROL (PORT+2)


int main(void)
{
	outportb(CONTROL, 0x20); // Put parallel port in reading mode

	puts("Press any key to quit\n");

	while (!kbhit()) {
		int data = inportb(DATA); // Read the data register
		printf("%02X  ", data);
		delay(200);
	}

	outportb(CONTROL, 0x00); // Put parallel port in writing mode

	return 0;
}
I have adapted this program for Windows 7 and Visual C++ 2010 Express, using inpout32.dll, and it still doesn't work.

Does anyone know why I am failing to read the parallel port?
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run stepper motor with parallel port ogimy VB.NET 2002/2003 Basics 1 June 24th, 2010 11:59 PM
Receiving data from parallel port using C#.net venkatvens Visual C++ 0 August 11th, 2008 05:44 AM
Visual C++ on parallel port yunarch Visual C++ 0 September 30th, 2005 07:40 AM
How Can I Read or Write to Parallel Port? qdata Visual C++ 3 January 31st, 2005 07:47 AM
LPT (Parallel ) Port dll driver for XP maxtashkent Visual C++ 3 November 14th, 2003 12:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.