• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

ReadFile Error code 1 for parallel port reading.

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
sakee
Asked:
sakee
  • 3
  • 3
1 Solution
 
lbertaccoCommented:
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
 
sakeeAuthor Commented:
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
 
lbertaccoCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
sakeeAuthor Commented:
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
 
sakeeAuthor Commented:
One thing is that it is difficult to learn to use the DDK for this. There is no examples available.
0
 
lbertaccoCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now