?
Solved

Parallel Comms under WinXP with VC++

Posted on 2005-03-07
5
Medium Priority
?
787 Views
Last Modified: 2012-08-13
Hi Gurus,
I want to use the Parallel port under Windows XP. I have done it successfully with other Windows versions but XP doesn't work. I am using a VC++ DLL to do the actual communications to the Parallel port. I am calling the DLL from a VisualBasic6 App.

HERE IS THE VC++ CODE FOR THE DLL

      void _stdcall OutM2G(short portVal, short number)
      {
            _outp(portVal, number);            //( This crashes with values (0x378, 0) )
      }

      short _stdcall InM2G(short portVal)
      {
            return _inp(portVal);            //( This crashes with value (0x378) )
      }

I have also tried using _outp and _inp from a Win32 Application but I get the same error: "Unhandled Eception in Blah.exe: 0xC0000096: Privileged Instruction."

Any idea what I'm doing wrong?
Thanks,
Jason
0
Comment
Question by:jasonbb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 13475391
This library can be used to make simple Windows program working with parallel port:

http://www.logix4u.cjb.net/
0
 
LVL 22

Accepted Solution

by:
grg99 earned 2000 total points
ID: 13475641
You can't do direct port I/O with Windows NT/2000/XP as-is.

There are a few kludgy helper apps that turn off the I/O protection, google for "giveio", that's one I've used with some success.

0
 
LVL 86

Expert Comment

by:jkr
ID: 13477009
>>Any idea what I'm doing wrong?

Yes. You are using a "Privileged Instruction" :o) Direct hardware acces is not allowed under NT/2k/XP.

I'd strongly advise to only use direct port I/O as a last resort. Actually, all the APIs you need are described at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp ("Serial Communications in Win32"), which also applies to parallel port programming (just use 'LPT1' instead of e.g. 'COM1'). http://support.microsoft.com/default.aspx?scid=kb;en-us;138594 ("HOWTO: Send Raw Data to a Printer by Using the Win32 API")
0
 
LVL 22

Expert Comment

by:grg99
ID: 13477525
The problem with using the recommended methods of talking to LPT port is that many devices need more than simple data stream out with Centronics or ECP handshaking.

.  The LPT port is a bi-directional 14-bit port.  there are unfortunately lots of EE's that want to talk i2L protocol, which involves twiddling one of the bits as an output clock, while watching a different bit for input data.  

That was trivial under DOS, you just send out one bitmask to select what wires you wanted as inputs, which as outputs.  Then you could do an out 378h,al to send a byte, in 37Ah to input a byte.    

Now of course we have several layers (SIX I think if you use the stock Miniport driver skeletons) of protocols to navigate if we want to set up our own port driver.    Kind of a steep learning curve for somebody that just wants to input one bloody bit.

I still suggest kludges like "giveio".  They're not the "right" way to do it, just 10,000,000 times simpler.



0
 

Author Comment

by:jasonbb
ID: 13503379
The program I used is called "UserPort". It's very easy and it works.
I found "UserPort" from a link at "GiveIO" so grg99 gets the points.
Thankyou posters.

Links follow:

http://www.littlesounddj.com/awkiawki/index.cgi/UserPort

http://www.littlesounddj.com/awkiawki/index.cgi/GiveIO

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question