5,445,109 members and growing! (14,842 online)
Email Password   helpLost your password?
General Reading » Hardware & System » General     Intermediate

Port Access

By asef

A way to access parallel port in Windows XP
VC6, C++Windows, WinXPVS6, Visual Studio, Dev

Posted: 17 Aug 2004
Updated: 17 Aug 2004
Views: 72,344
Bookmarked: 28 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
25 votes for this Article.
Popularity: 4.84 Rating: 3.46 out of 5
7 votes, 28.0%
1
0 votes, 0.0%
2
2 votes, 8.0%
3
4 votes, 16.0%
4
12 votes, 48.0%
5

Introduction

At first I want to thank Mr. Tomas Franzon as I used his help a lot in this project. This code opens and closes 0x378 port ( printer port ) manually. In XP we have no permission to access external port like Printer. Here we copy a sys file to system32 and use it in the code so we can send and receive data through this port.

Using the code

For using the code you have to copy PortAccess.sys ( exists in source ) to system32\drivers. Then you can run the program.

For sending and receiving data we do this :

#include <conio.h>

#include <math.h>

// 


         // for sending data

         _outp(Port_Address,iByte); 

//

Return Value:

This function returns data output . There is no error return.

Parameters:

Unsigned short Port Number ( defined 0x378 )

Int Output value

         // for receiving data

         iByte=_inp(Port_Address); 

Return Value:

This function returns the byte, word or int from port. There is no error report

Parameters:

Unsigned short Port Number ( defined 0x378 )

When you check a check box the iBitOut value is Set or Reset.

// to set or reset a bit

iBitOut[i]=1-iBitOut[i];
 

When you click output button the Bits are changed to int value to send to port.

 
         // to send value to port


         iByte=0;

         for (i=0;i<=7;i++)

         {

                 iTemp=pow(2,i);

                 nIndex=iTemp*iBitOut[i];

                 iByte=iByte+nIndex;

         }

         _outp(Port_Address,iByte);
 

When you click input button the input value is read and iBitIn[i] becomes set or reset.

 

         // to get data from port 


         iByte=_inp(Port_Address);

         for (i=7;i>=0;i--)

         {

                 nIndex=pow(2,i);

                 if (iByte>=nIndex)

                 {        iByte=iByte-nIndex;

                          iBitIn[i]=1;

                 }

                 else iBitIn[i]=0;

         } 

For checking a check box we use code below :

         // to check a check box


         if (iBitIn[0]==1)
                 CheckDlgButton(hDlg,IDC_CHECKINPUT1,BST_CHECKED);
 

Points of Interest

I always work with peripheral devices. In these cases, communicating in parallel mode is more flexible and easier than the other modes like serial communication. So I am forced to go to this field. You can send and receive int, long, Byte, unsigned short, unsigned char etc as easy as possible.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

asef


I live in Islamic Republic of Iran . I started hardware programming when I was young. I designed and built some ISA cards for attaching to PC.like ocsiloscope and signal generator. Now I am working for a engineering company and Manager of some project.

Occupation: Web Developer
Location: Iran, Islamic Republic Of Iran, Islamic Republic Of

Other popular Hardware & System articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 37 (Total in Forum: 37) (Refresh)FirstPrevNext
Subject  Author Date 
Questionemergency helpmembermechatron1:39 19 Apr '08  
GeneralI have a problem with a parallel port, could you please help me?memberluixilva12:53 9 Oct '07  
QuestionInput Problemmembermirispearl20:37 5 Sep '07  
Questiona question from lovers_aliadminSean Ewington9:41 6 Jun '07  
AnswerRe: a question from lovers_alimemberasef20:26 9 Jun '07  
GeneralPort access projectmemberRupanagudi16:25 4 May '07  
GeneralRe: Port access projectmemberf217:49 27 May '07  
GeneralRe: Port access projectmemberasef20:42 9 Jun '07  
GeneralRe: Port access projectmemberWamuti7:07 16 Nov '07  
Generalplotting a graph in VC++member23:07 19 Mar '07  
GeneralVisual C++ 6 Or Visual C++.Net 2005membersaman_programing2:13 29 May '06  
GeneralRe: Visual C++ 6 Or Visual C++.Net 2005memberasef3:40 29 May '06  
Questionejraye barname dar Turbo C++ 3.0 DOSmembersaman_programing19:55 24 May '06  
AnswerRe: ejraye barname dar Turbo C++ 3.0 DOSmemberasef19:49 26 May '06  
Generalserial ( COM) port accessingmemberbala nagesh19:29 15 May '06  
GeneralRe: serial ( COM) port accessingmemberasef21:14 15 May '06  
QuestionInput Probsmemberbhaskar_gupta9:31 8 Feb '06  
AnswerRe: Input Probsmemberasef18:45 11 Feb '06  
GeneralHow to control parallel port by programming Visual C++memberBK20075:07 25 Dec '06  
GeneralParallel portmemberdzldan11:46 2 Nov '05  
GeneralRe: Parallel portmemberasef18:36 4 Nov '05  
GeneralRe: Parallel portmemberBK20075:05 25 Dec '06  
Generalport Programming Problem In XPmemberMasoud Aghapour18:49 7 Sep '05  
GeneralRe: port Programming Problem In XPmemberasef19:49 21 Oct '05  
Generalport interface for XPmembersarkiszakaryan12:26 23 Aug '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Aug 2004
Editor: Smitha Vijayan
Copyright 2004 by asef
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project