Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 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
 
Old January 23rd, 2005, 07:34 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How Can I Read or Write to Parallel Port?

I am using VC++ 6.0, is there any code I can use to read or write to parallel port? For example to turn on/off a bulb (for sure it will be buffered).

With turbo C++ or Borland C++ (older versions) I can easily do this by using "inportb/inport" and "outportb/outport" commands to send/receive a "byte/word". For example by connecting 7 LEDs (each seried with a resistor) to seven pins of Par. port (Q0....Q7) I can turn them on/off anyway the bits of my unsigned char in outport command says.

Example:
void outportb(int port, unsigned char byte);
//char=0x61 or 0x21 for parallel port address in IBM standard

unsigned char inportb(int port);
//the seven bits of port(address) will be copied to the pre-defined unsigned char

(see turbo C bible for more details)

IF ANYBODY THROUGH ME A WORKING SOURCE CODE IT WOULD BE APPRECIATED WHOLE MY LIFE :D.

WOW...GOT SO LONG.....THANKS IN ADVANCE...
 
Old January 24th, 2005, 04:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

You will First have to buy some sort of automation card do get such a thing to work. Do you have that?


Regards
Ankur Verma
 
Old January 27th, 2005, 03:58 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I/O Port Access in Microsoft Visual C++
Microsoft Visual C/C++ provides access to the I/O ports on the 80x86 CPU via the predefined functions _inp / _inpw and _outp / _outpw.


     int _inp(unsigned portid); /* returns a byte read from the I/O port portid */

unsigned _inpw(unsigned portid); /* returns a word read from the I/O port portid */

     int _outp(unsigned portid, /* writes the byte value to the I/O port portid */
                int value); /* returns the data actually written */

unsigned _outpw(unsigned portid, /* writes the word value to the I/O port portid */
                unsigned value); /* returns the data actually written */

portid can be any unsigned integer in the range 0-65535
#include <conio.h> /* required only for function declarations */

#define Data 0x378 /*SEE YOUR'S FROM BIOS OR SYSTEM INFO*/
                      /* YOUR'S MIGHTBE DIFERENT */
#define Status 0x379
#define Control 0x37a

int Bits, /* 0 <= Bits <= 255 */
    Dummy;

Dummy = _outp(Data,Bits); /* output data */

Bits = _inp(Status); /* input data */





Here's my Digital Joystick example


--------------------------------------------------------------------------------

[ Back to Reading & Writing Data ]

--------------------------------------------------------------------------------

last updated: 13-Mar-97 Ian Harries <[email protected]>
 
Old January 31st, 2005, 07:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Do write back if you write a similar program for a NT based machines as well.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Receiving data from parallel port using C#.net venkatvens Visual C++ 0 August 11th, 2008 05:44 AM
to read eternet port data nmmeenaa General .NET 1 October 23rd, 2006 09:34 AM
Visual C++ on parallel port yunarch Visual C++ 0 September 30th, 2005 07:40 AM
How to Read and Receive data from a port Vijay_VB VB How-To 1 August 14th, 2004 05:01 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.