Solved

ReadFile Error code 1 for parallel port reading.

Posted on 2004-08-11
6
516 Views
Last Modified: 2011-09-20
I am trying to run a program to read from the parallel port. The following is the beginning of the program, and when I try to do the ReadFile( ) function, there is an error message of code 1. Anyone know why is it so?

=============================================
      hDevice =
            CreateFile("\\\\.\\LPT1",
                              GENERIC_READ | GENERIC_WRITE,
                              0,            // share mode none
                              NULL,      // no security
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL );            // no template
      printf("Attempting to read from device...\n");
      char inBuffer[80];
      DWORD inCount = sizeof(inBuffer);
      DWORD bR;
      status = ReadFile(hDevice, inBuffer, inCount, &bR, NULL);
      if (status==0) {
            printf("Failed on call to ReadFile - error: %d\n",
                  GetLastError() );
            return 4;
      }
=============================================
0
Comment
Question by:sakee
[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
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:lbertacco
ID: 11770791
Despite the fact that SPP/EPP/ECP parallel ports support bidirectional communication, I don't think that just accessing them via the LPT device supports bidir communication and you are limited to unidirectional (output only) communication (I'm not sure about WinXP).

For lower level access to the parallel port you should refere to the Windows DDK. Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/parallel/hh/parallel/sspd_73eda256-542a-4967-8b5f-183f45723b1d.xml.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/parallel/hh/parallel/cisspd_a108ba77-8f01-436e-bc7a-48a74f80ac75.xml.asp

Or use third party drivers (http://www.fapo.com/1284tkit.htm)
0
 

Author Comment

by:sakee
ID: 11790159
Thanks lbertacco for replying.

I am using the sample codes from the book "Windows® 2000 Device Driver Book: A Guide for Programmers, Second Edition, By Art Baker, Jerry Lozano" to learn about the parallel port communication and develop a usbale application. So I assume it should be working well.

Now I am disappointed with the book, so I would llike to learn about the parallel port access recommended by the msdn site but I am wondering how much time will it take. Have you any idea on the learning curve and implementation?

0
 
LVL 11

Expert Comment

by:lbertacco
ID: 11790615
Well if the book is about device drivers , it probably covers the DDK. Anyway I'm not sure you can't do what you are doing. Bidir parallel communication was not supported by the OS some years ago (when I have programmed them a bit), but now things may have changed, so if that book says it's possibile, I guess it is.
It may fail for other reasons too: e.g. are you using a recent enough version of windows (Win2k/XP)? Do you have an ECP parallel port and have you configured it in ECP mode (in the BIOS)?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sakee
ID: 11807179
Just tried all the available parallel port mode in the BIOS (ECP, EPP, PS/2, AT). All give the same error message. There is not much detail regarding this in the book. Think I am stuck.

Any other suggestions?

0
 

Author Comment

by:sakee
ID: 11807185
One thing is that it is difficult to learn to use the DDK for this. There is no examples available.
0
 
LVL 11

Accepted Solution

by:
lbertacco earned 100 total points
ID: 11807374
If the book clearly says that that should work and provides source code try asking confirmation to the author (I still don't belive it can possibily work). I'm not an expert with DDK, so I can't help you with that.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

738 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